Search in sources :

Example 6 with FieldExpression

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

the class SimpleEqualityPartitionerTest method testNoPartitioningForQueryWithExpressionFields.

@Test
public void testNoPartitioningForQueryWithExpressionFields() {
    FieldExpression fieldExpression = new FieldExpression("A", new ValueExpression("b"));
    SimpleEqualityPartitioner partitioner = createPartitioner(fieldExpression.getName());
    Query query = createQuery(new BinaryExpression(fieldExpression, new ValueExpression("bar"), Operation.EQUALS));
    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 7 with FieldExpression

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

the class SimpleEqualityPartitionerTest method testPartitioningForQueryWithMissingFields.

@Test
public void testPartitioningForQueryWithMissingFields() {
    SimpleEqualityPartitioner partitioner = createPartitioner("A", "B");
    Query query = createQuery(new BinaryExpression(new FieldExpression("A"), new ValueExpression("bar"), Operation.EQUALS));
    Assert.assertEquals(partitioner.getKeys(query), singleton("bar.-*"));
}
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 8 with FieldExpression

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

the class ComputationStrategyTest method testComputation.

@Test
public void testComputation() {
    // Computations are done using the fields in the original record and then the new fields are written at the end.
    // a = 2 * a + 5 * b
    // b = a * b
    List<Field> fields = new ArrayList<>();
    fields.add(new Field("a", new BinaryExpression(new BinaryExpression(new ValueExpression(2), new FieldExpression("a"), Operation.MUL), new BinaryExpression(new ValueExpression(5), new FieldExpression("b"), Operation.MUL), Operation.ADD)));
    fields.add(new Field("b", new BinaryExpression(new FieldExpression("a"), new FieldExpression("b"), Operation.MUL)));
    List<BulletRecord> records = new ArrayList<>();
    records.add(RecordBox.get().add("a", 5).add("b", 2).add("c", 0).getRecord());
    records.add(RecordBox.get().add("a", 2).add("b", 4).add("c", 1).getRecord());
    records.add(RecordBox.get().add("a", 1).add("b", 7).add("c", 2).getRecord());
    Clip clip = new Clip();
    clip.add(records);
    ComputationStrategy strategy = (ComputationStrategy) new Computation(fields).getPostStrategy();
    Clip result = strategy.execute(clip);
    Assert.assertEquals(result.getRecords().size(), 3);
    Assert.assertEquals(result.getRecords().get(0).typedGet("a").getValue(), 20);
    Assert.assertEquals(result.getRecords().get(0).typedGet("b").getValue(), 10);
    Assert.assertEquals(result.getRecords().get(0).typedGet("c").getValue(), 0);
    Assert.assertEquals(result.getRecords().get(1).typedGet("a").getValue(), 24);
    Assert.assertEquals(result.getRecords().get(1).typedGet("b").getValue(), 8);
    Assert.assertEquals(result.getRecords().get(1).typedGet("c").getValue(), 1);
    Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), 37);
    Assert.assertEquals(result.getRecords().get(2).typedGet("b").getValue(), 7);
    Assert.assertEquals(result.getRecords().get(2).typedGet("c").getValue(), 2);
}
Also used : Clip(com.yahoo.bullet.result.Clip) Field(com.yahoo.bullet.query.Field) BulletRecord(com.yahoo.bullet.record.BulletRecord) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) Computation(com.yahoo.bullet.query.postaggregations.Computation) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) ArrayList(java.util.ArrayList) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 9 with FieldExpression

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

the class OrderByStrategyTest method testOrderByAscending.

@Test
public void testOrderByAscending() {
    OrderByStrategy orderByStrategy = makeOrderBy(Arrays.asList(new OrderBy.SortItem(new FieldExpression("a"), OrderBy.Direction.ASC), new OrderBy.SortItem(new FieldExpression("b"), OrderBy.Direction.ASC)));
    List<BulletRecord> records = new ArrayList<>();
    records.add(RecordBox.get().add("a", 5).add("b", 2).getRecord());
    records.add(RecordBox.get().add("a", 2).add("b", 4).getRecord());
    records.add(RecordBox.get().add("a", 2).add("b", 2).getRecord());
    records.add(RecordBox.get().add("a", 1).add("b", 7).getRecord());
    Clip clip = new Clip();
    clip.add(records);
    Clip result = orderByStrategy.execute(clip);
    Assert.assertEquals(result.getRecords().get(0).typedGet("a").getValue(), 1);
    Assert.assertEquals(result.getRecords().get(0).typedGet("b").getValue(), 7);
    Assert.assertEquals(result.getRecords().get(1).typedGet("a").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(1).typedGet("b").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(2).typedGet("b").getValue(), 4);
    Assert.assertEquals(result.getRecords().get(3).typedGet("a").getValue(), 5);
    Assert.assertEquals(result.getRecords().get(3).typedGet("b").getValue(), 2);
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) ArrayList(java.util.ArrayList) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 10 with FieldExpression

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

the class OrderByStrategyTest method testOrderByComputationWithSingleField.

@Test
public void testOrderByComputationWithSingleField() {
    OrderByStrategy orderByStrategy = makeOrderBy(Arrays.asList(new OrderBy.SortItem(new BinaryExpression(new FieldExpression("a"), new ValueExpression(-1), Operation.MUL), OrderBy.Direction.ASC), new OrderBy.SortItem(new BinaryExpression(new FieldExpression("b"), new ValueExpression(-1), Operation.MUL), OrderBy.Direction.ASC)));
    List<BulletRecord> records = new ArrayList<>();
    records.add(RecordBox.get().add("a", 5).add("b", 2).getRecord());
    records.add(RecordBox.get().add("a", 2).add("b", 4).getRecord());
    records.add(RecordBox.get().add("a", 2).add("b", 2).getRecord());
    records.add(RecordBox.get().add("a", 1).add("b", 7).getRecord());
    Clip clip = new Clip();
    clip.add(records);
    Clip result = orderByStrategy.execute(clip);
    Assert.assertEquals(result.getRecords().get(0).typedGet("a").getValue(), 5);
    Assert.assertEquals(result.getRecords().get(0).typedGet("b").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(1).typedGet("a").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(1).typedGet("b").getValue(), 4);
    Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(2).typedGet("b").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(3).typedGet("a").getValue(), 1);
    Assert.assertEquals(result.getRecords().get(3).typedGet("b").getValue(), 7);
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) ArrayList(java.util.ArrayList) 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