Search in sources :

Example 11 with Window

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

the class QueryManagerTest method getQuery.

@SafeVarargs
private static Query getQuery(Pair<String, Serializable>... equalities) {
    BinaryExpression expression = null;
    if (equalities != null && equalities.length > 0) {
        if (equalities.length == 1) {
            expression = new BinaryExpression(new FieldExpression(equalities[0].getLeft()), new ValueExpression(equalities[0].getRight()), Operation.EQUALS);
            expression.setType(Type.BOOLEAN);
            expression.getLeft().setType(expression.getRight().getType());
        } else {
            expression = Arrays.stream(equalities).reduce(null, (a, b) -> {
                BinaryExpression equals = new BinaryExpression(new FieldExpression(b.getLeft()), new ValueExpression(b.getRight()), Operation.EQUALS);
                equals.setType(Type.BOOLEAN);
                equals.getLeft().setType(equals.getRight().getType());
                if (a == null) {
                    return equals;
                }
                BinaryExpression and = new BinaryExpression(a, equals, Operation.AND);
                and.setType(Type.BOOLEAN);
                return and;
            }, (left, right) -> {
                BinaryExpression and = new BinaryExpression(left, right, Operation.AND);
                and.setType(Type.BOOLEAN);
                return and;
            });
        }
    }
    Query query = new Query(new Projection(), expression, new Raw(null), null, new Window(), null);
    query.configure(new BulletConfig());
    return query;
}
Also used : Query(com.yahoo.bullet.query.Query) Arrays(java.util.Arrays) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) RecordBox(com.yahoo.bullet.result.RecordBox) Operation(com.yahoo.bullet.query.expressions.Operation) HashSet(java.util.HashSet) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) Raw(com.yahoo.bullet.query.aggregations.Raw) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) LinkedHashSet(java.util.LinkedHashSet) Window(com.yahoo.bullet.query.Window) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) BulletRecord(com.yahoo.bullet.record.BulletRecord) SimpleEqualityPartitioner(com.yahoo.bullet.querying.partitioning.SimpleEqualityPartitioner) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Serializable(java.io.Serializable) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Mockito.never(org.mockito.Mockito.never) Projection(com.yahoo.bullet.query.Projection) BulletConfig(com.yahoo.bullet.common.BulletConfig) Type(com.yahoo.bullet.typesystem.Type) Window(com.yahoo.bullet.query.Window) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) Query(com.yahoo.bullet.query.Query) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) 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)

Example 12 with Window

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

the class QuerierTest method testLogicFilterAnd.

@Test
public void testLogicFilterAnd() {
    // 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.AND);
    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.assertFalse(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 13 with Window

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

the class QuerierTest method testFilteringProjection.

@Test
public void testFilteringProjection() {
    Projection projection = new Projection(Collections.singletonList(new Field("mid", new FieldExpression("map_field", "id"))), false);
    Expression filter = new BinaryExpression(new FieldExpression("map_field", "id"), new ListExpression(Arrays.asList(new ValueExpression("1"), new ValueExpression("23"))), Operation.EQUALS_ANY);
    Query query = new Query(projection, filter, 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", "3"));
    querier.consume(boxA.getRecord());
    Assert.assertFalse(querier.isClosed());
    Assert.assertNull(querier.getData());
    RecordBox boxB = RecordBox.get().addMap("map_field", Pair.of("id", "23"));
    RecordBox expected = RecordBox.get().add("mid", "23");
    querier.consume(boxB.getRecord());
    Assert.assertFalse(querier.isClosed());
    Assert.assertEquals(querier.getData(), getListBytes(expected.getRecord()));
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) RecordBox(com.yahoo.bullet.result.RecordBox) Field(com.yahoo.bullet.query.Field) 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) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 14 with Window

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

the class QuerierTest method testLogicFilterNot.

@Test
public void testLogicFilterNot() {
    // legacy test
    Expression filter = new BinaryExpression(new FieldExpression("field"), new ValueExpression("abc"), Operation.NOT_EQUALS);
    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").getRecord());
    Assert.assertFalse(querier.hasNewData());
    querier.consume(RecordBox.get().add("field", "ddd").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 15 with Window

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

the class QuerierTest method testBasicWindowMaximumEmittedWithNonMatchingRecords.

@Test
public void testBasicWindowMaximumEmittedWithNonMatchingRecords() {
    Expression filter = new BinaryExpression(new FieldExpression("mid"), new ListExpression(Arrays.asList(new ValueExpression("1"), new ValueExpression("23"))), Operation.EQUALS_ANY);
    Query query = new Query(new Projection(), filter, new Raw(2), null, new Window(), null);
    Querier querier = make(Querier.Mode.PARTITION, query);
    byte[] expected = getListBytes(RecordBox.get().add("mid", "23").getRecord());
    byte[] expectedTwice = getListBytes(RecordBox.get().add("mid", "23").getRecord(), RecordBox.get().add("mid", "23").getRecord());
    querier.consume(RecordBox.get().add("mid", "23").getRecord());
    Assert.assertFalse(querier.isClosed());
    Assert.assertFalse(querier.isDone());
    Assert.assertTrue(querier.hasNewData());
    Assert.assertEquals(querier.getData(), expected);
    // Doesn't match
    querier.consume(RecordBox.get().add("mid", "42").getRecord());
    Assert.assertFalse(querier.isClosed());
    Assert.assertFalse(querier.isDone());
    Assert.assertTrue(querier.hasNewData());
    Assert.assertEquals(querier.getData(), expected);
    querier.consume(RecordBox.get().add("mid", "23").getRecord());
    Assert.assertTrue(querier.isClosed());
    Assert.assertTrue(querier.isDone());
    Assert.assertTrue(querier.hasNewData());
    Assert.assertEquals(querier.getData(), expectedTwice);
    // Nothing else is consumed because RAW is closed
    IntStream.range(0, 10).mapToObj(i -> RecordBox.get().add("mid", "23").getRecord()).forEach(querier::consume);
    Assert.assertTrue(querier.isClosed());
    Assert.assertTrue(querier.isDone());
    Assert.assertTrue(querier.hasNewData());
    Assert.assertEquals(querier.getData(), expectedTwice);
    querier.reset();
    Assert.assertFalse(querier.isClosed());
    Assert.assertFalse(querier.isDone());
    Assert.assertFalse(querier.hasNewData());
    Assert.assertNull(querier.getData());
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Arrays(java.util.Arrays) TableFunction(com.yahoo.bullet.query.tablefunctions.TableFunction) BulletError(com.yahoo.bullet.common.BulletError) Strategy(com.yahoo.bullet.querying.aggregations.Strategy) Test(org.testng.annotations.Test) RecordBox(com.yahoo.bullet.result.RecordBox) TestHelpers.getListBytes(com.yahoo.bullet.TestHelpers.getListBytes) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) GroupBy(com.yahoo.bullet.query.aggregations.GroupBy) Pair(org.apache.commons.lang3.tuple.Pair) Collections.singleton(java.util.Collections.singleton) Computation(com.yahoo.bullet.query.postaggregations.Computation) Raw(com.yahoo.bullet.query.aggregations.Raw) Map(java.util.Map) Explode(com.yahoo.bullet.query.tablefunctions.Explode) Metadata(com.yahoo.bullet.pubsub.Metadata) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest) Culling(com.yahoo.bullet.query.postaggregations.Culling) BulletRecord(com.yahoo.bullet.record.BulletRecord) Scheme(com.yahoo.bullet.windowing.Scheme) AdditiveTumbling(com.yahoo.bullet.windowing.AdditiveTumbling) AdditionalAnswers(org.mockito.AdditionalAnswers) WindowUtils(com.yahoo.bullet.query.WindowUtils) List(java.util.List) Field(com.yahoo.bullet.query.Field) Stream(java.util.stream.Stream) LateralView(com.yahoo.bullet.query.tablefunctions.LateralView) BulletConfig(com.yahoo.bullet.common.BulletConfig) IntStream(java.util.stream.IntStream) AggregationType(com.yahoo.bullet.query.aggregations.AggregationType) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Operation(com.yahoo.bullet.query.expressions.Operation) Clip(com.yahoo.bullet.result.Clip) Assert(org.testng.Assert) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) GroupAll(com.yahoo.bullet.query.aggregations.GroupAll) Collections.singletonMap(java.util.Collections.singletonMap) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) Basic(com.yahoo.bullet.windowing.Basic) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Window(com.yahoo.bullet.query.Window) Meta(com.yahoo.bullet.result.Meta) Tumbling(com.yahoo.bullet.windowing.Tumbling) Expression(com.yahoo.bullet.query.expressions.Expression) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Mockito(org.mockito.Mockito) Projection(com.yahoo.bullet.query.Projection) CountDistinct(com.yahoo.bullet.query.aggregations.CountDistinct) OrderBy(com.yahoo.bullet.query.postaggregations.OrderBy) Collections(java.util.Collections) Query(com.yahoo.bullet.query.Query) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) 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) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Aggregations

Window (com.yahoo.bullet.query.Window)42 Test (org.testng.annotations.Test)34 Projection (com.yahoo.bullet.query.Projection)28 Query (com.yahoo.bullet.query.Query)28 Raw (com.yahoo.bullet.query.aggregations.Raw)26 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)17 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)12 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)11 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)11 BulletConfig (com.yahoo.bullet.common.BulletConfig)10 Expression (com.yahoo.bullet.query.expressions.Expression)10 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)10 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)10 BulletRecord (com.yahoo.bullet.record.BulletRecord)7 Field (com.yahoo.bullet.query.Field)6 Metadata (com.yahoo.bullet.pubsub.Metadata)5 RecordBox (com.yahoo.bullet.result.RecordBox)5 Map (java.util.Map)4 CountDistinct (com.yahoo.bullet.query.aggregations.CountDistinct)3 GroupAll (com.yahoo.bullet.query.aggregations.GroupAll)3