Skip to content

Commit 92af727

Browse files
committed
WIP
1 parent 205bdeb commit 92af727

4 files changed

Lines changed: 109 additions & 85 deletions

File tree

document-store/src/integrationTest/java/org/hypertrace/core/documentstore/FlatCollectionWriteTest.java

Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,14 +1711,14 @@ void testBulkCreateOrReplaceReturnOlderDocuments() throws Exception {
17111711
String docId1 = "bulk-replace-return-1";
17121712
String docId2 = "bulk-replace-return-2";
17131713

1714-
String initial1Json = readFileFromResource(
1715-
"create/bulk_replace_initial_doc1.json").orElseThrow();
1716-
String initial2Json = readFileFromResource(
1717-
"create/bulk_replace_initial_doc2.json").orElseThrow();
1718-
String updated1Json = readFileFromResource(
1719-
"create/bulk_replace_updated_doc1.json").orElseThrow();
1720-
String updated2Json = readFileFromResource(
1721-
"create/bulk_replace_updated_doc2.json").orElseThrow();
1714+
String initial1Json =
1715+
readFileFromResource("create/bulk_replace_initial_doc1.json").orElseThrow();
1716+
String initial2Json =
1717+
readFileFromResource("create/bulk_replace_initial_doc2.json").orElseThrow();
1718+
String updated1Json =
1719+
readFileFromResource("create/bulk_replace_updated_doc1.json").orElseThrow();
1720+
String updated2Json =
1721+
readFileFromResource("create/bulk_replace_updated_doc2.json").orElseThrow();
17221722

17231723
flatCollection.createOrReplace(
17241724
new SingleValueKey(DEFAULT_TENANT, docId1), new JSONDocument(initial1Json));
@@ -1760,32 +1760,34 @@ void testBulkCreateOrReplaceReturnOlderDocuments() throws Exception {
17601760
assertEquals(expectedDoc2, oldDoc2);
17611761

17621762
// Verify the documents were actually replaced with new values
1763-
String expectedResult1Json = readFileFromResource(
1764-
"expected/bulk_replace_result_doc1.json").orElseThrow();
1765-
String expectedResult2Json = readFileFromResource(
1766-
"expected/bulk_replace_result_doc2.json").orElseThrow();
1767-
1768-
Query query1 = Query.builder()
1769-
.setFilter(
1770-
RelationalExpression.of(
1771-
IdentifierExpression.of("id"),
1772-
RelationalOperator.EQ,
1773-
ConstantExpression.of(new SingleValueKey(DEFAULT_TENANT, docId1).toString())))
1774-
.build();
1763+
String expectedResult1Json =
1764+
readFileFromResource("expected/bulk_replace_result_doc1.json").orElseThrow();
1765+
String expectedResult2Json =
1766+
readFileFromResource("expected/bulk_replace_result_doc2.json").orElseThrow();
1767+
1768+
Query query1 =
1769+
Query.builder()
1770+
.setFilter(
1771+
RelationalExpression.of(
1772+
IdentifierExpression.of("id"),
1773+
RelationalOperator.EQ,
1774+
ConstantExpression.of(new SingleValueKey(DEFAULT_TENANT, docId1).toString())))
1775+
.build();
17751776
try (CloseableIterator<Document> iter = flatCollection.find(query1)) {
17761777
assertTrue(iter.hasNext());
17771778
JsonNode actualDoc1 = OBJECT_MAPPER.readTree(iter.next().toJson());
17781779
JsonNode expectedResultDoc1 = OBJECT_MAPPER.readTree(expectedResult1Json);
17791780
assertEquals(expectedResultDoc1, actualDoc1);
17801781
}
17811782

1782-
Query query2 = Query.builder()
1783-
.setFilter(
1784-
RelationalExpression.of(
1785-
IdentifierExpression.of("id"),
1786-
RelationalOperator.EQ,
1787-
ConstantExpression.of(new SingleValueKey(DEFAULT_TENANT, docId2).toString())))
1788-
.build();
1783+
Query query2 =
1784+
Query.builder()
1785+
.setFilter(
1786+
RelationalExpression.of(
1787+
IdentifierExpression.of("id"),
1788+
RelationalOperator.EQ,
1789+
ConstantExpression.of(new SingleValueKey(DEFAULT_TENANT, docId2).toString())))
1790+
.build();
17891791
try (CloseableIterator<Document> iter = flatCollection.find(query2)) {
17901792
assertTrue(iter.hasNext());
17911793
JsonNode actualDoc2 = OBJECT_MAPPER.readTree(iter.next().toJson());
@@ -2237,15 +2239,15 @@ void testSetAllFieldTypes() throws Exception {
22372239
SubDocumentUpdate.of("rating", 4.5f),
22382240
SubDocumentUpdate.of("weight", 123.456),
22392241
// Case 2: Top-level arrays
2240-
SubDocumentUpdate.of("tags", new String[]{"tag4", "tag5", "tag6"}),
2241-
SubDocumentUpdate.of("numbers", new Integer[]{10, 20, 30}),
2242-
SubDocumentUpdate.of("scores", new Double[]{1.1, 2.2, 3.3}),
2243-
SubDocumentUpdate.of("flags", new Boolean[]{true, false, true}),
2242+
SubDocumentUpdate.of("tags", new String[] {"tag4", "tag5", "tag6"}),
2243+
SubDocumentUpdate.of("numbers", new Integer[] {10, 20, 30}),
2244+
SubDocumentUpdate.of("scores", new Double[] {1.1, 2.2, 3.3}),
2245+
SubDocumentUpdate.of("flags", new Boolean[] {true, false, true}),
22442246
// Case 3 & 4: One nested path in JSONB (props) - tests nested primitive
22452247
SubDocumentUpdate.of("props.brand", "NewBrand"),
22462248
// Use 'sales' JSONB column for nested array test
22472249
SubDocumentUpdate.of(
2248-
"sales.regions", SubDocumentValue.of(new String[]{"US", "EU", "APAC"})));
2250+
"sales.regions", SubDocumentValue.of(new String[] {"US", "EU", "APAC"})));
22492251

22502252
UpdateOptions options =
22512253
UpdateOptions.builder().returnDocumentType(ReturnDocumentType.AFTER_UPDATE).build();
@@ -2455,7 +2457,7 @@ void testSetMultipleNestedPathsInSameJsonbColumn() throws Exception {
24552457
SubDocumentUpdate.of("props.size", "XL"),
24562458
SubDocumentUpdate.of("props.newField", "newValue"),
24572459
SubDocumentUpdate.of(
2458-
"props.owners", SubDocumentValue.of(new String[]{"owner1", "owner2"})));
2460+
"props.owners", SubDocumentValue.of(new String[] {"owner1", "owner2"})));
24592461

24602462
UpdateOptions options =
24612463
UpdateOptions.builder().returnDocumentType(ReturnDocumentType.AFTER_UPDATE).build();
@@ -2761,7 +2763,7 @@ void testAddArrayValue() {
27612763
SubDocumentUpdate.builder()
27622764
.subDocument("price")
27632765
.operator(UpdateOperator.ADD)
2764-
.subDocumentValue(SubDocumentValue.of(new Integer[]{1, 2, 3}))
2766+
.subDocumentValue(SubDocumentValue.of(new Integer[] {1, 2, 3}))
27652767
.build());
27662768

27672769
UpdateOptions options =
@@ -2808,19 +2810,19 @@ void testAppendToListAllCases() throws Exception {
28082810
SubDocumentUpdate.builder()
28092811
.subDocument("tags")
28102812
.operator(UpdateOperator.APPEND_TO_LIST)
2811-
.subDocumentValue(SubDocumentValue.of(new String[]{"newTag1", "newTag2"}))
2813+
.subDocumentValue(SubDocumentValue.of(new String[] {"newTag1", "newTag2"}))
28122814
.build(),
28132815
// Nested JSONB array: append to existing props.colors
28142816
SubDocumentUpdate.builder()
28152817
.subDocument("props.colors")
28162818
.operator(UpdateOperator.APPEND_TO_LIST)
2817-
.subDocumentValue(SubDocumentValue.of(new String[]{"green", "yellow"}))
2819+
.subDocumentValue(SubDocumentValue.of(new String[] {"green", "yellow"}))
28182820
.build(),
28192821
// Nested JSONB: append to non-existent array (creates it)
28202822
SubDocumentUpdate.builder()
28212823
.subDocument("sales.regions")
28222824
.operator(UpdateOperator.APPEND_TO_LIST)
2823-
.subDocumentValue(SubDocumentValue.of(new String[]{"US", "EU"}))
2825+
.subDocumentValue(SubDocumentValue.of(new String[] {"US", "EU"}))
28242826
.build());
28252827

28262828
UpdateOptions options =
@@ -2899,13 +2901,13 @@ void testAddToListIfAbsentAllCases() throws Exception {
28992901
SubDocumentUpdate.builder()
29002902
.subDocument("tags")
29012903
.operator(UpdateOperator.ADD_TO_LIST_IF_ABSENT)
2902-
.subDocumentValue(SubDocumentValue.of(new String[]{"existing1", "newTag"}))
2904+
.subDocumentValue(SubDocumentValue.of(new String[] {"existing1", "newTag"}))
29032905
.build(),
29042906
// Nested JSONB: 'red' exists, 'green' is new → adds only 'green'
29052907
SubDocumentUpdate.builder()
29062908
.subDocument("props.colors")
29072909
.operator(UpdateOperator.ADD_TO_LIST_IF_ABSENT)
2908-
.subDocumentValue(SubDocumentValue.of(new String[]{"red", "green"}))
2910+
.subDocumentValue(SubDocumentValue.of(new String[] {"red", "green"}))
29092911
.build());
29102912

29112913
UpdateOptions options =
@@ -2976,13 +2978,13 @@ void testRemoveAllFromListAllCases() throws Exception {
29762978
SubDocumentUpdate.builder()
29772979
.subDocument("tags")
29782980
.operator(UpdateOperator.REMOVE_ALL_FROM_LIST)
2979-
.subDocumentValue(SubDocumentValue.of(new String[]{"tag1"}))
2981+
.subDocumentValue(SubDocumentValue.of(new String[] {"tag1"}))
29802982
.build(),
29812983
// Nested JSONB: remove 'red' and 'blue' → leaves green
29822984
SubDocumentUpdate.builder()
29832985
.subDocument("props.colors")
29842986
.operator(UpdateOperator.REMOVE_ALL_FROM_LIST)
2985-
.subDocumentValue(SubDocumentValue.of(new String[]{"red", "blue"}))
2987+
.subDocumentValue(SubDocumentValue.of(new String[] {"red", "blue"}))
29862988
.build());
29872989

29882990
UpdateOptions options =
@@ -3427,9 +3429,33 @@ void testCreateOrReplaceRefreshesSchemaOnDroppedColumn() throws Exception {
34273429
class DropTests {
34283430

34293431
@Test
3430-
@DisplayName("Should throw UnsupportedOperationException for drop")
3431-
void testDrop() {
3432-
assertThrows(UnsupportedOperationException.class, () -> flatCollection.drop());
3432+
@DisplayName("Should drop the table successfully")
3433+
void testDrop() throws Exception {
3434+
// Create a separate collection to drop (don't drop the main test collection)
3435+
String dropTestCollection = "drop_test_collection";
3436+
createFlatCollectionSchema((PostgresDatastore) postgresDatastore, dropTestCollection);
3437+
Collection dropCollection =
3438+
postgresDatastore.getCollectionForType(dropTestCollection, DocumentType.FLAT);
3439+
3440+
Key key = new SingleValueKey("default", "drop-test-doc");
3441+
ObjectNode doc = OBJECT_MAPPER.createObjectNode();
3442+
doc.put("item", "test");
3443+
dropCollection.upsert(key, new JSONDocument(doc));
3444+
3445+
dropCollection.drop();
3446+
3447+
// Verify table no longer exists by trying to query it
3448+
PostgresDatastore pgDatastore = (PostgresDatastore) postgresDatastore;
3449+
try (Connection conn = pgDatastore.getPostgresClient();
3450+
PreparedStatement ps =
3451+
conn.prepareStatement(
3452+
String.format(
3453+
"SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = '%s')",
3454+
dropTestCollection));
3455+
ResultSet rs = ps.executeQuery()) {
3456+
assertTrue(rs.next());
3457+
assertFalse(rs.getBoolean(1));
3458+
}
34333459
}
34343460
}
34353461
}

0 commit comments

Comments
 (0)