Search in sources :

Example 26 with FieldExpression

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

the class ExplodeTest method testToString.

@Test
public void testToString() {
    Explode tableFunction = new Explode(new FieldExpression("abc"), "foo", null, true);
    Assert.assertEquals(tableFunction.toString(), "{outer: true, type: EXPLODE, field: {field: abc, type: null}, keyAlias: foo, valueAlias: null}");
}
Also used : FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 27 with FieldExpression

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

the class ExplodeTest method testExplodeTableFunction.

@Test
public void testExplodeTableFunction() {
    Explode tableFunction = new Explode(new FieldExpression("abc"), "foo", "bar", true);
    Assert.assertEquals(tableFunction.getType(), TableFunctionType.EXPLODE);
    Assert.assertEquals(tableFunction.getField(), new FieldExpression("abc"));
    Assert.assertEquals(tableFunction.getKeyAlias(), "foo");
    Assert.assertEquals(tableFunction.getValueAlias(), "bar");
    Assert.assertTrue(tableFunction.isOuter());
    Assert.assertTrue(tableFunction.getTableFunctor() instanceof ExplodeFunctor);
}
Also used : ExplodeFunctor(com.yahoo.bullet.querying.tablefunctors.ExplodeFunctor) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 28 with FieldExpression

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

the class FilterTest method testFilterMatch.

@Test
public void testFilterMatch() {
    Filter filter = new Filter(new BinaryExpression(new FieldExpression("abc"), new ValueExpression(0), Operation.GREATER_THAN));
    BulletRecord recordA = RecordBox.get().add("abc", 1).getRecord();
    BulletRecord recordB = RecordBox.get().add("abc", 0).getRecord();
    BulletRecord recordC = RecordBox.get().getRecord();
    Assert.assertTrue(filter.match(recordA));
    Assert.assertFalse(filter.match(recordB));
    Assert.assertFalse(filter.match(recordC));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) 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 29 with FieldExpression

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

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

the class QuerierTest method testCopyProjection.

@Test
public void testCopyProjection() {
    Projection projection = new Projection(Collections.singletonList(new Field("mid", new FieldExpression("map_field", "id"))), true);
    Query query = new Query(projection, null, new Raw(null), null, new Window(), null);
    BulletConfig config = new BulletConfig();
    query.configure(config);
    Querier querier = new Querier(makeRunningQuery("", query), config);
    RecordBox boxA = RecordBox.get().addMap("map_field", Pair.of("id", "23"));
    BulletRecord expected = boxA.getRecord().copy();
    expected.setString("mid", "23");
    querier.consume(boxA.getRecord());
    Assert.assertFalse(querier.isClosed());
    Assert.assertEquals(querier.getData(), getListBytes(expected));
}
Also used : Window(com.yahoo.bullet.query.Window) RecordBox(com.yahoo.bullet.result.RecordBox) Field(com.yahoo.bullet.query.Field) BulletRecord(com.yahoo.bullet.record.BulletRecord) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) BulletConfig(com.yahoo.bullet.common.BulletConfig) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

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