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);
}
}
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;
}
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;
}
Aggregations