use of org.hypertrace.core.documentstore.expression.impl.IdentifierExpression in project entity-service by hypertrace.
the class NullFilteringExpressionConverterTest method testEqNull.
@Test
void testEqNull() throws ConversionException {
ColumnIdentifier columnIdentifier = ColumnIdentifier.newBuilder().setColumnName("column1").build();
LiteralConstant constant = LiteralConstant.newBuilder().setValue(Value.newBuilder().setString("null").build()).build();
when(entityAttributeMapping.getDocStorePathByAttributeId(REQUEST_CONTEXT, "column1")).thenReturn(Optional.of("subDocPath1"));
IdentifierConverter identifierConverter = mock(IdentifierConverter.class);
when(identifierConverter.convert(any(), eq(REQUEST_CONTEXT))).thenReturn("attributes.subDocPath1");
when(identifierConverterFactory.getIdentifierConverter("column1", "subDocPath1", ValueType.STRING, REQUEST_CONTEXT)).thenReturn(identifierConverter);
ConstantExpression constantExpression = ConstantExpression.of("null");
when(constantExpressionConverter.convert(constant, REQUEST_CONTEXT)).thenReturn(constantExpression);
FilterTypeExpression filterTypeExpression = nullFilteringExpressionConverter.convert(columnIdentifier, Operator.EQ, constant, REQUEST_CONTEXT);
IdentifierExpression identifierExpression = IdentifierExpression.of("attributes.subDocPath1");
assertEquals(LogicalExpression.builder().operator(LogicalOperator.OR).operands(List.of(RelationalExpression.of(identifierExpression, RelationalOperator.NOT_EXISTS, constantExpression), RelationalExpression.of(identifierExpression, RelationalOperator.EQ, constantExpression))).build(), filterTypeExpression);
}
use of org.hypertrace.core.documentstore.expression.impl.IdentifierExpression in project entity-service by hypertrace.
the class NullFilteringExpressionConverterTest method testNeqNull.
@Test
void testNeqNull() throws ConversionException {
ColumnIdentifier columnIdentifier = ColumnIdentifier.newBuilder().setColumnName("column1").build();
LiteralConstant constant = LiteralConstant.newBuilder().setValue(Value.newBuilder().setString("null").build()).build();
when(entityAttributeMapping.getDocStorePathByAttributeId(REQUEST_CONTEXT, "column1")).thenReturn(Optional.of("subDocPath1"));
IdentifierConverter identifierConverter = mock(IdentifierConverter.class);
when(identifierConverter.convert(any(), eq(REQUEST_CONTEXT))).thenReturn("attributes.subDocPath1");
when(identifierConverterFactory.getIdentifierConverter("column1", "subDocPath1", ValueType.STRING, REQUEST_CONTEXT)).thenReturn(identifierConverter);
ConstantExpression constantExpression = ConstantExpression.of("null");
when(constantExpressionConverter.convert(constant, REQUEST_CONTEXT)).thenReturn(constantExpression);
FilterTypeExpression filterTypeExpression = nullFilteringExpressionConverter.convert(columnIdentifier, Operator.NEQ, constant, REQUEST_CONTEXT);
IdentifierExpression identifierExpression = IdentifierExpression.of("attributes.subDocPath1");
assertEquals(RelationalExpression.of(identifierExpression, RelationalOperator.NEQ, constantExpression), filterTypeExpression);
}
use of org.hypertrace.core.documentstore.expression.impl.IdentifierExpression in project entity-service by hypertrace.
the class IdentifierExpressionConverterTest method testConvertArray.
@Test
void testConvertArray() throws ConversionException {
when(attributeMapping.getDocStorePathByAttributeId(requestContext, columnIdentifier.getColumnName())).thenReturn(Optional.of("attributes.entity_name"));
when(attributeMapping.isMultiValued(requestContext, columnIdentifier.getColumnName())).thenReturn(true);
IdentifierExpression expected = IdentifierExpression.of("attributes.entity_name.valueList.values");
assertEquals(expected, identifierExpressionConverter.convert(columnIdentifier, requestContext));
}
use of org.hypertrace.core.documentstore.expression.impl.IdentifierExpression in project entity-service by hypertrace.
the class ArrayFilteringExpressionConverter method convert.
@Override
public FilterTypeExpression convert(final ColumnIdentifier columnIdentifier, final Operator operator, final LiteralConstant constant, final RequestContext requestContext) throws ConversionException {
if (ARRAY_OPERATORS.contains(operator)) {
return primitiveFilteringExpressionConverter.convert(columnIdentifier, operator, constant, requestContext);
}
final String id = columnIdentifier.getColumnName();
final String subDocPath = getSubDocPathById(entityAttributeMapping, id, requestContext);
final Value value = constant.getValue();
final ValueType valueType = value.getValueType();
final List<?> list = valueOneOfAccessor.access(value, valueType);
if (list.isEmpty()) {
throw new ConversionException("Conversion of empty-list is unsupported");
}
final IdentifierConverter identifierConverter = identifierConverterFactory.getIdentifierConverter(id, subDocPath, valueType, requestContext);
final IdentifierConversionMetadata metadata = IdentifierConversionMetadata.builder().subDocPath(subDocPath).operator(operator).valueType(valueType).build();
final String suffixedSubDocPath = identifierConverter.convert(metadata, requestContext);
final List<RelationalExpression> expressions = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
final IdentifierExpression lhs = IdentifierExpression.of(String.format(suffixedSubDocPath, i));
final RelationalOperator relationalOperator = convertOperator(operator);
final ConstantExpression rhs = valueHelper.convertToConstantExpression(value, i);
final RelationalExpression expression = RelationalExpression.of(lhs, relationalOperator, rhs);
expressions.add(expression);
}
if (expressions.size() == 1) {
return expressions.get(0);
}
return LogicalExpression.builder().operator(LogicalOperator.AND).operands(expressions).build();
}
use of org.hypertrace.core.documentstore.expression.impl.IdentifierExpression in project entity-service by hypertrace.
the class MapFilteringExpressionConverter method convert.
@Override
public FilterTypeExpression convert(final ColumnIdentifier columnIdentifier, final Operator operator, final LiteralConstant constant, final RequestContext requestContext) throws ConversionException {
if (!SUPPORTED_OPERATORS.contains(operator)) {
throw new ConversionException(String.format("Operator %s is not supported", operator));
}
final String id = columnIdentifier.getColumnName();
final String subDocPath = getSubDocPathById(entityAttributeMapping, id, requestContext);
final Value value = constant.getValue();
final ValueType valueType = value.getValueType();
final Map<?, ?> map = valueOneOfAccessor.access(value, valueType);
if (map.isEmpty()) {
throw new ConversionException("Conversion of empty-map is unsupported");
}
final IdentifierConverter identifierConverter = identifierConverterFactory.getIdentifierConverter(id, subDocPath, valueType, requestContext);
final IdentifierConversionMetadata metadata = IdentifierConversionMetadata.builder().subDocPath(subDocPath).operator(operator).valueType(valueType).build();
final String suffixedSubDocPath = identifierConverter.convert(metadata, requestContext);
final List<RelationalExpression> expressions = new ArrayList<>();
for (final Map.Entry<?, ?> entry : map.entrySet()) {
final IdentifierExpression lhs = IdentifierExpression.of(String.format(suffixedSubDocPath, entry.getKey()));
final RelationalOperator relationalOperator = convertOperator(operator);
final ConstantExpression rhs = valueHelper.convertToConstantExpression(value, entry.getKey());
final RelationalExpression expression = RelationalExpression.of(lhs, relationalOperator, rhs);
expressions.add(expression);
}
if (expressions.size() == 1) {
return expressions.get(0);
}
return LogicalExpression.builder().operator(LogicalOperator.AND).operands(expressions).build();
}
Aggregations