Search in sources :

Example 1 with ValueExpression

use of com.yahoo.bullet.query.expressions.ValueExpression in project bullet-core by yahoo.

the class FieldTest method testHashCode.

@Test
public void testHashCode() {
    Field fieldA = new Field("abc", new ValueExpression(5));
    Field fieldB = new Field("def", new ValueExpression(5));
    Field fieldC = new Field("abc", new ValueExpression(1));
    Field fieldD = new Field("abc", new ValueExpression(5));
    Assert.assertNotEquals(fieldA.hashCode(), fieldB.hashCode());
    Assert.assertNotEquals(fieldA.hashCode(), fieldC.hashCode());
    Assert.assertEquals(fieldA.hashCode(), fieldD.hashCode());
}
Also used : ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Test(org.testng.annotations.Test)

Example 2 with ValueExpression

use of com.yahoo.bullet.query.expressions.ValueExpression 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 3 with ValueExpression

use of com.yahoo.bullet.query.expressions.ValueExpression in project bullet-core by yahoo.

the class CastEvaluatorTest method testConstructor.

@Test
public void testConstructor() {
    CastExpression expression = new CastExpression(new ValueExpression(5), Type.STRING);
    expression.setType(Type.STRING);
    CastEvaluator evaluator = new CastEvaluator(expression);
    Assert.assertTrue(evaluator.value instanceof ValueEvaluator);
    Assert.assertEquals(evaluator.castType, Type.STRING);
    Assert.assertEquals(evaluator.evaluate(RecordBox.get().getRecord()), new TypedObject(Type.STRING, "5"));
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) CastExpression(com.yahoo.bullet.query.expressions.CastExpression) Test(org.testng.annotations.Test)

Example 4 with ValueExpression

use of com.yahoo.bullet.query.expressions.ValueExpression in project bullet-core by yahoo.

the class NAryEvaluatorTest method testConstructor.

@Test
public void testConstructor() {
    NAryExpression expression = new NAryExpression(Arrays.asList(new ValueExpression(false), new ValueExpression(1), new ValueExpression(2)), Operation.IF);
    expression.setType(Type.INTEGER);
    NAryEvaluator evaluator = new NAryEvaluator(expression);
    Assert.assertTrue(evaluator.operands.get(0) instanceof ValueEvaluator);
    Assert.assertTrue(evaluator.operands.get(1) instanceof ValueEvaluator);
    Assert.assertTrue(evaluator.operands.get(2) instanceof ValueEvaluator);
    Assert.assertEquals(evaluator.op, N_ARY_OPERATORS.get(Operation.IF));
    Assert.assertEquals(evaluator.evaluate(RecordBox.get().getRecord()), new TypedObject(Type.INTEGER, 2));
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) NAryExpression(com.yahoo.bullet.query.expressions.NAryExpression) Test(org.testng.annotations.Test)

Example 5 with ValueExpression

use of com.yahoo.bullet.query.expressions.ValueExpression in project bullet-core by yahoo.

the class ValueEvaluatorTest method testConstructor.

@Test
public void testConstructor() {
    ValueEvaluator evaluator = new ValueEvaluator(new ValueExpression(5));
    Assert.assertEquals(evaluator.value, new TypedObject(Type.INTEGER, 5));
    Assert.assertEquals(evaluator.evaluate(RecordBox.get().getRecord()), evaluator.value);
    evaluator = new ValueEvaluator(new ValueExpression("5"));
    Assert.assertEquals(evaluator.value, new TypedObject(Type.STRING, "5"));
    Assert.assertEquals(evaluator.evaluate(RecordBox.get().getRecord()), evaluator.value);
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Test(org.testng.annotations.Test)

Aggregations

ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)42 Test (org.testng.annotations.Test)40 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)29 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)28 Query (com.yahoo.bullet.query.Query)23 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)11 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)10 BulletRecord (com.yahoo.bullet.record.BulletRecord)10 Projection (com.yahoo.bullet.query.Projection)9 Window (com.yahoo.bullet.query.Window)9 Raw (com.yahoo.bullet.query.aggregations.Raw)9 Expression (com.yahoo.bullet.query.expressions.Expression)9 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)8 TypedObject (com.yahoo.bullet.typesystem.TypedObject)7 Field (com.yahoo.bullet.query.Field)6 BulletConfig (com.yahoo.bullet.common.BulletConfig)5 Clip (com.yahoo.bullet.result.Clip)5 Operation (com.yahoo.bullet.query.expressions.Operation)4 Computation (com.yahoo.bullet.query.postaggregations.Computation)4 RecordBox (com.yahoo.bullet.result.RecordBox)4