Search in sources :

Example 6 with ExpressionTypeManager

use of io.confluent.ksql.execution.util.ExpressionTypeManager in project ksql by confluentinc.

the class TermCompiler method visitInPredicate.

@Override
public Term visitInPredicate(final InPredicate inPredicate, final Context context) {
    final InPredicate preprocessed = InListEvaluator.preprocess(inPredicate, expressionTypeManager, context.getLambdaSqlTypeMapping());
    final Term value = process(preprocessed.getValue(), context);
    final List<Term> valueList = preprocessed.getValueList().getValues().stream().map(v -> process(v, context)).collect(ImmutableList.toImmutableList());
    return new InPredicateTerm(value, valueList);
}
Also used : TimestampLiteral(io.confluent.ksql.execution.expression.tree.TimestampLiteral) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) GenericsUtil(io.confluent.ksql.function.GenericsUtil) Pair(io.confluent.ksql.util.Pair) Term(io.confluent.ksql.execution.interpreter.terms.Term) LambdaFunction3Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction3Term) LiteralTerms(io.confluent.ksql.execution.interpreter.terms.LiteralTerms) Map(java.util.Map) ColumnReferenceTerm(io.confluent.ksql.execution.interpreter.terms.ColumnReferenceTerm) ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) SchemaConverters.sqlToFunctionConverter(io.confluent.ksql.schema.ksql.SchemaConverters.sqlToFunctionConverter) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) BytesLiteral(io.confluent.ksql.execution.expression.tree.BytesLiteral) LambdaVariable(io.confluent.ksql.execution.expression.tree.LambdaVariable) Expression(io.confluent.ksql.execution.expression.tree.Expression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) LambdaFunction1Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction1Term) KsqlException(io.confluent.ksql.util.KsqlException) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) Iterables(com.google.common.collect.Iterables) KsqlScalarFunction(io.confluent.ksql.function.KsqlScalarFunction) ExpressionVisitor(io.confluent.ksql.execution.expression.tree.ExpressionVisitor) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Field(io.confluent.ksql.execution.expression.tree.CreateStructExpression.Field) SqlMap(io.confluent.ksql.schema.ksql.types.SqlMap) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) ArrayList(java.util.ArrayList) InListEvaluator(io.confluent.ksql.execution.codegen.helpers.InListEvaluator) BetweenPredicate(io.confluent.ksql.execution.expression.tree.BetweenPredicate) Cast(io.confluent.ksql.execution.expression.tree.Cast) LikeTerm(io.confluent.ksql.execution.interpreter.terms.LikeTerm) CoercionUtil(io.confluent.ksql.execution.util.CoercionUtil) FunctionCallTerm(io.confluent.ksql.execution.interpreter.terms.FunctionCallTerm) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Context(io.confluent.ksql.execution.interpreter.TermCompiler.Context) LogicalBinaryTerms(io.confluent.ksql.execution.interpreter.terms.LogicalBinaryTerms) FunctionTypeInfo(io.confluent.ksql.execution.util.FunctionArgumentsUtil.FunctionTypeInfo) Type(io.confluent.ksql.execution.expression.tree.Type) Kudf(io.confluent.ksql.function.udf.Kudf) ParamTypes(io.confluent.ksql.function.types.ParamTypes) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ArrayType(io.confluent.ksql.function.types.ArrayType) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) DecimalUtil(io.confluent.ksql.util.DecimalUtil) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) UdfFactory(io.confluent.ksql.function.UdfFactory) ArgumentInfo(io.confluent.ksql.execution.util.FunctionArgumentsUtil.ArgumentInfo) SearchedCaseTerm(io.confluent.ksql.execution.interpreter.terms.SearchedCaseTerm) StructTerm(io.confluent.ksql.execution.interpreter.terms.StructTerm) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LambdaVariableTerm(io.confluent.ksql.execution.interpreter.terms.LambdaVariableTerm) DateLiteral(io.confluent.ksql.execution.expression.tree.DateLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) Immutable(com.google.errorprone.annotations.Immutable) IntervalUnit(io.confluent.ksql.execution.expression.tree.IntervalUnit) CreateMapTerm(io.confluent.ksql.execution.interpreter.terms.CreateMapTerm) LambdaFunction2Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction2Term) SubscriptTerm(io.confluent.ksql.execution.interpreter.terms.SubscriptTerm) ImmutableMap(com.google.common.collect.ImmutableMap) NotTerm(io.confluent.ksql.execution.interpreter.terms.NotTerm) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) WhenClause(io.confluent.ksql.execution.expression.tree.WhenClause) IsNullTerm(io.confluent.ksql.execution.interpreter.terms.IsNullTerm) IsNotNullPredicate(io.confluent.ksql.execution.expression.tree.IsNotNullPredicate) FunctionArgumentsUtil(io.confluent.ksql.execution.util.FunctionArgumentsUtil) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Streams(com.google.common.collect.Streams) SqlArray(io.confluent.ksql.schema.ksql.types.SqlArray) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) String.format(java.lang.String.format) CreateArrayTerm(io.confluent.ksql.execution.interpreter.terms.CreateArrayTerm) List(java.util.List) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) Optional(java.util.Optional) Column(io.confluent.ksql.schema.ksql.Column) DereferenceTerm(io.confluent.ksql.execution.interpreter.terms.DereferenceTerm) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ArrayAccess(io.confluent.ksql.execution.codegen.helpers.ArrayAccess) IsNullPredicate(io.confluent.ksql.execution.expression.tree.IsNullPredicate) ParamType(io.confluent.ksql.function.types.ParamType) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) HashMap(java.util.HashMap) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) ImmutableList(com.google.common.collect.ImmutableList) QualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp) SchemaConverters(io.confluent.ksql.schema.ksql.SchemaConverters) TimeLiteral(io.confluent.ksql.execution.expression.tree.TimeLiteral) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) IsNotNullTerm(io.confluent.ksql.execution.interpreter.terms.IsNotNullTerm) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) InPredicateTerm(io.confluent.ksql.execution.interpreter.terms.InPredicateTerm) LikePredicate(io.confluent.ksql.execution.expression.tree.LikePredicate) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) Term(io.confluent.ksql.execution.interpreter.terms.Term) LambdaFunction3Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction3Term) ColumnReferenceTerm(io.confluent.ksql.execution.interpreter.terms.ColumnReferenceTerm) LambdaFunction1Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction1Term) LikeTerm(io.confluent.ksql.execution.interpreter.terms.LikeTerm) FunctionCallTerm(io.confluent.ksql.execution.interpreter.terms.FunctionCallTerm) SearchedCaseTerm(io.confluent.ksql.execution.interpreter.terms.SearchedCaseTerm) StructTerm(io.confluent.ksql.execution.interpreter.terms.StructTerm) LambdaVariableTerm(io.confluent.ksql.execution.interpreter.terms.LambdaVariableTerm) CreateMapTerm(io.confluent.ksql.execution.interpreter.terms.CreateMapTerm) LambdaFunction2Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction2Term) SubscriptTerm(io.confluent.ksql.execution.interpreter.terms.SubscriptTerm) NotTerm(io.confluent.ksql.execution.interpreter.terms.NotTerm) IsNullTerm(io.confluent.ksql.execution.interpreter.terms.IsNullTerm) CreateArrayTerm(io.confluent.ksql.execution.interpreter.terms.CreateArrayTerm) DereferenceTerm(io.confluent.ksql.execution.interpreter.terms.DereferenceTerm) IsNotNullTerm(io.confluent.ksql.execution.interpreter.terms.IsNotNullTerm) InPredicateTerm(io.confluent.ksql.execution.interpreter.terms.InPredicateTerm) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) InPredicateTerm(io.confluent.ksql.execution.interpreter.terms.InPredicateTerm)

Example 7 with ExpressionTypeManager

use of io.confluent.ksql.execution.util.ExpressionTypeManager in project ksql by confluentinc.

the class UdafUtil method resolveAggregateFunction.

public static KsqlAggregateFunction<?, ?, ?> resolveAggregateFunction(final FunctionRegistry functionRegistry, final FunctionCall functionCall, final LogicalSchema schema, final KsqlConfig config) {
    try {
        final ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
        final SqlType argumentType = expressionTypeManager.getExpressionSqlType(functionCall.getArguments().get(0));
        // UDAFs only support one non-constant argument, and that argument must be a column reference
        final Expression arg = functionCall.getArguments().get(0);
        final Optional<Column> possibleValueColumn = arg instanceof UnqualifiedColumnReferenceExp ? schema.findValueColumn(((UnqualifiedColumnReferenceExp) arg).getColumnName()) : // assume that it is a column reference with no alias
        schema.findValueColumn(ColumnName.of(arg.toString()));
        final Column valueColumn = possibleValueColumn.orElseThrow(() -> new KsqlException("Could not find column for expression: " + arg));
        final AggregateFunctionInitArguments aggregateFunctionInitArguments = createAggregateFunctionInitArgs(valueColumn.index(), functionCall, config);
        return functionRegistry.getAggregateFunction(functionCall.getName(), argumentType, aggregateFunctionInitArguments);
    } catch (final Exception e) {
        throw new KsqlException("Failed to create aggregate function: " + functionCall, e);
    }
}
Also used : ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) AggregateFunctionInitArguments(io.confluent.ksql.function.AggregateFunctionInitArguments) Expression(io.confluent.ksql.execution.expression.tree.Expression) Column(io.confluent.ksql.schema.ksql.Column) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) KsqlException(io.confluent.ksql.util.KsqlException) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) KsqlException(io.confluent.ksql.util.KsqlException)

Example 8 with ExpressionTypeManager

use of io.confluent.ksql.execution.util.ExpressionTypeManager in project ksql by confluentinc.

the class InterpretedExpressionFactory method create.

@VisibleForTesting
public static InterpretedExpression create(final Expression expression, final LogicalSchema schema, final FunctionRegistry functionRegistry, final KsqlConfig ksqlConfig, final Context context) {
    try {
        final ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
        final SqlType returnType = expressionTypeManager.getExpressionSqlType(expression, context.getLambdaSqlTypeMapping());
        if (returnType == null) {
            // practice.
            throw new KsqlException("NULL expression not supported");
        }
        final Term term = new TermCompiler(functionRegistry, schema, ksqlConfig, expressionTypeManager).process(expression, context);
        return new InterpretedExpression(expression, returnType, term);
    } catch (KsqlException e) {
        throw new KsqlException("Invalid expression: " + e.getMessage() + ". expression: " + expression + ", schema:" + schema, e);
    } catch (final Exception e) {
        throw new RuntimeException("Unexpected error generating code for expression: " + expression, e);
    }
}
Also used : ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Term(io.confluent.ksql.execution.interpreter.terms.Term) KsqlException(io.confluent.ksql.util.KsqlException) KsqlException(io.confluent.ksql.util.KsqlException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with ExpressionTypeManager

use of io.confluent.ksql.execution.util.ExpressionTypeManager in project ksql by confluentinc.

the class LogicalPlanner method buildAggregateSchema.

private LogicalSchema buildAggregateSchema(final PlanNode sourcePlanNode, final GroupBy groupBy, final List<SelectExpression> projectionExpressions) {
    final LogicalSchema sourceSchema = sourcePlanNode.getSchema();
    final LogicalSchema projectionSchema = SelectionUtil.buildProjectionSchema(sourceSchema.withPseudoAndKeyColsInValue(analysis.getWindowExpression().isPresent(), ksqlConfig), projectionExpressions, metaStore);
    final List<Expression> groupByExps = groupBy.getGroupingExpressions();
    final Function<Expression, Optional<ColumnName>> selectResolver = expression -> {
        final List<ColumnName> foundInProjection = projectionExpressions.stream().filter(e -> e.getExpression().equals(expression)).map(SelectExpression::getAlias).collect(Collectors.toList());
        switch(foundInProjection.size()) {
            case 0:
                return Optional.empty();
            case 1:
                return Optional.of(foundInProjection.get(0));
            default:
                final String keys = GrammaticalJoiner.and().join(foundInProjection);
                throw new KsqlException("The projection contains a key column more than once: " + keys + "." + System.lineSeparator() + "Each key column must only be in the projection once. " + "If you intended to copy the key into the value, then consider using the " + AsValue.NAME + " function to indicate which key reference should be copied.");
        }
    };
    final List<Column> valueColumns;
    if (analysis.getInto().isPresent()) {
        // Persistent query:
        final Set<ColumnName> keyColumnNames = groupBy.getGroupingExpressions().stream().map(selectResolver).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toSet());
        valueColumns = projectionSchema.value().stream().filter(col -> !keyColumnNames.contains(col.name())).collect(Collectors.toList());
        if (valueColumns.isEmpty()) {
            throw new KsqlException("The projection contains no value columns.");
        }
    } else {
        // Transient query:
        // Transient queries only return value columns, so must have key columns in the value:
        valueColumns = projectionSchema.columns();
    }
    final Builder builder = LogicalSchema.builder();
    final ExpressionTypeManager typeManager = new ExpressionTypeManager(sourceSchema, metaStore);
    for (final Expression expression : groupByExps) {
        final SqlType keyType = typeManager.getExpressionSqlType(expression);
        final ColumnName keyName = selectResolver.apply(expression).orElseGet(() -> expression instanceof ColumnReferenceExp ? ((ColumnReferenceExp) expression).getColumnName() : ColumnNames.uniqueAliasFor(expression, sourceSchema));
        builder.keyColumn(keyName, keyType);
    }
    return builder.valueColumns(valueColumns).build();
}
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) ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) Optional(java.util.Optional) Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) SelectExpression(io.confluent.ksql.execution.plan.SelectExpression) KsqlException(io.confluent.ksql.util.KsqlException) ColumnName(io.confluent.ksql.name.ColumnName) ColumnReferenceExp(io.confluent.ksql.execution.expression.tree.ColumnReferenceExp) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) QualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp) 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) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) Column(io.confluent.ksql.schema.ksql.Column) List(java.util.List) SqlType(io.confluent.ksql.schema.ksql.types.SqlType)

Example 10 with ExpressionTypeManager

use of io.confluent.ksql.execution.util.ExpressionTypeManager in project ksql by confluentinc.

the class QueryProjectNode method selectOutputSchema.

private LogicalSchema selectOutputSchema(final MetaStore metaStore, final List<SelectExpression> selectExpressions, final boolean isWindowed) {
    final Builder schemaBuilder = LogicalSchema.builder();
    final LogicalSchema parentSchema = getSource().getSchema();
    // Copy meta & key columns into the value schema as SelectValueMapper expects it:
    final LogicalSchema schema = parentSchema.withPseudoAndKeyColsInValue(isWindowed, ksqlConfig);
    final ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(schema, metaStore);
    for (final SelectExpression select : selectExpressions) {
        final SqlType type = expressionTypeManager.getExpressionSqlType(select.getExpression());
        if (parentSchema.isKeyColumn(select.getAlias()) || select.getAlias().equals(SystemColumns.WINDOWSTART_NAME) || select.getAlias().equals(SystemColumns.WINDOWEND_NAME)) {
            schemaBuilder.keyColumn(select.getAlias(), type);
        } else {
            schemaBuilder.valueColumn(select.getAlias(), type);
        }
    }
    return schemaBuilder.build();
}
Also used : ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) SelectExpression(io.confluent.ksql.execution.plan.SelectExpression)

Aggregations

ExpressionTypeManager (io.confluent.ksql.execution.util.ExpressionTypeManager)13 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)11 Expression (io.confluent.ksql.execution.expression.tree.Expression)8 KsqlException (io.confluent.ksql.util.KsqlException)6 Column (io.confluent.ksql.schema.ksql.Column)5 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)5 List (java.util.List)5 Optional (java.util.Optional)5 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)4 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)4 Builder (io.confluent.ksql.schema.ksql.LogicalSchema.Builder)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Iterables (com.google.common.collect.Iterables)3 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)3 ColumnName (io.confluent.ksql.name.ColumnName)3 Streams (com.google.common.collect.Streams)2 Immutable (com.google.errorprone.annotations.Immutable)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 ColumnReferenceExp (io.confluent.ksql.execution.expression.tree.ColumnReferenceExp)2