use of org.hypertrace.core.documentstore.expression.operators.RelationalOperator 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.operators.RelationalOperator 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();
}
use of org.hypertrace.core.documentstore.expression.operators.RelationalOperator in project entity-service by hypertrace.
the class NullFilteringExpressionConverter method convert.
@Override
public FilterTypeExpression convert(final ColumnIdentifier columnIdentifier, final Operator operator, final LiteralConstant constant, final RequestContext requestContext) throws ConversionException {
final String id = columnIdentifier.getColumnName();
final String subDocPath = getSubDocPathById(entityAttributeMapping, id, requestContext);
final Value value = constant.getValue();
final ValueType valueType = value.getValueType();
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 IdentifierExpression identifierExpression = IdentifierExpression.of(suffixedSubDocPath);
final RelationalOperator relationalOperator = convertOperator(operator);
final ConstantExpression constantExpression = constantExpressionConverter.convert(constant, requestContext);
RelationalExpression relationalExpression = RelationalExpression.of(identifierExpression, relationalOperator, constantExpression);
switch(operator) {
// 'field' EQ 'null' -> 'field' EQ 'null' || 'field' NOT_EXISTS
case EQ:
RelationalExpression nonExistenceRelationalExpression = RelationalExpression.of(identifierExpression, convertOperator(Operator.NOT_EXISTS), constantExpression);
return LogicalExpression.builder().operator(LogicalOperator.OR).operands(List.of(nonExistenceRelationalExpression, relationalExpression)).build();
default:
return relationalExpression;
}
}
use of org.hypertrace.core.documentstore.expression.operators.RelationalOperator in project entity-service by hypertrace.
the class PrimitiveFilteringExpressionConverter method convert.
@Override
public FilterTypeExpression convert(final ColumnIdentifier columnIdentifier, final Operator operator, final LiteralConstant constant, final RequestContext requestContext) throws ConversionException {
final String id = columnIdentifier.getColumnName();
final String subDocPath = getSubDocPathById(entityAttributeMapping, id, requestContext);
final Value value = constant.getValue();
final ValueType valueType = value.getValueType();
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 IdentifierExpression identifierExpression = IdentifierExpression.of(suffixedSubDocPath);
final RelationalOperator relationalOperator = convertOperator(operator);
final ConstantExpression constantExpression = constantExpressionConverter.convert(constant, requestContext);
return RelationalExpression.of(identifierExpression, relationalOperator, constantExpression);
}
use of org.hypertrace.core.documentstore.expression.operators.RelationalOperator in project document-store by hypertrace.
the class MongoRelationalExpressionParser method parse.
Map<String, Object> parse(final RelationalExpression expression) {
SelectTypeExpression lhs = expression.getLhs();
RelationalOperator operator = expression.getOperator();
SelectTypeExpression rhs = expression.getRhs();
// Only an identifier LHS and a constant RHS is supported as of now.
MongoSelectTypeExpressionParser lhsParser = new MongoIdentifierExpressionParser();
MongoSelectTypeExpressionParser rhsParser = new MongoConstantExpressionParser();
String key = lhs.accept(lhsParser);
Object value = rhs.accept(rhsParser);
return generateMap(key, value, operator);
}
Aggregations