use of com.yahoo.bullet.query.expressions.FieldExpression in project bullet-core by yahoo.
the class SimpleEqualityPartitioner method addFieldToMapping.
private void addFieldToMapping(FieldExpression fieldExpression, ValueExpression valueExpression, Map<String, Set<Serializable>> mapping) {
if (fieldExpression.getKey() instanceof Expression || fieldExpression.getSubKey() instanceof Expression) {
return;
}
String field = fieldExpression.getName();
if (fieldSet.contains(field)) {
Serializable value = valueExpression.getValue();
mapping.computeIfAbsent(field, s -> new HashSet<>()).add(value);
}
}
use of com.yahoo.bullet.query.expressions.FieldExpression 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.query.expressions.FieldExpression in project bullet-core by yahoo.
the class FieldEvaluatorTest method testEvaluate.
@Test
public void testEvaluate() {
FieldEvaluator evaluator = new FieldEvaluator(new FieldExpression("abc"));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER_MAP_LIST, new ArrayList<>(Collections.singletonList(map))));
evaluator = new FieldEvaluator(new FieldExpression("abc", 0));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER_MAP, map));
evaluator = new FieldEvaluator(new FieldExpression("abc", 0, "def"));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER, 5));
HashMap<String, Serializable> hashMap = new HashMap<>();
hashMap.put("abc", map);
evaluator = new FieldEvaluator(new FieldExpression("aaa"));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER_MAP_MAP, hashMap));
evaluator = new FieldEvaluator(new FieldExpression("aaa", "abc"));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER_MAP, map));
evaluator = new FieldEvaluator(new FieldExpression("aaa", "abc", "def"));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER, 5));
}
use of com.yahoo.bullet.query.expressions.FieldExpression in project bullet-core by yahoo.
the class SimpleEqualityPartitionerTest method testDefaultPartitioningQueryWithOR.
@Test
public void testDefaultPartitioningQueryWithOR() {
SimpleEqualityPartitioner partitioner = createPartitioner("A", "B");
Query query = createQuery(new BinaryExpression(new BinaryExpression(new FieldExpression("A"), new ValueExpression("bar"), Operation.EQUALS), new BinaryExpression(new FieldExpression("B"), new ValueExpression("baz"), Operation.EQUALS), Operation.OR));
Assert.assertEquals(partitioner.getKeys(query), singleton("*-*"));
}
use of com.yahoo.bullet.query.expressions.FieldExpression in project bullet-core by yahoo.
the class SimpleEqualityPartitionerTest method testDefaultPartitioningQueryWithNOT.
@Test
public void testDefaultPartitioningQueryWithNOT() {
SimpleEqualityPartitioner partitioner = createPartitioner("A", "B");
Query query = createQuery(new UnaryExpression(new BinaryExpression(new FieldExpression("A"), new ValueExpression("bar"), Operation.EQUALS), Operation.NOT));
Assert.assertEquals(partitioner.getKeys(query), singleton("*-*"));
}
Aggregations