Search in sources :

Example 1 with PartitionBy

use of io.confluent.ksql.parser.tree.PartitionBy in project ksql by confluentinc.

the class LogicalPlanner method buildUserRepartitionNode.

private UserRepartitionNode buildUserRepartitionNode(final PlanNode currentNode, final PartitionBy partitionBy) {
    final List<Expression> rewrittenPartitionBys = partitionBy.getExpressions().stream().map(exp -> ExpressionTreeRewriter.rewriteWith(refRewriter::process, exp)).collect(Collectors.toList());
    final LogicalSchema schema = buildRepartitionedSchema(currentNode, rewrittenPartitionBys);
    return new UserRepartitionNode(new PlanNodeId("PartitionBy"), currentNode, schema, partitionBy.getExpressions(), rewrittenPartitionBys, ksqlConfig);
}
Also used : JoinInfo(io.confluent.ksql.analyzer.Analysis.JoinInfo) DataSource(io.confluent.ksql.metastore.model.DataSource) Leaf(io.confluent.ksql.planner.JoinTree.Leaf) AggregateAnalysisResult(io.confluent.ksql.analyzer.AggregateAnalysisResult) Into(io.confluent.ksql.analyzer.Analysis.Into) ColumnName(io.confluent.ksql.name.ColumnName) SourceName(io.confluent.ksql.name.SourceName) BiFunction(java.util.function.BiFunction) AggregateAnalyzer(io.confluent.ksql.analyzer.AggregateAnalyzer) FilterNode(io.confluent.ksql.planner.plan.FilterNode) SerdeFeaturesFactory(io.confluent.ksql.serde.SerdeFeaturesFactory) JoinKey(io.confluent.ksql.planner.plan.JoinNode.JoinKey) CodeGenRunner(io.confluent.ksql.execution.codegen.CodeGenRunner) WindowInfo(io.confluent.ksql.serde.WindowInfo) RewrittenAnalysis(io.confluent.ksql.analyzer.RewrittenAnalysis) QueryLimitNode(io.confluent.ksql.planner.plan.QueryLimitNode) AggregateNode(io.confluent.ksql.planner.plan.AggregateNode) AliasedDataSource(io.confluent.ksql.analyzer.Analysis.AliasedDataSource) TimestampExtractionPolicyFactory(io.confluent.ksql.execution.streams.timestamp.TimestampExtractionPolicyFactory) ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) KsqlBareOutputNode(io.confluent.ksql.planner.plan.KsqlBareOutputNode) SelectionUtil(io.confluent.ksql.planner.plan.SelectionUtil) PartitionBy(io.confluent.ksql.parser.tree.PartitionBy) ColumnReferenceExp(io.confluent.ksql.execution.expression.tree.ColumnReferenceExp) PreJoinProjectNode(io.confluent.ksql.planner.plan.PreJoinProjectNode) VisitParentExpressionVisitor(io.confluent.ksql.execution.expression.tree.VisitParentExpressionVisitor) FinalProjectNode(io.confluent.ksql.planner.plan.FinalProjectNode) ColumnNames(io.confluent.ksql.schema.ksql.ColumnNames) RefinementInfo(io.confluent.ksql.serde.RefinementInfo) ImmutableAnalysis(io.confluent.ksql.analyzer.ImmutableAnalysis) ExpressionEvaluator(io.confluent.ksql.execution.transform.ExpressionEvaluator) Expression(io.confluent.ksql.execution.expression.tree.Expression) JoinType(io.confluent.ksql.planner.plan.JoinNode.JoinType) Set(java.util.Set) QueryFilterNode(io.confluent.ksql.planner.plan.QueryFilterNode) KsqlConfig(io.confluent.ksql.util.KsqlConfig) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) PlanNodeId(io.confluent.ksql.planner.plan.PlanNodeId) SingleSourcePlanNode(io.confluent.ksql.planner.plan.SingleSourcePlanNode) Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) Objects(java.util.Objects) Join(io.confluent.ksql.planner.JoinTree.Join) List(java.util.List) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) QueryProjectNode(io.confluent.ksql.planner.plan.QueryProjectNode) Column(io.confluent.ksql.schema.ksql.Column) FormatInfo(io.confluent.ksql.serde.FormatInfo) ProjectNode(io.confluent.ksql.planner.plan.ProjectNode) Iterables(com.google.common.collect.Iterables) FormatFactory(io.confluent.ksql.serde.FormatFactory) GrammaticalJoiner(io.confluent.ksql.util.GrammaticalJoiner) KeyFormat(io.confluent.ksql.serde.KeyFormat) JoinNode(io.confluent.ksql.planner.plan.JoinNode) SuppressNode(io.confluent.ksql.planner.plan.SuppressNode) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) PartitionByParamsFactory(io.confluent.ksql.execution.streams.PartitionByParamsFactory) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Function(java.util.function.Function) NoneFormat(io.confluent.ksql.serde.none.NoneFormat) AsValue(io.confluent.ksql.function.udf.AsValue) QualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp) MetaStore(io.confluent.ksql.metastore.MetaStore) GroupBy(io.confluent.ksql.parser.tree.GroupBy) KsqlStructuredDataOutputNode(io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode) UserRepartitionNode(io.confluent.ksql.planner.plan.UserRepartitionNode) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) DataSourceNode(io.confluent.ksql.planner.plan.DataSourceNode) NewTopic(io.confluent.ksql.analyzer.Analysis.Into.NewTopic) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) OutputNode(io.confluent.ksql.planner.plan.OutputNode) FilterTypeValidator(io.confluent.ksql.analyzer.FilterTypeValidator) FlatMapNode(io.confluent.ksql.planner.plan.FlatMapNode) ValueFormat(io.confluent.ksql.serde.ValueFormat) SelectExpression(io.confluent.ksql.execution.plan.SelectExpression) NodeLocation(io.confluent.ksql.parser.NodeLocation) PreJoinRepartitionNode(io.confluent.ksql.planner.plan.PreJoinRepartitionNode) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) PlanNode(io.confluent.ksql.planner.plan.PlanNode) Context(io.confluent.ksql.engine.rewrite.ExpressionTreeRewriter.Context) ExpressionTreeRewriter(io.confluent.ksql.engine.rewrite.ExpressionTreeRewriter) OutputRefinement(io.confluent.ksql.parser.OutputRefinement) FilterType(io.confluent.ksql.analyzer.FilterTypeValidator.FilterType) Collections(java.util.Collections) PlanNodeId(io.confluent.ksql.planner.plan.PlanNodeId) Expression(io.confluent.ksql.execution.expression.tree.Expression) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) SelectExpression(io.confluent.ksql.execution.plan.SelectExpression) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) UserRepartitionNode(io.confluent.ksql.planner.plan.UserRepartitionNode)

Example 2 with PartitionBy

use of io.confluent.ksql.parser.tree.PartitionBy in project ksql by confluentinc.

the class PullQueryValidatorTest method shouldThrowOnPartitionBy.

@Test
public void shouldThrowOnPartitionBy() {
    // Given:
    when(analysis.getPartitionBy()).thenReturn(Optional.of(new PartitionBy(Optional.empty(), ImmutableList.of(AN_EXPRESSION))));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> validator.validate(analysis));
    // Then:
    assertThat(e.getMessage(), containsString("Pull queries don't support PARTITION BY clauses."));
}
Also used : PartitionBy(io.confluent.ksql.parser.tree.PartitionBy) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 3 with PartitionBy

use of io.confluent.ksql.parser.tree.PartitionBy in project ksql by confluentinc.

the class StatementRewriterTest method shouldRewriteQueryWithPartitionBy.

@Test
public void shouldRewriteQueryWithPartitionBy() {
    // Given:
    final PartitionBy partitionBy = mock(PartitionBy.class);
    final PartitionBy rewrittenPartitionBy = mock(PartitionBy.class);
    final Query query = givenQuery(Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(partitionBy), Optional.empty());
    when(mockRewriter.apply(partitionBy, context)).thenReturn(rewrittenPartitionBy);
    // When:
    final AstNode rewritten = rewriter.rewrite(query, context);
    // Then:
    assertThat(rewritten, equalTo(new Query(location, rewrittenSelect, rewrittenRelation, Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(rewrittenPartitionBy), Optional.empty(), Optional.of(refinementInfo), false, optionalInt)));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) PartitionBy(io.confluent.ksql.parser.tree.PartitionBy) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Example 4 with PartitionBy

use of io.confluent.ksql.parser.tree.PartitionBy in project ksql by confluentinc.

the class StatementRewriterTest method shouldRewritePartitionBy.

@Test
public void shouldRewritePartitionBy() {
    // Given:
    final PartitionBy partitionBy = new PartitionBy(location, ImmutableList.of(expression));
    when(expressionRewriter.apply(expression, context)).thenReturn(rewrittenExpression);
    // When:
    final AstNode rewritten = rewriter.rewrite(partitionBy, context);
    // Then:
    assertThat(rewritten, equalTo(new PartitionBy(location, ImmutableList.of(rewrittenExpression))));
}
Also used : PartitionBy(io.confluent.ksql.parser.tree.PartitionBy) AstNode(io.confluent.ksql.parser.tree.AstNode) Test(org.junit.Test)

Aggregations

PartitionBy (io.confluent.ksql.parser.tree.PartitionBy)4 Test (org.junit.Test)3 AstNode (io.confluent.ksql.parser.tree.AstNode)2 KsqlException (io.confluent.ksql.util.KsqlException)2 Iterables (com.google.common.collect.Iterables)1 AggregateAnalysisResult (io.confluent.ksql.analyzer.AggregateAnalysisResult)1 AggregateAnalyzer (io.confluent.ksql.analyzer.AggregateAnalyzer)1 AliasedDataSource (io.confluent.ksql.analyzer.Analysis.AliasedDataSource)1 Into (io.confluent.ksql.analyzer.Analysis.Into)1 NewTopic (io.confluent.ksql.analyzer.Analysis.Into.NewTopic)1 JoinInfo (io.confluent.ksql.analyzer.Analysis.JoinInfo)1 FilterTypeValidator (io.confluent.ksql.analyzer.FilterTypeValidator)1 FilterType (io.confluent.ksql.analyzer.FilterTypeValidator.FilterType)1 ImmutableAnalysis (io.confluent.ksql.analyzer.ImmutableAnalysis)1 RewrittenAnalysis (io.confluent.ksql.analyzer.RewrittenAnalysis)1 ExpressionTreeRewriter (io.confluent.ksql.engine.rewrite.ExpressionTreeRewriter)1 Context (io.confluent.ksql.engine.rewrite.ExpressionTreeRewriter.Context)1 CodeGenRunner (io.confluent.ksql.execution.codegen.CodeGenRunner)1 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1 ColumnReferenceExp (io.confluent.ksql.execution.expression.tree.ColumnReferenceExp)1