/** * Constructor takes a {@link StringFilterClause} object to construct from. * * @param stringFilterClause The {@link StringFilterClause} object tor construct from. */ public ObjectFilterClause(StringFilterClause stringFilterClause) { this.operation = stringFilterClause.operation; this.field = stringFilterClause.field; this.patterns = stringFilterClause.patterns; List<String> stringValues = stringFilterClause.getValues(); if (stringValues != null) { values = stringValues.stream().map(s -> s == null ? null : new Value(Value.Kind.VALUE, s)).collect(Collectors.toList()); } }
@Override public Optional<List<BulletError>> initialize() { if (value == null) { return Optional.of(Collections.singletonList(LEAF_EXPRESSION_REQUIRES_VALUE_FIELD_ERROR)); } Optional<List<BulletError>> errors = value.initialize(); if (errors.isPresent()) { return errors; } if (value.getType() != null && !Type.PRIMITIVES.contains(value.getType())) { return Optional.of(Collections.singletonList(LEAF_EXPRESSION_REQUIRES_PRIMITIVE_TYPE_ERROR)); } if (value.getKind() == Value.Kind.VALUE && value.getType() == null) { return Optional.of(Collections.singletonList(LEAF_EXPRESSION_VALUE_KIND_REQUIRES_TYPE_ERROR)); } return Optional.empty(); } }
private TypedObject calculateLeafExpression(LeafExpression expression, BulletRecord record) { Value value = expression.getValue(); TypedObject result = null; String valueString = value.getValue(); Type type = value.getType(); switch (value.getKind()) { case FIELD: result = extractTypedObject(valueString, record); if (type != null) { result = result.forceCast(type); } break; case VALUE: result = TypedObject.forceCast(type, valueString); break; } return result; }
protected com.yahoo.bullet.parsing.Expression visitCastExpression(CastExpression node, Void context) throws ParsingException { if (containsCastExpression(node.getExpression())) { throw new ParsingException("Casting of cast expressions is not supported"); } com.yahoo.bullet.parsing.Expression expression = process(node.getExpression()); if (expression instanceof BinaryExpression) { ((BinaryExpression) expression).setType(Type.valueOf(node.getCastType().toUpperCase())); } else { Value value = ((LeafExpression) expression).getValue(); ((LeafExpression) expression).setValue(new Value(value.getKind(), value.getValue(), Type.valueOf(node.getCastType().toUpperCase()))); } return expression; }
@Override public String getValue(Value value) { return value.getValue(); }
@Override public Optional<List<BulletError>> initialize() { Optional<List<BulletError>> errors = super.initialize(); if (errors.isPresent()) { return errors; } if (values != null) { for (Value value : values) { errors = value.initialize(); if (errors.isPresent()) { return errors; } } } return Optional.empty(); } }
private static TypedObject getTypedValue(BulletRecord record, Type type, Value value) { TypedObject result = null; String valueString = value.getValue(); Type newType = value.getType(); switch (value.getKind()) { case FIELD: result = newType == null ? TypedObject.typeCastFromObject(type, record.extractField(valueString)) : extractTypedObject(valueString, record).forceCast(newType); break; case VALUE: result = newType == null ? TypedObject.typeCast(type, valueString) : TypedObject.forceCast(newType, valueString); break; } return result; }
private Clause createFilterClause(Operation operation, String field, String... values) { FilterClause filterClause = new ObjectFilterClause(); filterClause.setOperation(operation); filterClause.setField(field); filterClause.setValues(Stream.of(values).map(v -> new Value(Value.Kind.VALUE, v)).collect(Collectors.toList())); return filterClause; }
private Clause createFilterClause(Operation operation, String field, Expression... expressions) { FilterClause filterClause = new ObjectFilterClause(); filterClause.setOperation(operation); filterClause.setField(field); filterClause.setValues(Stream.of(expressions).map(e -> new Value(e instanceof Identifier ? Value.Kind.FIELD : Value.Kind.VALUE, e.toFormatlessString())).collect(Collectors.toList())); return filterClause; }
@Override protected com.yahoo.bullet.parsing.Expression visitLongLiteral(LongLiteral node, Void context) { LeafExpression leafExpression = new LeafExpression(); leafExpression.setValue(new Value(Value.Kind.VALUE, node.toFormatlessString(), Type.LONG)); return leafExpression; }
@Override protected com.yahoo.bullet.parsing.Expression visitDoubleLiteral(DoubleLiteral node, Void context) { LeafExpression leafExpression = new LeafExpression(); leafExpression.setValue(new Value(Value.Kind.VALUE, node.toFormatlessString(), Type.DOUBLE)); return leafExpression; }
@Override protected com.yahoo.bullet.parsing.Expression visitStringLiteral(StringLiteral node, Void context) { LeafExpression leafExpression = new LeafExpression(); leafExpression.setValue(new Value(Value.Kind.VALUE, node.toFormatlessString(), Type.STRING)); return leafExpression; }
@Override protected com.yahoo.bullet.parsing.Expression visitIdentifier(Identifier node, Void context) { LeafExpression leafExpression = new LeafExpression(); leafExpression.setValue(new Value(Value.Kind.FIELD, node.toFormatlessString())); return leafExpression; } }
@Override protected com.yahoo.bullet.parsing.Expression visitDecimalLiteral(DecimalLiteral node, Void context) { LeafExpression leafExpression = new LeafExpression(); leafExpression.setValue(new Value(Value.Kind.VALUE, node.toFormatlessString(), Type.DOUBLE)); return leafExpression; }
@Override protected com.yahoo.bullet.parsing.Expression visitBooleanLiteral(BooleanLiteral node, Void context) { LeafExpression leafExpression = new LeafExpression(); leafExpression.setValue(new Value(Value.Kind.VALUE, node.toFormatlessString(), Type.BOOLEAN)); return leafExpression; }
@Override protected com.yahoo.bullet.parsing.Expression visitArithmeticUnary(ArithmeticUnaryExpression node, Void context) { LeafExpression leafExpression = new LeafExpression(); Type type; if (node.getValue() instanceof LongLiteral) { type = Type.LONG; } else { type = Type.DOUBLE; } leafExpression.setValue(new Value(Value.Kind.VALUE, node.toFormatlessString(), type)); return leafExpression; }