use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class AggregateExpressionRewriter method visitFunctionCall.
@Override
public Optional<Expression> visitFunctionCall(final FunctionCall node, final ExpressionTreeRewriter.Context<Void> context) {
final FunctionName functionName = node.getName();
if (functionRegistry.isAggregate(functionName)) {
final ColumnName aggVarName = ColumnNames.aggregateColumn(aggVariableIndex);
aggVariableIndex++;
return Optional.of(new UnqualifiedColumnReferenceExp(node.getLocation(), aggVarName));
} else {
final List<Expression> arguments = new ArrayList<>();
for (final Expression argExpression : node.getArguments()) {
arguments.add(context.process(argExpression));
}
return Optional.of(new FunctionCall(node.getLocation(), node.getName(), arguments));
}
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class FilterTypeValidator method getExpressionReturnType.
private SqlType getExpressionReturnType(final Expression exp) {
final ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
// Rewrite the expression with magic timestamps, so type checking can pass
final Expression magicTimestampRewrite = new StatementRewriteForMagicPseudoTimestamp().rewrite(exp);
try {
return expressionTypeManager.getExpressionSqlType(magicTimestampRewrite);
} catch (KsqlException e) {
throw new KsqlStatementException("Error in " + filterType.name() + " expression: " + e.getMessage(), exp.toString());
}
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class LogicalPlanner method verifyForeignKeyJoin.
private Optional<Expression> verifyForeignKeyJoin(final JoinInfo joinInfo, final PlanNode leftNode, final PlanNode rightNode) {
final JoinType joinType = joinInfo.getType();
final Expression leftExpression = joinInfo.getLeftJoinExpression();
final Expression rightExpression = joinInfo.getRightJoinExpression();
if (joinInfo.getType().equals(JoinType.OUTER)) {
throw new KsqlException(String.format("Invalid join type:" + " full-outer join not supported for foreign-key table-table join." + " Got %s %s %s.", joinInfo.getLeftSource().getDataSource().getName().text(), joinType, joinInfo.getRightSource().getDataSource().getName().text()));
}
// because a FK-join output table has the same PK as its left input table
if (!(leftNode instanceof DataSourceNode) || !(rightNode instanceof DataSourceNode)) {
throw new KsqlException(String.format("Invalid join condition:" + " foreign-key table-table joins are not supported as part of n-way joins." + " Got %s = %s.", joinInfo.getFlippedLeftJoinExpression(), joinInfo.getFlippedRightJoinExpression()));
}
final CodeGenRunner codeGenRunner = new CodeGenRunner(leftNode.getSchema(), ksqlConfig, metaStore);
final VisitParentExpressionVisitor<Optional<Expression>, Context<Void>> unqualifiedRewritter = new VisitParentExpressionVisitor<Optional<Expression>, Context<Void>>(Optional.empty()) {
@Override
public Optional<Expression> visitQualifiedColumnReference(final QualifiedColumnReferenceExp node, final Context<Void> ctx) {
return Optional.of(new UnqualifiedColumnReferenceExp(node.getColumnName()));
}
};
final Expression leftExpressionUnqualified = ExpressionTreeRewriter.rewriteWith(unqualifiedRewritter::process, leftExpression);
final ExpressionEvaluator expressionEvaluator = codeGenRunner.buildCodeGenFromParseTree(leftExpressionUnqualified, "Left Join Expression");
final SqlType fkType = expressionEvaluator.getExpressionType();
final SqlType rightKeyType = Iterables.getOnlyElement(rightNode.getSchema().key()).type();
verifyJoinConditionTypes(fkType, rightKeyType, leftExpression, rightExpression, joinInfo.hasFlippedJoinCondition());
if (((DataSourceNode) rightNode).isWindowed()) {
throw new KsqlException("Foreign-key table-table joins are not supported on windowed tables.");
}
return Optional.of(leftExpression);
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class LogicalPlanner method buildInternalRepartitionNode.
private PreJoinRepartitionNode buildInternalRepartitionNode(final PlanNode source, final String side, final Expression joinExpression, final BiFunction<Expression, Context<Void>, Optional<Expression>> plugin) {
final Expression rewrittenPartitionBy = ExpressionTreeRewriter.rewriteWith(plugin, joinExpression);
final LogicalSchema schema = buildRepartitionedSchema(source, Collections.singletonList(rewrittenPartitionBy));
return new PreJoinRepartitionNode(new PlanNodeId(side + "SourceKeyed"), source, schema, rewrittenPartitionBy);
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class LogicalPlanner method prepareSourceForJoin.
private PlanNode prepareSourceForJoin(final DataSourceNode sourceNode, final String side, final Expression joinExpression, final boolean isForeignKeyJoin) {
final PlanNode preProjectNode;
if (isForeignKeyJoin) {
// we do not need to repartition for foreign key joins, as FK joins do not
// have co-partitioning requirements
preProjectNode = sourceNode;
} else {
// it is always safe to build the repartition node - this operation will be
// a no-op if a repartition is not required. if the source is a table, and
// a repartition is needed, then an exception will be thrown
final VisitParentExpressionVisitor<Optional<Expression>, Context<Void>> rewriter = new VisitParentExpressionVisitor<Optional<Expression>, Context<Void>>(Optional.empty()) {
@Override
public Optional<Expression> visitQualifiedColumnReference(final QualifiedColumnReferenceExp node, final Context<Void> ctx) {
return Optional.of(new UnqualifiedColumnReferenceExp(node.getColumnName()));
}
};
preProjectNode = buildInternalRepartitionNode(sourceNode, side, joinExpression, rewriter::process);
}
return buildInternalProjectNode(preProjectNode, "PrependAlias" + side, sourceNode.getAlias());
}
Aggregations