Search in sources :

Example 1 with FieldExpression

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);
    }
}
Also used : IntStream(java.util.stream.IntStream) Query(com.yahoo.bullet.query.Query) TypedObject(com.yahoo.bullet.typesystem.TypedObject) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) BulletRecord(com.yahoo.bullet.record.BulletRecord) Set(java.util.Set) HashMap(java.util.HashMap) Expression(com.yahoo.bullet.query.expressions.Expression) Collectors(java.util.stream.Collectors) Operation(com.yahoo.bullet.query.expressions.Operation) Serializable(java.io.Serializable) HashSet(java.util.HashSet) Objects(java.util.Objects) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) List(java.util.List) BulletConfig(com.yahoo.bullet.common.BulletConfig) Map(java.util.Map) Utilities.isNull(com.yahoo.bullet.common.Utilities.isNull) Collections(java.util.Collections) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) Serializable(java.io.Serializable) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Expression(com.yahoo.bullet.query.expressions.Expression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) HashSet(java.util.HashSet)

Example 2 with FieldExpression

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);
    }
}
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 3 with FieldExpression

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));
}
Also used : Serializable(java.io.Serializable) TypedObject(com.yahoo.bullet.typesystem.TypedObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 4 with FieldExpression

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("*-*"));
}
Also used : Query(com.yahoo.bullet.query.Query) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 5 with FieldExpression

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("*-*"));
}
Also used : Query(com.yahoo.bullet.query.Query) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Aggregations

FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)63 Test (org.testng.annotations.Test)60 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)33 BulletRecord (com.yahoo.bullet.record.BulletRecord)33 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)30 Query (com.yahoo.bullet.query.Query)27 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)15 Explode (com.yahoo.bullet.query.tablefunctions.Explode)15 Clip (com.yahoo.bullet.result.Clip)13 ArrayList (java.util.ArrayList)13 Projection (com.yahoo.bullet.query.Projection)12 Window (com.yahoo.bullet.query.Window)12 Raw (com.yahoo.bullet.query.aggregations.Raw)12 Expression (com.yahoo.bullet.query.expressions.Expression)12 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)11 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)11 Field (com.yahoo.bullet.query.Field)9 LateralView (com.yahoo.bullet.query.tablefunctions.LateralView)7 BulletConfig (com.yahoo.bullet.common.BulletConfig)6 RecordBox (com.yahoo.bullet.result.RecordBox)6