Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Srikar Mannepalli authored and Srikar Mannepalli committed Dec 15, 2023
1 parent a039f9d commit d1d4ac7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,38 @@ public void testQueryV1AggregationFilter(String dataStoreName) throws IOExceptio
dataStoreName, resultDocs, "query/distinct_count_response.json", 4);
}

@ParameterizedTest
@ArgumentsSource(AllProvider.class)
public void testQueryV1AggregationWithInFilterWithPrimitiveLhs(final String dataStoreName) throws IOException {
final Collection collection = getCollection(dataStoreName);
final Query query = Query.builder()
.addSelection(IdentifierExpression.of("item"))
.addSelection(IdentifierExpression.of("quantity"))
.setFilter(
RelationalExpression.of(IdentifierExpression.of("item"), IN, ConstantExpression.ofStrings(List.of("Comb", "Shampoo")))
)
.build();

final Iterator<Document> resultDocs = collection.aggregate(query);
assertDocsAndSizeEqualWithoutOrder(dataStoreName, resultDocs, "query/test_primitive_lhs_in_filter_aggr_response.json", 4);
}

@ParameterizedTest
@ArgumentsSource(AllProvider.class)
public void testQueryV1AggregationWithInFilterWithArrayLhs(final String dataStoreName) throws IOException {
final Collection collection = getCollection(dataStoreName);
final Query query = Query.builder()
.addSelection(IdentifierExpression.of("item"))
.addSelection(IdentifierExpression.of("price"))
.setFilter(
RelationalExpression.of(IdentifierExpression.of("props.colors"), IN, ConstantExpression.ofStrings(List.of("Orange")))
)
.build();

final Iterator<Document> resultDocs = collection.aggregate(query);
assertDocsAndSizeEqualWithoutOrder(dataStoreName, resultDocs, "query/test_json_column_array_lhs_in_filter_aggr_response.json", 1);
}

@ParameterizedTest
@ArgumentsSource(AllProvider.class)
public void testQueryV1AggregationFilterWithWhereClause(String dataStoreName) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"item": "Soap",
"price": 20
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"item":"Comb",
"quantity": 10
},
{
"item":"Comb",
"quantity": 5
},
{
"item":"Shampoo",
"quantity": 20
},
{
"item":"Shampoo",
"quantity": 10
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ private boolean isOperatorNeedsFieldAccessor(RelationalOperator operator) {
case NOT_CONTAINS:
case EXISTS:
case NOT_EXISTS:
case IN:
case NOT_IN:
return true;
default:
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ private static StringBuilder prepareFilterStringForInOperator(
StreamSupport.stream(values.spliterator(), false)
.map(
val -> {
paramsBuilder.addObjectParam(val);
return "(jsonb_build_array(" + parsedExpression + ") @> jsonb_build_array(?))";
paramsBuilder.addObjectParam(val).addObjectParam(val);
return "((jsonb_typeof(to_jsonb("+parsedExpression+")) = 'array' AND to_jsonb("+parsedExpression+") @> jsonb_build_array(?)) OR (jsonb_build_array(" + parsedExpression + ") @> jsonb_build_array(?)))";
})
.collect(Collectors.joining(" OR "));
filterStringBuilder.append(collect);
Expand Down

0 comments on commit d1d4ac7

Please sign in to comment.