Search in sources :

Example 1 with Type

use of com.yahoo.bullet.typesystem.Type in project bullet-core by yahoo.

the class FieldEvaluator method getFieldExtractor.

private static FieldExtractor getFieldExtractor(FieldExpression fieldExpression) {
    final String field = fieldExpression.getField();
    final Serializable key = fieldExpression.getKey();
    final Serializable subKey = fieldExpression.getSubKey();
    final Type fieldType = fieldExpression.getType() != null ? fieldExpression.getType() : Type.UNKNOWN;
    if (key instanceof String) {
        if (subKey instanceof String) {
            return record -> record.typedGet(field, (String) key, (String) subKey, getSuperSuperType(Type.COMPLEX_MAPS, fieldType));
        } else if (subKey instanceof Expression) {
            final Evaluator subKeyEvaluator = ((Expression) subKey).getEvaluator();
            return record -> {
                TypedObject subKeyArg = subKeyEvaluator.evaluate(record);
                if (subKeyArg.isNull()) {
                    return TypedObject.NULL;
                }
                return record.typedGet(field, (String) key, (String) subKeyArg.getValue(), getSuperSuperType(Type.COMPLEX_MAPS, fieldType));
            };
        } else {
            return record -> record.typedGet(field, (String) key, getSuperType(Type.MAPS, fieldType));
        }
    } else if (key instanceof Integer) {
        if (subKey instanceof String) {
            return record -> record.typedGet(field, (Integer) key, (String) subKey, getSuperSuperType(Type.COMPLEX_LISTS, fieldType));
        } else if (subKey instanceof Expression) {
            final Evaluator subKeyEvaluator = ((Expression) subKey).getEvaluator();
            return record -> {
                TypedObject subKeyArg = subKeyEvaluator.evaluate(record);
                if (subKeyArg.isNull()) {
                    return TypedObject.NULL;
                }
                return record.typedGet(field, (Integer) key, (String) subKeyArg.getValue(), getSuperSuperType(Type.COMPLEX_LISTS, fieldType));
            };
        } else {
            return record -> record.typedGet(field, (Integer) key, getSuperType(Type.LISTS, fieldType));
        }
    } else if (key instanceof Expression) {
        final Evaluator keyEvaluator = ((Expression) key).getEvaluator();
        if (subKey instanceof String) {
            return record -> {
                TypedObject keyArg = keyEvaluator.evaluate(record);
                if (keyArg.isNull()) {
                    return TypedObject.NULL;
                }
                Type type = keyArg.getType();
                if (Type.isNumeric(type)) {
                    return record.typedGet(field, ((Number) keyArg.getValue()).intValue(), (String) subKey, getSuperSuperType(Type.COMPLEX_LISTS, fieldType));
                } else {
                    return record.typedGet(field, (String) keyArg.getValue(), (String) subKey, getSuperSuperType(Type.COMPLEX_MAPS, fieldType));
                }
            };
        } else if (subKey instanceof Expression) {
            final Evaluator subKeyEvaluator = ((Expression) subKey).getEvaluator();
            return record -> {
                TypedObject keyArg = keyEvaluator.evaluate(record);
                if (keyArg.isNull()) {
                    return TypedObject.NULL;
                }
                TypedObject subKeyArg = subKeyEvaluator.evaluate(record);
                if (subKeyArg.isNull()) {
                    return TypedObject.NULL;
                }
                Type type = keyArg.getType();
                if (Type.isNumeric(type)) {
                    return record.typedGet(field, ((Number) keyArg.getValue()).intValue(), (String) subKeyArg.getValue(), getSuperSuperType(Type.COMPLEX_LISTS, fieldType));
                } else {
                    return record.typedGet(field, (String) keyArg.getValue(), (String) subKeyArg.getValue(), getSuperSuperType(Type.COMPLEX_MAPS, fieldType));
                }
            };
        } else {
            return record -> {
                TypedObject keyArg = keyEvaluator.evaluate(record);
                if (keyArg.isNull()) {
                    return TypedObject.NULL;
                }
                Type type = keyArg.getType();
                if (Type.isNumeric(type)) {
                    return record.typedGet(field, ((Number) keyArg.getValue()).intValue(), getSuperType(Type.LISTS, fieldType));
                } else {
                    return record.typedGet(field, (String) keyArg.getValue(), getSuperType(Type.MAPS, fieldType));
                }
            };
        }
    } else {
        return record -> record.typedGet(field, fieldType);
    }
}
Also used : FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) TypedObject(com.yahoo.bullet.typesystem.TypedObject) BulletRecord(com.yahoo.bullet.record.BulletRecord) Set(java.util.Set) Expression(com.yahoo.bullet.query.expressions.Expression) Type(com.yahoo.bullet.typesystem.Type) Serializable(java.io.Serializable) Serializable(java.io.Serializable) Type(com.yahoo.bullet.typesystem.Type) TypedObject(com.yahoo.bullet.typesystem.TypedObject) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Expression(com.yahoo.bullet.query.expressions.Expression)

Example 2 with Type

use of com.yahoo.bullet.typesystem.Type in project bullet-core by yahoo.

the class BinaryOperations method ternaryAllMatch.

@SuppressWarnings("unchecked")
private static TypedObject ternaryAllMatch(TypedObject leftValue, TypedObject rightValue, Predicate<Integer> predicate) {
    Type subType = rightValue.getType().getSubType();
    boolean hasNull = false;
    for (Serializable object : (List<? extends Serializable>) rightValue.getValue()) {
        if (object == null) {
            hasNull = true;
        } else if (!predicate.test(leftValue.compareTo(new TypedObject(subType, object)))) {
            return TypedObject.FALSE;
        }
    }
    return !hasNull ? TypedObject.TRUE : TypedObject.NULL;
}
Also used : Type(com.yahoo.bullet.typesystem.Type) Serializable(java.io.Serializable) TypedObject(com.yahoo.bullet.typesystem.TypedObject) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Type

use of com.yahoo.bullet.typesystem.Type in project bullet-core by yahoo.

the class BinaryOperations method ternaryAnyMatch.

@SuppressWarnings("unchecked")
private static TypedObject ternaryAnyMatch(TypedObject leftValue, TypedObject rightValue, Predicate<Integer> predicate) {
    Type subType = rightValue.getType().getSubType();
    boolean containsNull = false;
    for (Serializable object : (List<? extends Serializable>) rightValue.getValue()) {
        if (object == null) {
            containsNull = true;
        } else if (predicate.test(leftValue.compareTo(new TypedObject(subType, object)))) {
            return TypedObject.TRUE;
        }
    }
    return !containsNull ? TypedObject.FALSE : TypedObject.NULL;
}
Also used : Type(com.yahoo.bullet.typesystem.Type) Serializable(java.io.Serializable) TypedObject(com.yahoo.bullet.typesystem.TypedObject) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Type (com.yahoo.bullet.typesystem.Type)3 TypedObject (com.yahoo.bullet.typesystem.TypedObject)3 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Expression (com.yahoo.bullet.query.expressions.Expression)1 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)1 BulletRecord (com.yahoo.bullet.record.BulletRecord)1 Set (java.util.Set)1