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("*-*"));
}
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);
}
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);
}
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);
}
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);
}
Aggregations