Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the Postgres issue with the removal of an element from a singleton list #185

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2639,7 +2639,53 @@ void testUpdateWithAllOperatorsOnObject(final String datastoreName) throws IOExc

@ParameterizedTest
@ArgumentsSource(AllProvider.class)
void testRemoveAllOccurrancesFromIntegerList(final String datastoreName) throws IOException {
void testRemoveFromSingletonList(final String datastoreName) throws IOException {
final Collection collection = getCollection(datastoreName, UPDATABLE_COLLECTION_NAME);
createCollectionData("query/updatable_collection_data.json", UPDATABLE_COLLECTION_NAME);

final SubDocumentUpdate set =
SubDocumentUpdate.builder()
.subDocument("props.added.habitable_planets")
.operator(SET)
.subDocumentValue(SubDocumentValue.of(new String[] {"Earth"}))
.build();

final Query query = Query.builder().build();
final List<SubDocumentUpdate> updates = List.of(set);

final CloseableIterator<Document> iterator =
collection.bulkUpdate(
query, updates, UpdateOptions.builder().returnDocumentType(AFTER_UPDATE).build());

assertDocsAndSizeEqualWithoutOrder(
datastoreName,
iterator,
"query/update_operator/updated_set_string_array_with_singleton_element.json",
9);

final SubDocumentUpdate remove =
SubDocumentUpdate.builder()
.subDocument("props.added.habitable_planets")
.operator(REMOVE_ALL_FROM_LIST)
.subDocumentValue(SubDocumentValue.of(new String[] {"Earth"}))
.build();

final List<SubDocumentUpdate> newUpdates = List.of(remove);

final CloseableIterator<Document> newIterator =
collection.bulkUpdate(
query, newUpdates, UpdateOptions.builder().returnDocumentType(AFTER_UPDATE).build());

assertDocsAndSizeEqualWithoutOrder(
datastoreName,
newIterator,
"query/update_operator/updated_remove_from_string_array_with_singleton_element.json",
9);
}

@ParameterizedTest
@ArgumentsSource(AllProvider.class)
void testRemoveAllOccurrencesFromIntegerList(final String datastoreName) throws IOException {
final Collection collection = getCollection(datastoreName, UPDATABLE_COLLECTION_NAME);
createCollectionData("query/updatable_collection_data.json", UPDATABLE_COLLECTION_NAME);

Expand All @@ -2655,9 +2701,8 @@ void testRemoveAllOccurrancesFromIntegerList(final String datastoreName) throws
final Query query = Query.builder().build();
final List<SubDocumentUpdate> updates = List.of(set, unset);

final CloseableIterator<Document> iterator =
collection.bulkUpdate(
query, updates, UpdateOptions.builder().returnDocumentType(NONE).build());
collection.bulkUpdate(
query, updates, UpdateOptions.builder().returnDocumentType(NONE).build());

final SubDocumentUpdate remove =
SubDocumentUpdate.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
[
{
"item": "Soap",
"price": 10,
"quantity": 2,
"date": "2014-03-01T08:00:00Z",
"props": {
"brand": "Dettol",
"size": "M",
"seller": {
"name": "Metro Chemicals Pvt. Ltd.",
"address": {
"city": "Mumbai",
"pincode": 400004
}
},
"added": {
"habitable_planets": [
]
}
},
"sales": [
{
"city": "delhi",
"medium": [
{
"type": "distributionChannel",
"volume": 1000
},
{
"type": "retail",
"volume": 500
},
{
"type": "online",
"volume": 1000
}
]
},
{
"city": "pune",
"medium": [
{
"type": "distributionChannel",
"volume": 300
},
{
"type": "online",
"volume": 2000
}
]
}
]
},
{
"item": "Mirror",
"price": 20,
"quantity": 1,
"date": "2014-03-01T09:00:00Z",
"sales": [
{
"city": "delhi",
"medium": []
}
],
"props": {
"added": {
"habitable_planets": [
]
}
}
},
{
"item": "Shampoo",
"price": 5,
"quantity": 10,
"date": "2014-03-15T09:00:00Z",
"props": {
"brand": "Sunsilk",
"size": "L",
"seller": {
"name": "Metro Chemicals Pvt. Ltd.",
"address": {
"city": "Mumbai",
"pincode": 400004
}
},
"added": {
"habitable_planets": [
]
}
},
"sales": [
{
"city": "delhi",
"medium": [
{
"type": "distributionChannel",
"volume": 3000
},
{
"type": "retail",
"volume": 500
},
{
"type": "online",
"volume": 1000
}
]
},
{
"city": "mumbai",
"medium": [
{
"type": "distributionChannel",
"volume": 700
},
{
"type": "retail",
"volume": 500
},
{
"type": "online",
"volume": 5000
}
]
}
]
},
{
"item": "Shampoo",
"price": 5,
"quantity": 20,
"date": "2014-04-04T11:21:39.736Z",
"sales": [],
"props": {
"added": {
"habitable_planets": [
]
}
}
},
{
"item": "Soap",
"price": 20,
"quantity": 5,
"date": "2014-04-04T21:23:13.331Z",
"props": {
"brand": "Lifebuoy",
"size": "S",
"seller": {
"name": "Hans and Co.",
"address": {
"city": "Kolkata",
"pincode": 700007
}
},
"added": {
"habitable_planets": [
]
}
}
},
{
"item": "Comb",
"price": 7.5,
"quantity": 5,
"date": "2015-06-04T05:08:13Z",
"props": {
"added": {
"habitable_planets": [
]
}
}
},
{
"item": "Comb",
"price": 7.5,
"quantity": 10,
"date": "2015-09-10T08:43:00Z",
"props": {
"seller": {
"name": "Go Go Plastics",
"address": {
"city": "Kolkata",
"pincode": 700007
}
},
"added": {
"habitable_planets": [
]
}
}
},
{
"item": "Soap",
"price": 10,
"quantity": 5,
"date": "2016-02-06T20:20:13Z",
"props": {
"added": {
"habitable_planets": [
]
}
}
},
{
"item": "Soap",
"price": 88,
"quantity": 50,
"date": "2023-08-09T18:53:17Z",
"props": {
"added": {
"habitable_planets": [
]
}
}
}
]
Loading