Skip to content

Commit

Permalink
added funtional operator for supporting case insensitive exact matchi… (
Browse files Browse the repository at this point in the history
#201)

* added funtional operator for supporting case insensitive exact matching in mongo

* addressed

* update
  • Loading branch information
patelraj0602 authored Jul 9, 2024
1 parent c7ea09e commit edd1dab
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
import org.hypertrace.core.documentstore.expression.impl.LogicalExpression;
import org.hypertrace.core.documentstore.expression.impl.RelationalExpression;
import org.hypertrace.core.documentstore.expression.impl.UnnestExpression;
import org.hypertrace.core.documentstore.expression.operators.FunctionOperator;
import org.hypertrace.core.documentstore.expression.operators.RelationalOperator;
import org.hypertrace.core.documentstore.expression.type.FilterTypeExpression;
import org.hypertrace.core.documentstore.model.options.UpdateOptions;
import org.hypertrace.core.documentstore.model.subdoc.SubDocumentUpdate;
Expand Down Expand Up @@ -3362,6 +3364,37 @@ public void testMongoFunctionExpressionGroupBy(String dataStoreName) throws Exce
testCountApi(dataStoreName, query, "query/function_expression_group_by_response.json");
}

@ParameterizedTest
@ArgumentsSource(MongoProvider.class)
public void testToLowerCaseMongoFunctionOperator(String dataStoreName) throws Exception {
Collection collection = getCollection(dataStoreName);

List<SelectionSpec> selectionSpecs =
List.of(
SelectionSpec.of(IdentifierExpression.of("item")),
SelectionSpec.of(IdentifierExpression.of("price")),
SelectionSpec.of(IdentifierExpression.of("quantity")),
SelectionSpec.of(IdentifierExpression.of("date")));
Selection selection = Selection.builder().selectionSpecs(selectionSpecs).build();
Filter filter =
Filter.builder()
.expression(
RelationalExpression.of(
FunctionExpression.builder()
.operator(FunctionOperator.TO_LOWER_CASE)
.operand(IdentifierExpression.of("item"))
.build(),
RelationalOperator.EQ,
ConstantExpression.of("shampoo")))
.build();

Query query = Query.builder().setSelection(selection).setFilter(filter).build();

Iterator<Document> resultDocs = collection.find(query);
assertDocsAndSizeEqualWithoutOrder(
dataStoreName, resultDocs, "query/case_insensitive_exact_match_response.json", 2);
}

private static Collection getCollection(final String dataStoreName) {
return getCollection(dataStoreName, COLLECTION_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"date": "2014-03-15T09:00:00Z",
"item": "Shampoo",
"price": 5,
"quantity": 10
},
{
"date": "2014-04-04T11:21:39.736Z",
"item": "Shampoo",
"price": 5,
"quantity": 20
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public enum FunctionOperator {
// Unary operations
TO_LOWER_CASE,
ABS,
FLOOR,
LENGTH, // This operator returns the length of an array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.hypertrace.core.documentstore.expression.operators.FunctionOperator.LENGTH;
import static org.hypertrace.core.documentstore.expression.operators.FunctionOperator.MULTIPLY;
import static org.hypertrace.core.documentstore.expression.operators.FunctionOperator.SUBTRACT;
import static org.hypertrace.core.documentstore.expression.operators.FunctionOperator.TO_LOWER_CASE;
import static org.hypertrace.core.documentstore.mongo.MongoUtils.getUnsupportedOperationException;

import java.util.EnumMap;
Expand All @@ -32,6 +33,7 @@ public final class MongoFunctionExpressionParser extends MongoSelectTypeExpressi
put(DIVIDE, "$divide");
put(MULTIPLY, "$multiply");
put(SUBTRACT, "$subtract");
put(TO_LOWER_CASE, "$toLower");
}
});

Expand Down

0 comments on commit edd1dab

Please sign in to comment.