Search in sources :

Example 1 with KsqlWindowExpression

use of io.confluent.ksql.execution.windows.KsqlWindowExpression in project ksql by confluentinc.

the class RewrittenAnalysis method getWindowExpression.

@Override
public Optional<WindowExpression> getWindowExpression() {
    final Optional<WindowExpression> windowExpression = original.getWindowExpression();
    final Optional<RefinementInfo> refinementInfo = original.getRefinementInfo();
    /* Return the original window expression, unless there is no grace period provided during a
    suppression, in which case we rewrite the window expression to have a default grace period
    of zero.
    */
    if (!(windowExpression.isPresent() && !windowExpression.get().getKsqlWindowExpression().getGracePeriod().isPresent() && refinementInfo.isPresent() && refinementInfo.get().getOutputRefinement() == OutputRefinement.FINAL)) {
        return original.getWindowExpression();
    }
    final WindowExpression window = original.getWindowExpression().get();
    final KsqlWindowExpression ksqlWindowNew;
    final KsqlWindowExpression ksqlWindowOld = window.getKsqlWindowExpression();
    final Optional<NodeLocation> location = ksqlWindowOld.getLocation();
    final Optional<WindowTimeClause> retention = ksqlWindowOld.getRetention();
    if (ksqlWindowOld instanceof HoppingWindowExpression) {
        ksqlWindowNew = new HoppingWindowExpression(location, ((HoppingWindowExpression) ksqlWindowOld).getSize(), ((HoppingWindowExpression) ksqlWindowOld).getAdvanceBy(), retention, Optional.of(zeroGracePeriod));
    } else if (ksqlWindowOld instanceof TumblingWindowExpression) {
        ksqlWindowNew = new TumblingWindowExpression(location, ((TumblingWindowExpression) ksqlWindowOld).getSize(), retention, Optional.of(zeroGracePeriod));
    } else if (ksqlWindowOld instanceof SessionWindowExpression) {
        ksqlWindowNew = new SessionWindowExpression(location, ((SessionWindowExpression) ksqlWindowOld).getGap(), retention, Optional.of(zeroGracePeriod));
    } else {
        throw new KsqlException("WINDOW type must be HOPPING, TUMBLING, or SESSION");
    }
    return Optional.of(new WindowExpression(original.getWindowExpression().get().getWindowName(), ksqlWindowNew));
}
Also used : HoppingWindowExpression(io.confluent.ksql.execution.windows.HoppingWindowExpression) TumblingWindowExpression(io.confluent.ksql.execution.windows.TumblingWindowExpression) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) SessionWindowExpression(io.confluent.ksql.execution.windows.SessionWindowExpression) HoppingWindowExpression(io.confluent.ksql.execution.windows.HoppingWindowExpression) KsqlException(io.confluent.ksql.util.KsqlException) SessionWindowExpression(io.confluent.ksql.execution.windows.SessionWindowExpression) NodeLocation(io.confluent.ksql.parser.NodeLocation) RefinementInfo(io.confluent.ksql.serde.RefinementInfo) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) WindowTimeClause(io.confluent.ksql.execution.windows.WindowTimeClause) TumblingWindowExpression(io.confluent.ksql.execution.windows.TumblingWindowExpression)

Example 2 with KsqlWindowExpression

use of io.confluent.ksql.execution.windows.KsqlWindowExpression in project ksql by confluentinc.

the class LogicalPlanner method getWindowInfo.

private Optional<WindowInfo> getWindowInfo() {
    final KsqlTopic srcTopic = analysis.getFrom().getDataSource().getKsqlTopic();
    final Optional<WindowInfo> explicitWindowInfo = analysis.getWindowExpression().map(WindowExpression::getKsqlWindowExpression).map(KsqlWindowExpression::getWindowInfo);
    return explicitWindowInfo.isPresent() ? explicitWindowInfo : srcTopic.getKeyFormat().getWindowInfo();
}
Also used : KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) WindowInfo(io.confluent.ksql.serde.WindowInfo)

Example 3 with KsqlWindowExpression

use of io.confluent.ksql.execution.windows.KsqlWindowExpression in project ksql by confluentinc.

the class ExpressionParserTest method shouldParseWindowExpressionWithRetention.

@Test
public void shouldParseWindowExpressionWithRetention() {
    // When:
    final KsqlWindowExpression parsed = ExpressionParser.parseWindowExpression("TUMBLING (SIZE 1 DAYS, RETENTION 2 DAYS, GRACE PERIOD 2 DAYS)");
    // Then:
    assertThat(parsed, equalTo(new TumblingWindowExpression(parsed.getLocation(), new WindowTimeClause(1, TimeUnit.DAYS), Optional.of(new WindowTimeClause(2, TimeUnit.DAYS)), Optional.of(new WindowTimeClause(2, TimeUnit.DAYS)))));
}
Also used : KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) WindowTimeClause(io.confluent.ksql.execution.windows.WindowTimeClause) TumblingWindowExpression(io.confluent.ksql.execution.windows.TumblingWindowExpression) Test(org.junit.Test)

Example 4 with KsqlWindowExpression

use of io.confluent.ksql.execution.windows.KsqlWindowExpression in project ksql by confluentinc.

the class StatementRewriterTest method shouldRewriteWindowExpression.

@Test
public void shouldRewriteWindowExpression() {
    // Given:
    final KsqlWindowExpression ksqlWindowExpression = mock(KsqlWindowExpression.class);
    final WindowExpression windowExpression = new WindowExpression(location, "name", ksqlWindowExpression);
    // When:
    final AstNode rewritten = rewriter.rewrite(windowExpression, context);
    // Then:
    assertThat(rewritten, equalTo(new WindowExpression(location, "name", ksqlWindowExpression)));
}
Also used : WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 5 with KsqlWindowExpression

use of io.confluent.ksql.execution.windows.KsqlWindowExpression in project ksql by confluentinc.

the class ExpressionParser method parseWindowExpression.

public static KsqlWindowExpression parseWindowExpression(final String expressionText) {
    final ParserRuleContext parseTree = GrammarParseUtil.getParseTree(expressionText, SqlBaseParser::windowExpression);
    final WindowExpression windowExpression = new AstBuilder(TypeRegistry.EMPTY).buildWindowExpression(parseTree);
    return windowExpression.getKsqlWindowExpression();
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression)

Aggregations

KsqlWindowExpression (io.confluent.ksql.execution.windows.KsqlWindowExpression)7 TumblingWindowExpression (io.confluent.ksql.execution.windows.TumblingWindowExpression)3 WindowTimeClause (io.confluent.ksql.execution.windows.WindowTimeClause)3 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)3 Test (org.junit.Test)3 GenericRow (io.confluent.ksql.GenericRow)1 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1 MaterializationInfo (io.confluent.ksql.execution.materialization.MaterializationInfo)1 KsTransformer (io.confluent.ksql.execution.streams.transform.KsTransformer)1 HoppingWindowExpression (io.confluent.ksql.execution.windows.HoppingWindowExpression)1 SessionWindowExpression (io.confluent.ksql.execution.windows.SessionWindowExpression)1 ColumnName (io.confluent.ksql.name.ColumnName)1 NodeLocation (io.confluent.ksql.parser.NodeLocation)1 AstNode (io.confluent.ksql.parser.tree.AstNode)1 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)1 RefinementInfo (io.confluent.ksql.serde.RefinementInfo)1 WindowInfo (io.confluent.ksql.serde.WindowInfo)1 KsqlException (io.confluent.ksql.util.KsqlException)1 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1 Windowed (org.apache.kafka.streams.kstream.Windowed)1