Search in sources :

Example 6 with UnqualifiedColumnReferenceExp

use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.

the class JoinNode method validateKeyPresent.

@Override
void validateKeyPresent(final SourceName sinkName, final Projection projection) {
    if (joinKey.isForeignKey()) {
        final DataSourceNode leftInputTable = getLeftmostSourceNode();
        final SourceName leftInputTableName = leftInputTable.getAlias();
        final List<Column> leftInputTableKeys = leftInputTable.getDataSource().getSchema().key();
        final List<Column> missingKeys = leftInputTableKeys.stream().filter(k -> !projection.containsExpression(new QualifiedColumnReferenceExp(leftInputTableName, k.name())) && !projection.containsExpression(new UnqualifiedColumnReferenceExp(ColumnNames.generatedJoinColumnAlias(leftInputTableName, k.name())))).collect(Collectors.toList());
        if (!missingKeys.isEmpty()) {
            throwMissingKeyColumnForFkJoinException(missingKeys, leftInputTableName);
        }
    } else {
        final boolean atLeastOneKey = joinKey.getAllViableKeys(schema).stream().anyMatch(projection::containsExpression);
        if (!atLeastOneKey) {
            final boolean synthetic = joinKey.isSynthetic();
            final List<? extends Expression> viable = joinKey.getOriginalViableKeys(schema);
            throwKeysNotIncludedError(sinkName, "join expression", viable, false, synthetic);
        }
    }
}
Also used : DataSource(io.confluent.ksql.metastore.model.DataSource) Arrays(java.util.Arrays) ColumnName(io.confluent.ksql.name.ColumnName) SourceName(io.confluent.ksql.name.SourceName) WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) BiFunction(java.util.function.BiFunction) Pair(io.confluent.ksql.util.Pair) Immutable(com.google.errorprone.annotations.Immutable) Map(java.util.Map) ColumnReferenceExp(io.confluent.ksql.execution.expression.tree.ColumnReferenceExp) ColumnNames(io.confluent.ksql.schema.ksql.ColumnNames) ImmutableMap(com.google.common.collect.ImmutableMap) Expression(io.confluent.ksql.execution.expression.tree.Expression) Collection(java.util.Collection) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) Streams(com.google.common.collect.Streams) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) Stream(java.util.stream.Stream) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) Column(io.confluent.ksql.schema.ksql.Column) FormatInfo(io.confluent.ksql.serde.FormatInfo) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) SchemaKStream(io.confluent.ksql.structured.SchemaKStream) SchemaKTable(io.confluent.ksql.structured.SchemaKTable) KeyFormat(io.confluent.ksql.serde.KeyFormat) QueryContext(io.confluent.ksql.execution.context.QueryContext) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) KafkaTopicClient(io.confluent.ksql.services.KafkaTopicClient) Supplier(java.util.function.Supplier) NoneFormat(io.confluent.ksql.serde.none.NoneFormat) ImmutableList(com.google.common.collect.ImmutableList) ForeignKeyJoinParamsFactory(io.confluent.ksql.execution.streams.ForeignKeyJoinParamsFactory) Objects.requireNonNull(java.util.Objects.requireNonNull) QualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp) Projection(io.confluent.ksql.planner.Projection) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) RequiredColumns(io.confluent.ksql.planner.RequiredColumns) JoinParamsFactory(io.confluent.ksql.execution.streams.JoinParamsFactory) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Context(io.confluent.ksql.engine.rewrite.ExpressionTreeRewriter.Context) ExpressionTreeRewriter(io.confluent.ksql.engine.rewrite.ExpressionTreeRewriter) Collections(java.util.Collections) Column(io.confluent.ksql.schema.ksql.Column) QualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp) SourceName(io.confluent.ksql.name.SourceName) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)

Example 7 with UnqualifiedColumnReferenceExp

use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.

the class JoinNode method validateColumns.

@Override
protected Set<ColumnReferenceExp> validateColumns(final RequiredColumns requiredColumns) {
    final boolean noSyntheticKey = !finalJoin || !joinKey.isSynthetic();
    final RequiredColumns updated = noSyntheticKey ? requiredColumns : requiredColumns.asBuilder().remove(new UnqualifiedColumnReferenceExp(getOnlyElement(schema.key()).name())).build();
    final Set<ColumnReferenceExp> leftUnknown = left.validateColumns(updated);
    final Set<ColumnReferenceExp> rightUnknown = right.validateColumns(updated);
    return Sets.intersection(leftUnknown, rightUnknown);
}
Also used : ColumnReferenceExp(io.confluent.ksql.execution.expression.tree.ColumnReferenceExp) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) QualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp) RequiredColumns(io.confluent.ksql.planner.RequiredColumns) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)

Example 8 with UnqualifiedColumnReferenceExp

use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.

the class FlatMapNodeTest method setUp.

@Before
public void setUp() {
    when(source.getSchema()).thenReturn(SOURCE_SCHEMA);
    when(source.getNodeOutputType()).thenReturn(DataSourceType.KSTREAM);
    when(analysis.getTableFunctions()).thenReturn(ImmutableList.of(A_TABLE_FUNCTION));
    when(analysis.getSelectItems()).thenReturn(ImmutableList.of(new AllColumns(Optional.empty()), new SingleColumn(new UnqualifiedColumnReferenceExp(COL0), Optional.empty()), new SingleColumn(A_TABLE_FUNCTION, Optional.empty())));
    final MutableFunctionRegistry functionRegistry = new InternalFunctionRegistry();
    new UdtfLoader(functionRegistry, Optional.empty(), SqlTypeParser.create(TypeRegistry.EMPTY), true).loadUdtfFromClass(Explode.class, "load path");
    flatMapNode = new FlatMapNode(PLAN_ID, source, functionRegistry, analysis);
}
Also used : MutableFunctionRegistry(io.confluent.ksql.function.MutableFunctionRegistry) AllColumns(io.confluent.ksql.parser.tree.AllColumns) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) UdtfLoader(io.confluent.ksql.function.UdtfLoader) Before(org.junit.Before)

Example 9 with UnqualifiedColumnReferenceExp

use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.

the class ProjectionTest method shouldNotMatchUnqualifiedColumnToQualifiedSingleColumn.

@Test
public void shouldNotMatchUnqualifiedColumnToQualifiedSingleColumn() {
    // Given:
    final Projection projection = Projection.of(ImmutableList.of(new SingleColumn(new UnqualifiedColumnReferenceExp(COL0), Optional.empty())));
    // Then:
    assertThat(projection.containsExpression(new QualifiedColumnReferenceExp(A, COL0)), is(false));
}
Also used : QualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 10 with UnqualifiedColumnReferenceExp

use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.

the class LogicalPlannerTest method shouldRewritePartitionByForJoin.

@Test
public void shouldRewritePartitionByForJoin() {
    // Given:
    final String simpleQuery = "SELECT t1.col1, t2.col1 FROM test1 t1 JOIN test2 t2 ON t1.col0 = t2.col0 PARTITION BY t1.col1 EMIT CHANGES;";
    // When:
    final PlanNode logicalPlan = buildLogicalPlan(simpleQuery);
    // Then:
    final UserRepartitionNode repart = (UserRepartitionNode) logicalPlan.getSources().get(0).getSources().get(0);
    assertThat(repart.getPartitionBys(), equalTo(ImmutableList.of(new UnqualifiedColumnReferenceExp(ColumnName.of("T1_COL1")))));
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) Matchers.containsString(org.hamcrest.Matchers.containsString) UserRepartitionNode(io.confluent.ksql.planner.plan.UserRepartitionNode) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Aggregations

UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)152 Test (org.junit.Test)138 Expression (io.confluent.ksql.execution.expression.tree.Expression)85 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)79 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)59 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)57 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)55 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)45 KsqlException (io.confluent.ksql.util.KsqlException)32 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)29 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)26 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)22 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)18 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)17 GenericKey (io.confluent.ksql.GenericKey)12 WindowBounds (io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds)12 GenericRow (io.confluent.ksql.GenericRow)11 PlanNode (io.confluent.ksql.planner.plan.PlanNode)11 WindowRange (io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds.WindowRange)11 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)10