Skip to content
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 @@ -212,6 +212,8 @@ enum RelationalOperator {
RELATIONAL_OPERATOR_LT = 6;
RELATIONAL_OPERATOR_GTE = 7;
RELATIONAL_OPERATOR_LTE = 8;
RELATIONAL_OPERATOR_EXISTS = 9;
RELATIONAL_OPERATOR_NOT_EXISTS = 10;
}

enum LogicalOperator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ private Filter evaluateLeafExpression(RelationalFilter relationalFilter) {
case RELATIONAL_OPERATOR_GTE:
return new Filter(
Filter.Op.GTE, buildConfigFieldPath(relationalFilter.getConfigJsonPath()), value);
case RELATIONAL_OPERATOR_EXISTS:
return new Filter(
Filter.Op.EXISTS, buildConfigFieldPath(relationalFilter.getConfigJsonPath()), value);
case RELATIONAL_OPERATOR_NOT_EXISTS:
return new Filter(
Filter.Op.NOT_EXISTS,
buildConfigFieldPath(relationalFilter.getConfigJsonPath()),
value);
case UNRECOGNIZED:
default:
throw Status.INVALID_ARGUMENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ private FilterTypeExpression buildRelationalExpression(RelationalFilter relation
case RELATIONAL_OPERATOR_GTE:
operator = RelationalOperator.GTE;
break;
case RELATIONAL_OPERATOR_EXISTS:
operator = RelationalOperator.EXISTS;
break;
case RELATIONAL_OPERATOR_NOT_EXISTS:
operator = RelationalOperator.NOT_EXISTS;
break;
case UNRECOGNIZED:
default:
throw Status.INVALID_ARGUMENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,41 @@ void buildDocStoreFilter2() {
assertEquals(docFilter.toString(), filterBuilder.buildDocStoreFilter(filter).toString());
}

@Test
void testExistsAndNotExistsOperators() {
// Test EXISTS operator
Filter existsFilter =
Filter.newBuilder()
.setRelationalFilter(
RelationalFilter.newBuilder()
.setConfigJsonPath("testField")
.setOperator(RelationalOperator.RELATIONAL_OPERATOR_EXISTS))
.build();

org.hypertrace.core.documentstore.Filter expectedExistsFilter =
new org.hypertrace.core.documentstore.Filter(
org.hypertrace.core.documentstore.Filter.Op.EXISTS, "config.testField", null);
assertEquals(
expectedExistsFilter.toString(),
filterBuilder.buildDocStoreFilter(existsFilter).toString());

// Test NOT_EXISTS operator
Filter notExistsFilter =
Filter.newBuilder()
.setRelationalFilter(
RelationalFilter.newBuilder()
.setConfigJsonPath("anotherField")
.setOperator(RelationalOperator.RELATIONAL_OPERATOR_NOT_EXISTS))
.build();

org.hypertrace.core.documentstore.Filter expectedNotExistsFilter =
new org.hypertrace.core.documentstore.Filter(
org.hypertrace.core.documentstore.Filter.Op.NOT_EXISTS, "config.anotherField", null);
assertEquals(
expectedNotExistsFilter.toString(),
filterBuilder.buildDocStoreFilter(notExistsFilter).toString());
}

@Test
void buildDocStoreFilter3() {
Filter filter =
Expand Down
Loading