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);
}
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."));
}
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)));
}
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))));
}
Aggregations