use of org.hypertrace.core.documentstore.Filter in project entity-service by hypertrace.
the class DocStoreConverterTest method testInFilterConversion.
@Test
public void testInFilterConversion() {
Query query = Query.newBuilder().setFilter(AttributeFilter.newBuilder().setName(EntityConstants.ATTRIBUTES_MAP_PATH).setOperator(Operator.IN).setAttributeValue(AttributeValue.newBuilder().setValueList(AttributeValueList.newBuilder().addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("attr-v1"))).addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("attr-v2"))).addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("attr-v3")))).build()).build()).build();
org.hypertrace.core.documentstore.Query transformedQuery = DocStoreConverter.transform(TENANT_ID, query, Collections.emptyList());
Filter transformedFilter = transformedQuery.getFilter();
Assertions.assertEquals(Filter.Op.AND, transformedFilter.getOp());
Assertions.assertEquals(2, transformedFilter.getChildFilters().length);
Assertions.assertEquals("attributes.value.string", transformedFilter.getChildFilters()[1].getFieldName());
Assertions.assertEquals(Filter.Op.IN, transformedFilter.getChildFilters()[1].getOp());
Assertions.assertEquals(List.of("attr-v1", "attr-v2", "attr-v3"), transformedFilter.getChildFilters()[1].getValue());
// Empty value list. Default to string attribute value type for the field name
Query query2 = Query.newBuilder().setFilter(AttributeFilter.newBuilder().setName(EntityConstants.ATTRIBUTES_MAP_PATH).setOperator(Operator.IN).setAttributeValue(AttributeValue.newBuilder().setValueList(AttributeValueList.newBuilder()).build()).build()).build();
org.hypertrace.core.documentstore.Query transformedQuery2 = DocStoreConverter.transform(TENANT_ID, query2, Collections.emptyList());
Filter transformedFilter2 = transformedQuery2.getFilter();
Assertions.assertEquals(Filter.Op.AND, transformedFilter2.getOp());
Assertions.assertEquals(2, transformedFilter2.getChildFilters().length);
Assertions.assertEquals("attributes.value.string", transformedFilter2.getChildFilters()[1].getFieldName());
Assertions.assertEquals(Filter.Op.IN, transformedFilter2.getChildFilters()[1].getOp());
Assertions.assertEquals(List.of(), transformedFilter2.getChildFilters()[1].getValue());
// Long list
Query query3 = Query.newBuilder().setFilter(AttributeFilter.newBuilder().setName(EntityConstants.ATTRIBUTES_MAP_PATH).setOperator(Operator.IN).setAttributeValue(AttributeValue.newBuilder().setValueList(AttributeValueList.newBuilder().addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setLong(21L))).addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setLong(22L)))).build()).build()).build();
org.hypertrace.core.documentstore.Query transformedQuery3 = DocStoreConverter.transform(TENANT_ID, query3, Collections.emptyList());
Filter transformedFilter3 = transformedQuery3.getFilter();
Assertions.assertEquals(Filter.Op.AND, transformedFilter3.getOp());
Assertions.assertEquals(2, transformedFilter3.getChildFilters().length);
Assertions.assertEquals("attributes.value.long", transformedFilter3.getChildFilters()[1].getFieldName());
Assertions.assertEquals(Filter.Op.IN, transformedFilter3.getChildFilters()[1].getOp());
Assertions.assertEquals(List.of(21L, 22L), transformedFilter3.getChildFilters()[1].getValue());
// CreatedTime field. Will not be part of attributes and so no need to specify the type suffix
Query query4 = Query.newBuilder().setFilter(AttributeFilter.newBuilder().setName(EntityServiceConstants.ENTITY_CREATED_TIME).setOperator(Operator.IN).setAttributeValue(AttributeValue.newBuilder().setValueList(AttributeValueList.newBuilder().addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setLong(21L))).addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setLong(22L)))).build()).build()).build();
org.hypertrace.core.documentstore.Query transformedQuery4 = DocStoreConverter.transform(TENANT_ID, query4, Collections.emptyList());
Filter transformedFilter4 = transformedQuery4.getFilter();
Assertions.assertEquals(Filter.Op.AND, transformedFilter4.getOp());
Assertions.assertEquals(2, transformedFilter4.getChildFilters().length);
Assertions.assertEquals("createdTime", transformedFilter4.getChildFilters()[1].getFieldName());
Assertions.assertEquals(Filter.Op.IN, transformedFilter4.getChildFilters()[1].getOp());
Assertions.assertEquals(List.of(21L, 22L), transformedFilter4.getChildFilters()[1].getValue());
}
use of org.hypertrace.core.documentstore.Filter in project entity-service by hypertrace.
the class DocStoreConverterTest method testStringArrayValueTypeColumnNeqAndChain.
@Test
public void testStringArrayValueTypeColumnNeqAndChain() throws JsonProcessingException {
Query query = Query.newBuilder().addEntityId("some id").setFilter(AttributeFilter.newBuilder().setOperator(Operator.AND).addChildFilter(AttributeFilter.newBuilder().setName(ATTRIBUTES_LABELS_FIELD_NAME).setIsMultiValued(true).setOperator(Operator.NEQ).setAttributeValue(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("l1")))).addChildFilter(AttributeFilter.newBuilder().setName(ATTRIBUTES_LABELS_FIELD_NAME).setIsMultiValued(true).setOperator(Operator.NEQ).setAttributeValue(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("l2"))))).build();
org.hypertrace.core.documentstore.Query transformedQuery = DocStoreConverter.transform(TENANT_ID, query, Collections.emptyList());
Filter transformedFilter = transformedQuery.getFilter();
Assertions.assertEquals(Filter.Op.AND, transformedFilter.getOp());
Assertions.assertEquals(3, transformedFilter.getChildFilters().length);
Assertions.assertEquals(EntityServiceConstants.ENTITY_ID, transformedFilter.getChildFilters()[1].getFieldName());
Assertions.assertEquals(Collections.singletonList("some id"), transformedFilter.getChildFilters()[1].getValue());
Assertions.assertEquals(Op.AND, transformedFilter.getChildFilters()[2].getOp());
Assertions.assertEquals(ATTRIBUTES_LABELS_FIELD_NAME + ".valueList.values", transformedFilter.getChildFilters()[2].getChildFilters()[0].getFieldName());
Assertions.assertEquals(Op.NEQ, transformedFilter.getChildFilters()[2].getChildFilters()[0].getOp());
Assertions.assertEquals(OBJECT_MAPPER.convertValue(OBJECT_MAPPER.readTree("{\"value\": {\"string\":\"l1\"}}"), Map.class), transformedFilter.getChildFilters()[2].getChildFilters()[0].getValue());
Assertions.assertEquals(ATTRIBUTES_LABELS_FIELD_NAME + ".valueList.values", transformedFilter.getChildFilters()[2].getChildFilters()[1].getFieldName());
Assertions.assertEquals(Op.NEQ, transformedFilter.getChildFilters()[2].getChildFilters()[1].getOp());
Assertions.assertEquals(OBJECT_MAPPER.convertValue(OBJECT_MAPPER.readTree("{\"value\": {\"string\":\"l2\"}}"), Map.class), transformedFilter.getChildFilters()[2].getChildFilters()[1].getValue());
}
use of org.hypertrace.core.documentstore.Filter in project entity-service by hypertrace.
the class DocStoreConverterTest method testStringArrayValueTypeColumnEq.
@Test
public void testStringArrayValueTypeColumnEq() throws JsonProcessingException {
Query query = Query.newBuilder().addEntityId("some id").setFilter(AttributeFilter.newBuilder().setName(ATTRIBUTES_LABELS_FIELD_NAME).setIsMultiValued(true).setOperator(Operator.EQ).setAttributeValue(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("l1")))).build();
org.hypertrace.core.documentstore.Query transformedQuery = DocStoreConverter.transform(TENANT_ID, query, Collections.emptyList());
Filter transformedFilter = transformedQuery.getFilter();
Assertions.assertEquals(Filter.Op.AND, transformedFilter.getOp());
Assertions.assertEquals(3, transformedFilter.getChildFilters().length);
Assertions.assertEquals(EntityServiceConstants.ENTITY_ID, transformedFilter.getChildFilters()[1].getFieldName());
Assertions.assertEquals(Collections.singletonList("some id"), transformedFilter.getChildFilters()[1].getValue());
Assertions.assertEquals(ATTRIBUTES_LABELS_FIELD_NAME + ".valueList.values", transformedFilter.getChildFilters()[2].getFieldName());
Assertions.assertEquals(Op.EQ, transformedFilter.getChildFilters()[2].getOp());
Assertions.assertEquals(OBJECT_MAPPER.convertValue(OBJECT_MAPPER.readTree("{\"value\": {\"string\":\"l1\"}}"), Map.class), transformedFilter.getChildFilters()[2].getValue());
}
use of org.hypertrace.core.documentstore.Filter in project entity-service by hypertrace.
the class DocStoreConverterTest method testFilterNonAttributesFieldNames.
@Test
public void testFilterNonAttributesFieldNames() {
Query query = Query.newBuilder().addEntityId("some id").setFilter(AttributeFilter.newBuilder().setName("API.createdTime").setOperator(Operator.GT).setAttributeValue(AttributeValue.newBuilder().setValue(Value.newBuilder().setLong(1234L).build()).build()).build()).build();
org.hypertrace.core.documentstore.Query transformedQuery = DocStoreConverter.transform(TENANT_ID, query, Collections.emptyList());
Filter transformedFilter = transformedQuery.getFilter();
Assertions.assertEquals(Filter.Op.AND, transformedFilter.getOp());
Assertions.assertEquals(3, transformedFilter.getChildFilters().length);
Assertions.assertEquals(EntityServiceConstants.ENTITY_ID, transformedFilter.getChildFilters()[1].getFieldName());
Assertions.assertEquals(Collections.singletonList("some id"), transformedFilter.getChildFilters()[1].getValue());
Assertions.assertEquals("API.createdTime", transformedFilter.getChildFilters()[2].getFieldName());
Assertions.assertEquals(Filter.Op.GT, transformedFilter.getChildFilters()[2].getOp());
Assertions.assertEquals(1234L, transformedFilter.getChildFilters()[2].getValue());
}
use of org.hypertrace.core.documentstore.Filter in project entity-service by hypertrace.
the class DocStoreConverterTest method testEqFilterConversionForValueList.
@Test
public void testEqFilterConversionForValueList() throws IOException {
Query query = Query.newBuilder().setFilter(AttributeFilter.newBuilder().setName(EntityConstants.ATTRIBUTES_MAP_PATH).setOperator(Operator.EQ).setAttributeValue(AttributeValue.newBuilder().setValueList(AttributeValueList.newBuilder().addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("{\"a1\":\"v1\"}"))).addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("{\"a2\":\"v2\"}"))).addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("{\"a3\":\"v3\"}")))).build()).build()).build();
org.hypertrace.core.documentstore.Query transformedQuery = DocStoreConverter.transform(TENANT_ID, query, Collections.emptyList());
Filter transformedFilter = transformedQuery.getFilter();
Assertions.assertEquals(Filter.Op.AND, transformedFilter.getOp());
Assertions.assertEquals(2, transformedFilter.getChildFilters().length);
Assertions.assertEquals("attributes.valueList.values", transformedFilter.getChildFilters()[1].getFieldName());
Assertions.assertEquals(Filter.Op.EQ, transformedFilter.getChildFilters()[1].getOp());
// I am not sure what if the value conversion is correct for this but will not modify it this
// time. Will leave and test
// the logic as is for now.
Assertions.assertEquals(List.of(OBJECT_MAPPER.convertValue(OBJECT_MAPPER.readTree(JSONFORMAT_PRINTER.print(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("{\"a1\":\"v1\"}")))), Map.class), OBJECT_MAPPER.convertValue(OBJECT_MAPPER.readTree(JSONFORMAT_PRINTER.print(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("{\"a2\":\"v2\"}")))), Map.class), OBJECT_MAPPER.convertValue(OBJECT_MAPPER.readTree(JSONFORMAT_PRINTER.print(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("{\"a3\":\"v3\"}")))), Map.class)), transformedFilter.getChildFilters()[1].getValue());
}
Aggregations