Search in sources :

Example 1 with UnaryExpression

use of com.yahoo.bullet.query.expressions.UnaryExpression 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)

Example 2 with UnaryExpression

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

the class QuerierTest method testTableFunction.

@Test
public void testTableFunction() {
    TableFunction tableFunction = new LateralView(new Explode(new FieldExpression("map"), "key", "value", true));
    Projection projection = new Projection(Arrays.asList(new Field("key", new FieldExpression("key")), new Field("value", new FieldExpression("value")), new Field("abc", new FieldExpression("abc"))), false);
    Expression filter = new UnaryExpression(new FieldExpression("map"), Operation.IS_NOT_NULL);
    Query query = new Query(tableFunction, projection, filter, new Raw(500), null, new Window(), null);
    Querier querier = make(Querier.Mode.ALL, query);
    querier.consume(RecordBox.get().addMap("map", Pair.of("a", 0), Pair.of("b", 1), Pair.of("c", 2)).add("abc", 1).getRecord());
    querier.consume(RecordBox.get().add("abc", 2).getRecord());
    querier.consume(RecordBox.get().add("abc", 3).add("map", new HashMap<>()).getRecord());
    List<BulletRecord> result = querier.getResult().getRecords();
    Assert.assertEquals(result.size(), 4);
    Assert.assertEquals(result.get(0).fieldCount(), 3);
    Assert.assertEquals(result.get(0).typedGet("key").getValue(), "a");
    Assert.assertEquals(result.get(0).typedGet("value").getValue(), 0);
    Assert.assertEquals(result.get(0).typedGet("abc").getValue(), 1);
    Assert.assertEquals(result.get(1).fieldCount(), 3);
    Assert.assertEquals(result.get(1).typedGet("key").getValue(), "b");
    Assert.assertEquals(result.get(1).typedGet("value").getValue(), 1);
    Assert.assertEquals(result.get(1).typedGet("abc").getValue(), 1);
    Assert.assertEquals(result.get(2).fieldCount(), 3);
    Assert.assertEquals(result.get(2).typedGet("key").getValue(), "c");
    Assert.assertEquals(result.get(2).typedGet("value").getValue(), 2);
    Assert.assertEquals(result.get(2).typedGet("abc").getValue(), 1);
    Assert.assertEquals(result.get(3).fieldCount(), 1);
    Assert.assertEquals(result.get(3).typedGet("abc").getValue(), 3);
}
Also used : Window(com.yahoo.bullet.query.Window) LateralView(com.yahoo.bullet.query.tablefunctions.LateralView) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Explode(com.yahoo.bullet.query.tablefunctions.Explode) Field(com.yahoo.bullet.query.Field) BulletRecord(com.yahoo.bullet.record.BulletRecord) 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) TableFunction(com.yahoo.bullet.query.tablefunctions.TableFunction) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 3 with UnaryExpression

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

the class ProjectionTest method testProjectOldRecord.

@Test
public void testProjectOldRecord() {
    BulletRecord record = RecordBox.get().add("a", 2).add("b", 4).add("c", 6).getRecord();
    List<Field> fields = Arrays.asList(new Field("a", new BinaryExpression(new FieldExpression("a"), new FieldExpression("b"), Operation.MUL)), new Field("b", new BinaryExpression(new FieldExpression("b"), new FieldExpression("c"), Operation.MUL)), new Field("d", new BinaryExpression(new FieldExpression("b"), new FieldExpression("c"), Operation.ADD)), new Field("e", new BinaryExpression(new FieldExpression("e"), new FieldExpression("f"), Operation.SUB)), new Field("f", new FieldExpression("f")), new Field("h", new UnaryExpression(new FieldExpression("a"), Operation.SIZE_OF)));
    Projection projection = new Projection(fields);
    BulletRecord oldRecord = projection.project(record);
    Assert.assertEquals(oldRecord.fieldCount(), 4);
    Assert.assertEquals(oldRecord.typedGet("a").getValue(), 8);
    Assert.assertEquals(oldRecord.typedGet("b").getValue(), 24);
    Assert.assertEquals(oldRecord.typedGet("c").getValue(), 6);
    Assert.assertEquals(oldRecord.typedGet("d").getValue(), 10);
    Assert.assertEquals(oldRecord, record);
}
Also used : Field(com.yahoo.bullet.query.Field) BulletRecord(com.yahoo.bullet.record.BulletRecord) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 4 with UnaryExpression

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

the class QuerierTest method testComputationAndCulling.

@Test
public void testComputationAndCulling() {
    Projection projection = new Projection(Arrays.asList(new Field("a", new FieldExpression("a")), new Field("b", new FieldExpression("b"))), false);
    Expression filter = new UnaryExpression(new FieldExpression("a"), Operation.IS_NOT_NULL);
    Expression expression = new BinaryExpression(new FieldExpression("a"), new ValueExpression(2L), Operation.ADD);
    Computation computation = new Computation(Collections.singletonList(new Field("newName", expression)));
    Culling culling = new Culling(singleton("a"));
    Query query = new Query(projection, filter, new Raw(500), Arrays.asList(computation, culling), new Window(), null);
    Querier querier = make(Querier.Mode.ALL, query);
    IntStream.range(0, 4).forEach(i -> querier.consume(RecordBox.get().add("a", i).add("b", i).getRecord()));
    List<BulletRecord> result = querier.getResult().getRecords();
    Assert.assertEquals(result.size(), 4);
    Assert.assertEquals(result.get(0).typedGet("newName").getValue(), 2L);
    Assert.assertFalse(result.get(0).hasField("a"));
    Assert.assertEquals(result.get(0).typedGet("b").getValue(), 0);
    Assert.assertEquals(result.get(1).typedGet("newName").getValue(), 3L);
    Assert.assertFalse(result.get(1).hasField("a"));
    Assert.assertEquals(result.get(1).typedGet("b").getValue(), 1);
    Assert.assertEquals(result.get(2).typedGet("newName").getValue(), 4L);
    Assert.assertFalse(result.get(2).hasField("a"));
    Assert.assertEquals(result.get(2).typedGet("b").getValue(), 2);
    Assert.assertEquals(result.get(3).typedGet("newName").getValue(), 5L);
    Assert.assertFalse(result.get(3).hasField("a"));
    Assert.assertEquals(result.get(3).typedGet("b").getValue(), 3);
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Field(com.yahoo.bullet.query.Field) BulletRecord(com.yahoo.bullet.record.BulletRecord) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) 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) Computation(com.yahoo.bullet.query.postaggregations.Computation) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Culling(com.yahoo.bullet.query.postaggregations.Culling) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 5 with UnaryExpression

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

the class QuerierTest method testOrderBy.

@Test
public void testOrderBy() {
    Expression filter = new UnaryExpression(new FieldExpression("a"), Operation.IS_NOT_NULL);
    OrderBy orderBy = new OrderBy(Collections.singletonList(new OrderBy.SortItem(new FieldExpression("a"), OrderBy.Direction.DESC)));
    Query query = new Query(new Projection(), filter, new Raw(500), Collections.singletonList(orderBy), new Window(), null);
    Querier querier = make(Querier.Mode.ALL, query);
    IntStream.range(0, 4).forEach(i -> querier.consume(RecordBox.get().add("a", 10 - i).add("b", i + 10).getRecord()));
    List<BulletRecord> result = querier.getResult().getRecords();
    Assert.assertEquals(result.size(), 4);
    Assert.assertEquals(result.get(0).typedGet("a").getValue(), 10);
    Assert.assertEquals(result.get(0).typedGet("b").getValue(), 10);
    Assert.assertEquals(result.get(1).typedGet("a").getValue(), 9);
    Assert.assertEquals(result.get(1).typedGet("b").getValue(), 11);
    Assert.assertEquals(result.get(2).typedGet("a").getValue(), 8);
    Assert.assertEquals(result.get(2).typedGet("b").getValue(), 12);
    Assert.assertEquals(result.get(3).typedGet("a").getValue(), 7);
    Assert.assertEquals(result.get(3).typedGet("b").getValue(), 13);
}
Also used : OrderBy(com.yahoo.bullet.query.postaggregations.OrderBy) Window(com.yahoo.bullet.query.Window) BulletRecord(com.yahoo.bullet.record.BulletRecord) 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) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Aggregations

UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)10 Test (org.testng.annotations.Test)10 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)8 BulletRecord (com.yahoo.bullet.record.BulletRecord)8 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)6 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)6 Field (com.yahoo.bullet.query.Field)4 Query (com.yahoo.bullet.query.Query)4 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)3 Projection (com.yahoo.bullet.query.Projection)3 Window (com.yahoo.bullet.query.Window)3 Raw (com.yahoo.bullet.query.aggregations.Raw)3 Expression (com.yahoo.bullet.query.expressions.Expression)3 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)3 Explode (com.yahoo.bullet.query.tablefunctions.Explode)2 Clip (com.yahoo.bullet.result.Clip)2 ArrayList (java.util.ArrayList)2 Computation (com.yahoo.bullet.query.postaggregations.Computation)1 Culling (com.yahoo.bullet.query.postaggregations.Culling)1 OrderBy (com.yahoo.bullet.query.postaggregations.OrderBy)1