Search in sources :

Example 1 with Window

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

the class Querier method shouldBuffer.

/**
 * Returns if this query should buffer before emitting results. You can use this to wait for the final results
 * for your window (or your final results if you have no window) in your Join or Combine stage after a query is
 * {@link #isDone()} or {@link #isClosed()}.
 *
 * @return A boolean that is true if the query results should be buffered.
 */
public boolean shouldBuffer() {
    Window window = runningQuery.getQuery().getWindow();
    boolean noWindow = window == null;
    // query is not yet done. So this tells the driver to buffer the query to wait for more potential results.
    if (noWindow && isRaw()) {
        return runningQuery.isTimedOut();
    }
    // No window (and not raw) is a duration based query => do buffer. Otherwise, buffer if the window is time based.
    return noWindow || window.isTimeBased();
}
Also used : Window(com.yahoo.bullet.parsing.Window)

Example 2 with Window

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

the class WindowingOperations method findScheme.

/**
 * Create a windowing {@link Scheme} for this particular {@link Query}.
 *
 * @param query The configured, initialized query to find a scheme for.
 * @param strategy The aggregation strategy to use for in the windowing scheme.
 * @param config The {@link BulletConfig} to use for configuration.
 * @return A windowing scheme to use for this query.
 */
public static Scheme findScheme(Query query, Strategy strategy, BulletConfig config) {
    /*
         * TODO: Support other windows
         * The windows we support at the moment:
         * 1. No window -> Basic
         * 2. Window is emit RECORD and include RECORD -> Reactive
         * 3. Window is emit TIME and include ALL -> Additive Tumbling
         * 4. All other windows -> Tumbling (RAW can be Tumbling too)
         */
    Window window = query.getWindow();
    if (window == null) {
        return new Basic(strategy, null, config);
    }
    Window.Classification classification = window.getType();
    if (classification == Window.Classification.RECORD_RECORD) {
        return new Reactive(strategy, window, config);
    }
    if (classification == Window.Classification.TIME_ALL) {
        return new AdditiveTumbling(strategy, window, config);
    }
    return new Tumbling(strategy, window, config);
}
Also used : Window(com.yahoo.bullet.parsing.Window) Basic(com.yahoo.bullet.windowing.Basic) AdditiveTumbling(com.yahoo.bullet.windowing.AdditiveTumbling) Reactive(com.yahoo.bullet.windowing.Reactive) Tumbling(com.yahoo.bullet.windowing.Tumbling) AdditiveTumbling(com.yahoo.bullet.windowing.AdditiveTumbling)

Example 3 with Window

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

the class WindowingOperationsTest method testNotForcingNonRawToTumbling.

@Test
public void testNotForcingNonRawToTumbling() {
    BulletConfig config = new BulletConfig();
    Query query = new Query();
    Window window = WindowUtils.makeReactiveWindow();
    window.configure(config);
    query.setWindow(window);
    Aggregation aggregation = new Aggregation();
    aggregation.setType(Aggregation.Type.GROUP);
    query.setAggregation(aggregation);
    Assert.assertEquals(WindowingOperations.findScheme(query, null, config).getClass(), Reactive.class);
}
Also used : Window(com.yahoo.bullet.parsing.Window) Aggregation(com.yahoo.bullet.parsing.Aggregation) Query(com.yahoo.bullet.parsing.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 4 with Window

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

the class WindowingOperationsTest method testAdditiveTumblingWindow.

@Test
public void testAdditiveTumblingWindow() {
    BulletConfig config = new BulletConfig();
    Query query = new Query();
    Window window = WindowUtils.makeWindow(Window.Unit.TIME, 1000, Window.Unit.ALL, null);
    window.configure(config);
    query.setWindow(window);
    Aggregation aggregation = new Aggregation();
    aggregation.setType(Aggregation.Type.GROUP);
    query.setAggregation(aggregation);
    Assert.assertEquals(WindowingOperations.findScheme(query, null, config).getClass(), AdditiveTumbling.class);
}
Also used : Window(com.yahoo.bullet.parsing.Window) Aggregation(com.yahoo.bullet.parsing.Aggregation) Query(com.yahoo.bullet.parsing.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 5 with Window

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

the class WindowingOperationsTest method testOtherWindowsForcedToTumbling.

@Test
public void testOtherWindowsForcedToTumbling() {
    BulletConfig config = new BulletConfig();
    Query query = new Query();
    Window window = WindowUtils.makeWindow(Window.Unit.TIME, 1000, Window.Unit.RECORD, 4);
    window.configure(config);
    query.setWindow(window);
    Aggregation aggregation = new Aggregation();
    aggregation.setType(Aggregation.Type.COUNT_DISTINCT);
    query.setAggregation(aggregation);
    Assert.assertEquals(WindowingOperations.findScheme(query, null, config).getClass(), Tumbling.class);
}
Also used : Window(com.yahoo.bullet.parsing.Window) Aggregation(com.yahoo.bullet.parsing.Aggregation) Query(com.yahoo.bullet.parsing.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Aggregations

Window (com.yahoo.bullet.parsing.Window)32 Test (org.testng.annotations.Test)24 BulletConfig (com.yahoo.bullet.common.BulletConfig)6 Query (com.yahoo.bullet.parsing.Query)6 Aggregation (com.yahoo.bullet.parsing.Aggregation)5 MockStrategy (com.yahoo.bullet.aggregations.MockStrategy)2 Meta (com.yahoo.bullet.result.Meta)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Map (java.util.Map)2 AdditiveTumbling (com.yahoo.bullet.windowing.AdditiveTumbling)1 Basic (com.yahoo.bullet.windowing.Basic)1 Reactive (com.yahoo.bullet.windowing.Reactive)1 Tumbling (com.yahoo.bullet.windowing.Tumbling)1