Search in sources :

Example 26 with ValueExpression

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

the class QuerierTest method testLogicFilterOr.

@Test
public void testLogicFilterOr() {
    // legacy test
    Expression filter = new BinaryExpression(new BinaryExpression(new FieldExpression("field"), new ValueExpression("abc"), Operation.EQUALS), new BinaryExpression(new FieldExpression("id"), new ValueExpression("1"), Operation.EQUALS), Operation.OR);
    Query query = new Query(new Projection(), filter, new Raw(null), null, new Window(), null);
    Querier querier = make(Querier.Mode.PARTITION, query);
    querier.consume(RecordBox.get().add("field", "abc").add("id", "2").getRecord());
    Assert.assertTrue(querier.hasNewData());
    querier.consume(RecordBox.get().add("field", "abc").add("id", "1").getRecord());
    Assert.assertTrue(querier.hasNewData());
}
Also used : Window(com.yahoo.bullet.query.Window) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) Query(com.yahoo.bullet.query.Query) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Expression(com.yahoo.bullet.query.expressions.Expression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 27 with ValueExpression

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

the class QuerierTest method testFiltering.

@Test
public void testFiltering() {
    Expression filter = new BinaryExpression(new FieldExpression("field"), new ListExpression(Arrays.asList(new ValueExpression("foo"), new ValueExpression("bar"))), Operation.EQUALS_ANY);
    Window window = WindowUtils.makeSlidingWindow(1);
    Query query = new Query(new Projection(), filter, new Raw(null), null, window, null);
    Querier querier = make(Querier.Mode.PARTITION, query);
    querier.consume(RecordBox.get().add("field", "foo").getRecord());
    Assert.assertTrue(querier.isClosed());
    querier.reset();
    querier.consume(RecordBox.get().add("field", "bar").getRecord());
    Assert.assertTrue(querier.isClosed());
    querier.reset();
    querier.consume(RecordBox.get().add("field", "baz").getRecord());
    Assert.assertFalse(querier.isClosed());
}
Also used : Window(com.yahoo.bullet.query.Window) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) Query(com.yahoo.bullet.query.Query) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Expression(com.yahoo.bullet.query.expressions.Expression) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 28 with ValueExpression

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

the class ListEvaluatorTest method testConstructor.

@Test
public void testConstructor() {
    ListExpression expression = new ListExpression(Arrays.asList(new ValueExpression(1), new ValueExpression(2)));
    expression.setType(Type.INTEGER_LIST);
    ListEvaluator evaluator = new ListEvaluator(expression);
    Assert.assertTrue(evaluator.evaluators.get(0) instanceof ValueEvaluator);
    Assert.assertTrue(evaluator.evaluators.get(1) instanceof ValueEvaluator);
    Assert.assertEquals(evaluator.evaluate(RecordBox.get().getRecord()), new TypedObject(Type.INTEGER_LIST, new ArrayList<>(Arrays.asList(1, 2))));
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 29 with ValueExpression

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

the class ComputationTest method testComputation.

@Test
public void testComputation() {
    Computation computation = new Computation(Collections.singletonList(new Field("abc", new ValueExpression(1))));
    Assert.assertEquals(computation.getFields(), Collections.singletonList(new Field("abc", new ValueExpression(1))));
    Assert.assertEquals(computation.getType(), PostAggregationType.COMPUTATION);
    Assert.assertEquals(computation.toString(), "{type: COMPUTATION, fields: [{name: abc, value: {value: 1, type: INTEGER}}]}");
    Assert.assertTrue(computation.getPostStrategy() instanceof ComputationStrategy);
}
Also used : Field(com.yahoo.bullet.query.Field) ComputationStrategy(com.yahoo.bullet.querying.postaggregations.ComputationStrategy) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Test(org.testng.annotations.Test)

Example 30 with ValueExpression

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

the class FieldTest method testEquals.

@Test
public void testEquals() {
    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.assertEquals(fieldA, fieldA);
    Assert.assertNotEquals(fieldA, fieldB);
    Assert.assertNotEquals(fieldA, fieldC);
    Assert.assertEquals(fieldA, fieldD);
    // coverage
    Assert.assertFalse(fieldA.equals(0));
}
Also used : 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