Search in sources :

Example 1 with IdentifierExpression

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);
}
Also used : IdentifierConverter(org.hypertrace.entity.query.service.converter.identifier.IdentifierConverter) ConstantExpression(org.hypertrace.core.documentstore.expression.impl.ConstantExpression) FilterTypeExpression(org.hypertrace.core.documentstore.expression.type.FilterTypeExpression) ColumnIdentifier(org.hypertrace.entity.query.service.v1.ColumnIdentifier) LiteralConstant(org.hypertrace.entity.query.service.v1.LiteralConstant) IdentifierExpression(org.hypertrace.core.documentstore.expression.impl.IdentifierExpression) Test(org.junit.jupiter.api.Test)

Example 2 with IdentifierExpression

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);
}
Also used : IdentifierConverter(org.hypertrace.entity.query.service.converter.identifier.IdentifierConverter) ConstantExpression(org.hypertrace.core.documentstore.expression.impl.ConstantExpression) FilterTypeExpression(org.hypertrace.core.documentstore.expression.type.FilterTypeExpression) ColumnIdentifier(org.hypertrace.entity.query.service.v1.ColumnIdentifier) LiteralConstant(org.hypertrace.entity.query.service.v1.LiteralConstant) IdentifierExpression(org.hypertrace.core.documentstore.expression.impl.IdentifierExpression) Test(org.junit.jupiter.api.Test)

Example 3 with IdentifierExpression

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));
}
Also used : IdentifierExpression(org.hypertrace.core.documentstore.expression.impl.IdentifierExpression) Test(org.junit.jupiter.api.Test)

Example 4 with IdentifierExpression

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();
}
Also used : ConversionException(org.hypertrace.entity.query.service.converter.ConversionException) RelationalOperator(org.hypertrace.core.documentstore.expression.operators.RelationalOperator) RelationalExpression(org.hypertrace.core.documentstore.expression.impl.RelationalExpression) ValueType(org.hypertrace.entity.query.service.v1.ValueType) ConstantExpression(org.hypertrace.core.documentstore.expression.impl.ConstantExpression) ArrayList(java.util.ArrayList) IdentifierExpression(org.hypertrace.core.documentstore.expression.impl.IdentifierExpression) IdentifierConverter(org.hypertrace.entity.query.service.converter.identifier.IdentifierConverter) Value(org.hypertrace.entity.query.service.v1.Value) IdentifierConversionMetadata(org.hypertrace.entity.query.service.converter.identifier.IdentifierConversionMetadata)

Example 5 with IdentifierExpression

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();
}
Also used : ConversionException(org.hypertrace.entity.query.service.converter.ConversionException) RelationalOperator(org.hypertrace.core.documentstore.expression.operators.RelationalOperator) RelationalExpression(org.hypertrace.core.documentstore.expression.impl.RelationalExpression) ValueType(org.hypertrace.entity.query.service.v1.ValueType) ConstantExpression(org.hypertrace.core.documentstore.expression.impl.ConstantExpression) ArrayList(java.util.ArrayList) IdentifierExpression(org.hypertrace.core.documentstore.expression.impl.IdentifierExpression) IdentifierConverter(org.hypertrace.entity.query.service.converter.identifier.IdentifierConverter) Value(org.hypertrace.entity.query.service.v1.Value) Map(java.util.Map) IdentifierConversionMetadata(org.hypertrace.entity.query.service.converter.identifier.IdentifierConversionMetadata)

Aggregations

IdentifierExpression (org.hypertrace.core.documentstore.expression.impl.IdentifierExpression)11 ConstantExpression (org.hypertrace.core.documentstore.expression.impl.ConstantExpression)6 IdentifierConverter (org.hypertrace.entity.query.service.converter.identifier.IdentifierConverter)6 ColumnIdentifier (org.hypertrace.entity.query.service.v1.ColumnIdentifier)5 RelationalOperator (org.hypertrace.core.documentstore.expression.operators.RelationalOperator)4 IdentifierConversionMetadata (org.hypertrace.entity.query.service.converter.identifier.IdentifierConversionMetadata)4 Value (org.hypertrace.entity.query.service.v1.Value)4 ValueType (org.hypertrace.entity.query.service.v1.ValueType)4 Test (org.junit.jupiter.api.Test)4 RelationalExpression (org.hypertrace.core.documentstore.expression.impl.RelationalExpression)3 ConversionException (org.hypertrace.entity.query.service.converter.ConversionException)3 ArrayList (java.util.ArrayList)2 FilterTypeExpression (org.hypertrace.core.documentstore.expression.type.FilterTypeExpression)2 Expression (org.hypertrace.entity.query.service.v1.Expression)2 LiteralConstant (org.hypertrace.entity.query.service.v1.LiteralConstant)2 Map (java.util.Map)1 AggregateExpression (org.hypertrace.core.documentstore.expression.impl.AggregateExpression)1 AggregationOperator (org.hypertrace.core.documentstore.expression.operators.AggregationOperator)1 SortOrder (org.hypertrace.core.documentstore.expression.operators.SortOrder)1 FromTypeExpression (org.hypertrace.core.documentstore.expression.type.FromTypeExpression)1