Search in sources :

Example 1 with Query

use of com.yahoo.bullet.parsing.Query in project bullet-core by yahoo.

the class QuerierTest method testNonRawQueriesWithRecordWindowsAreErrors.

@Test
public void testNonRawQueriesWithRecordWindowsAreErrors() {
    BulletConfig config = new BulletConfig();
    Query query = new Query();
    Aggregation aggregation = new Aggregation();
    aggregation.setType(Aggregation.Type.COUNT_DISTINCT);
    query.setAggregation(aggregation);
    query.setWindow(WindowUtils.makeWindow(Window.Unit.RECORD, 1));
    query.configure(config);
    Querier querier = new Querier(new RunningQuery("", query), config);
    Optional<List<BulletError>> errors = querier.initialize();
    Assert.assertTrue(errors.isPresent());
    Assert.assertEquals(errors.get(), singletonList(Query.ONLY_RAW_RECORD));
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation) QueryUtils.makeAggregationQuery(com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery) QueryUtils.makeProjectionFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery) QueryUtils.makeRawFullQuery(com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery) Query(com.yahoo.bullet.parsing.Query) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Booleans.asList(com.google.common.primitives.Booleans.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 2 with Query

use of com.yahoo.bullet.parsing.Query in project bullet-core by yahoo.

the class QuerierTest method testRawQueriesWithTimeWindowsAreNotChanged.

@Test
public void testRawQueriesWithTimeWindowsAreNotChanged() {
    BulletConfig config = new BulletConfig();
    Query query = new Query();
    query.setWindow(WindowUtils.makeWindow(Window.Unit.TIME, Integer.MAX_VALUE));
    query.configure(config);
    Querier querier = make(Querier.Mode.PARTITION, query, config);
    Assert.assertFalse(querier.isClosed());
    Assert.assertTrue(querier.shouldBuffer());
    querier.consume(RecordBox.get().getRecord());
    Assert.assertFalse(querier.isClosed());
    Assert.assertEquals(querier.getWindow().getClass(), Tumbling.class);
}
Also used : QueryUtils.makeAggregationQuery(com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery) QueryUtils.makeProjectionFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery) QueryUtils.makeRawFullQuery(com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery) Query(com.yahoo.bullet.parsing.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 3 with Query

use of com.yahoo.bullet.parsing.Query in project bullet-core by yahoo.

the class QuerierTest method testReceiveTimestampNoProjection.

@Test
public void testReceiveTimestampNoProjection() {
    Long start = System.currentTimeMillis();
    Query query = new Query();
    query.setProjection(null);
    query.setWindow(WindowUtils.makeReactiveWindow());
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RECORD_INJECT_TIMESTAMP, true);
    config.validate();
    query.configure(config);
    Querier querier = make(Querier.Mode.ALL, query, config);
    BulletRecord input = RecordBox.get().add("field", "foo").add("mid", "123").getRecord();
    querier.consume(input);
    Assert.assertTrue(querier.isClosed());
    List<BulletRecord> records = querier.getRecords();
    Assert.assertEquals(records.size(), 1);
    BulletRecord actual = records.get(0);
    Long end = System.currentTimeMillis();
    Assert.assertEquals(size(actual), 3);
    Assert.assertEquals(actual.get("field"), "foo");
    Assert.assertEquals(actual.get("mid"), "123");
    Long recordedTimestamp = (Long) actual.get(BulletConfig.DEFAULT_RECORD_INJECT_TIMESTAMP_KEY);
    Assert.assertTrue(recordedTimestamp >= start);
    Assert.assertTrue(recordedTimestamp <= end);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) QueryUtils.makeAggregationQuery(com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery) QueryUtils.makeProjectionFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery) QueryUtils.makeRawFullQuery(com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery) Query(com.yahoo.bullet.parsing.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 4 with Query

use of com.yahoo.bullet.parsing.Query in project bullet-core by yahoo.

the class QuerierTest method testReceiveTimestamp.

@Test
public void testReceiveTimestamp() {
    Long start = System.currentTimeMillis();
    Query query = new Query();
    query.setProjection(ProjectionUtils.makeProjection("field", "bid"));
    query.setWindow(WindowUtils.makeReactiveWindow());
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RECORD_INJECT_TIMESTAMP, true);
    config.validate();
    query.configure(config);
    Querier querier = make(Querier.Mode.ALL, query, config);
    BulletRecord input = RecordBox.get().add("field", "foo").add("mid", "123").getRecord();
    querier.consume(input);
    Assert.assertTrue(querier.isClosed());
    List<BulletRecord> records = querier.getRecords();
    Assert.assertEquals(records.size(), 1);
    BulletRecord actual = records.get(0);
    Long end = System.currentTimeMillis();
    Assert.assertEquals(size(actual), 2);
    Assert.assertEquals(actual.get("bid"), "foo");
    Long recordedTimestamp = (Long) actual.get(BulletConfig.DEFAULT_RECORD_INJECT_TIMESTAMP_KEY);
    Assert.assertTrue(recordedTimestamp >= start);
    Assert.assertTrue(recordedTimestamp <= end);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) QueryUtils.makeAggregationQuery(com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery) QueryUtils.makeProjectionFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery) QueryUtils.makeRawFullQuery(com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery) Query(com.yahoo.bullet.parsing.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 5 with Query

use of com.yahoo.bullet.parsing.Query in project bullet-core by yahoo.

the class QuerierTest method testRawQueriesWithAllIncludeWindowsAreErrors.

@Test
public void testRawQueriesWithAllIncludeWindowsAreErrors() {
    BulletConfig config = new BulletConfig();
    Query query = new Query();
    query.setWindow(WindowUtils.makeWindow(Window.Unit.TIME, 1, Window.Unit.ALL, null));
    query.configure(config);
    Querier querier = new Querier(new RunningQuery("", query), config);
    Optional<List<BulletError>> errors = querier.initialize();
    Assert.assertTrue(errors.isPresent());
    Assert.assertEquals(errors.get(), singletonList(Query.NO_RAW_ALL));
}
Also used : QueryUtils.makeAggregationQuery(com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery) QueryUtils.makeProjectionFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery) QueryUtils.makeRawFullQuery(com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery) Query(com.yahoo.bullet.parsing.Query) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Booleans.asList(com.google.common.primitives.Booleans.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Aggregations

Query (com.yahoo.bullet.parsing.Query)24 Test (org.testng.annotations.Test)22 BulletConfig (com.yahoo.bullet.common.BulletConfig)20 QueryUtils.makeAggregationQuery (com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery)16 QueryUtils.makeProjectionFilterQuery (com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery)14 QueryUtils.makeRawFullQuery (com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery)14 Aggregation (com.yahoo.bullet.parsing.Aggregation)12 Window (com.yahoo.bullet.parsing.Window)6 List (java.util.List)4 Booleans.asList (com.google.common.primitives.Booleans.asList)3 ArrayList (java.util.ArrayList)3 Collections.emptyList (java.util.Collections.emptyList)3 Collections.singletonList (java.util.Collections.singletonList)3 BulletRecord (com.yahoo.bullet.record.BulletRecord)2 Strategy (com.yahoo.bullet.aggregations.Strategy)1 BulletError (com.yahoo.bullet.common.BulletError)1 Clip (com.yahoo.bullet.result.Clip)1 Meta (com.yahoo.bullet.result.Meta)1