From 6516ea4fdd6cbd5afae44bac46862a1b7732f434 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Mon, 18 Nov 2024 10:52:58 -0800 Subject: [PATCH 1/2] Add failing test for #1532 to show the problem --- .../tables/FindOneTableIntegrationTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/tables/FindOneTableIntegrationTest.java b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/tables/FindOneTableIntegrationTest.java index 91b694f49..981e6ead8 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/tables/FindOneTableIntegrationTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/tables/FindOneTableIntegrationTest.java @@ -307,6 +307,47 @@ public final void sparseDataForCollectionDataType() { .wasSuccessful() .hasJSONField("data.document", docJSON); } + + // for [data-api#1532] + @Test + @Order(5) + public final void documentIdWith$in() { + final String TABLE_NAME = "findOneIdAndDollarInTable"; + assertNamespaceCommand(keyspaceName) + .templated() + .createTable( + TABLE_NAME, + Map.of( + "_id", "text", + "value", "int"), + "_id") + .wasSuccessful(); + + // First, insert 2 documents: + String DOC_A_JSON = "{ \"_id\": \"a\", \"value\": 12 }"; + assertTableCommand(keyspaceName, TABLE_NAME) + .templated() + .insertOne(DOC_A_JSON) + .wasSuccessful(); + + String DOC_B_JSON = "{ \"_id\": \"b\", \"value\": 23 }"; + assertTableCommand(keyspaceName, TABLE_NAME) + .templated() + .insertOne(DOC_B_JSON) + .wasSuccessful(); + + assertTableCommand(keyspaceName, TABLE_NAME) + .postFindOne( + """ + { + "filter": { + "_id": { "$in": ["b", "c"] } + } + } + """) + .wasSuccessful() + .hasJSONField("data.document", DOC_B_JSON); + } } @Nested From 29bd7db6c409ca3b0aae12950eb8383de0082dff Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 12 Dec 2024 09:05:20 -0800 Subject: [PATCH 2/2] Reorder test cases --- .../tables/FindOneTableIntegrationTest.java | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/tables/FindOneTableIntegrationTest.java b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/tables/FindOneTableIntegrationTest.java index 981e6ead8..e1d3d06db 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/tables/FindOneTableIntegrationTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/tables/FindOneTableIntegrationTest.java @@ -261,8 +261,49 @@ public void findOneDocIdKey() { .hasJSONField("data.document", removeNullValues(DOC_B_JSON)); } + // for [data-api#1532] @Test @Order(4) + public final void documentIdWith$in() { + final String TABLE_NAME = "findOneIdAndDollarInTable"; + assertNamespaceCommand(keyspaceName) + .templated() + .createTable( + TABLE_NAME, + Map.of( + "_id", "text", + "value", "int"), + "_id") + .wasSuccessful(); + + // First, insert 2 documents: + String DOC_A_JSON = "{ \"_id\": \"a\", \"value\": 12 }"; + assertTableCommand(keyspaceName, TABLE_NAME) + .templated() + .insertOne(DOC_A_JSON) + .wasSuccessful(); + + String DOC_B_JSON = "{ \"_id\": \"b\", \"value\": 23 }"; + assertTableCommand(keyspaceName, TABLE_NAME) + .templated() + .insertOne(DOC_B_JSON) + .wasSuccessful(); + + assertTableCommand(keyspaceName, TABLE_NAME) + .postFindOne( + """ + { + "filter": { + "_id": { "$in": ["b", "c"] } + } + } + """) + .wasSuccessful() + .hasJSONField("data.document", DOC_B_JSON); + } + + @Test + @Order(5) public final void sparseDataForCollectionDataType() { String tableName = "mapListSet"; String tableJson = @@ -307,47 +348,6 @@ public final void sparseDataForCollectionDataType() { .wasSuccessful() .hasJSONField("data.document", docJSON); } - - // for [data-api#1532] - @Test - @Order(5) - public final void documentIdWith$in() { - final String TABLE_NAME = "findOneIdAndDollarInTable"; - assertNamespaceCommand(keyspaceName) - .templated() - .createTable( - TABLE_NAME, - Map.of( - "_id", "text", - "value", "int"), - "_id") - .wasSuccessful(); - - // First, insert 2 documents: - String DOC_A_JSON = "{ \"_id\": \"a\", \"value\": 12 }"; - assertTableCommand(keyspaceName, TABLE_NAME) - .templated() - .insertOne(DOC_A_JSON) - .wasSuccessful(); - - String DOC_B_JSON = "{ \"_id\": \"b\", \"value\": 23 }"; - assertTableCommand(keyspaceName, TABLE_NAME) - .templated() - .insertOne(DOC_B_JSON) - .wasSuccessful(); - - assertTableCommand(keyspaceName, TABLE_NAME) - .postFindOne( - """ - { - "filter": { - "_id": { "$in": ["b", "c"] } - } - } - """) - .wasSuccessful() - .hasJSONField("data.document", DOC_B_JSON); - } } @Nested