Search in sources :

Example 11 with QualifiedColumnReferenceExp

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

the class LogicalPlanner method buildJoinKey.

private JoinKey buildJoinKey(final Join join) {
    final List<QualifiedColumnReferenceExp> viableKeyColumns = join.viableKeyColumns();
    if (viableKeyColumns.isEmpty()) {
        return JoinKey.syntheticColumn();
    }
    final Projection projection = Projection.of(analysis.original().getSelectItems());
    final List<QualifiedColumnReferenceExp> availableKeyColumns = viableKeyColumns.stream().filter(projection::containsExpression).collect(Collectors.toList());
    final QualifiedColumnReferenceExp keyColumn = availableKeyColumns.isEmpty() ? // Lack of availability is handle later.
    viableKeyColumns.get(0) : availableKeyColumns.get(0);
    final ColumnName keyColumnName = ColumnNames.generatedJoinColumnAlias(keyColumn.getQualifier(), keyColumn.getColumnName());
    return JoinKey.sourceColumn(keyColumnName, viableKeyColumns);
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) QualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp)

Example 12 with QualifiedColumnReferenceExp

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

the class ExpressionTypeManagerTest method shouldFailOnQualfiedColumnReference.

@Test
public void shouldFailOnQualfiedColumnReference() {
    // Given:
    final Expression expression = new QualifiedColumnReferenceExp(SourceName.of("foo"), ColumnName.of("bar"));
    // When:
    assertThrows(IllegalStateException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
}
Also used : ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) QualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp) Test(org.junit.Test)

Example 13 with QualifiedColumnReferenceExp

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

the class ProjectionTest method shouldNotMatchQualifiedColumnToDifferentQualifiedSingleColumn.

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

Example 14 with QualifiedColumnReferenceExp

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

the class ProjectionTest method shouldNotMatchQualifiedColumnToUnqualifiedSingleColumn.

@Test
public void shouldNotMatchQualifiedColumnToUnqualifiedSingleColumn() {
    // Given:
    final Projection projection = Projection.of(ImmutableList.of(new SingleColumn(new QualifiedColumnReferenceExp(A, COL0), Optional.empty())));
    // Then:
    assertThat(projection.containsExpression(new UnqualifiedColumnReferenceExp(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 15 with QualifiedColumnReferenceExp

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

the class ColumnReferenceValidatorTest method shouldThrowOnPossibleSyntheticKeyColumnIfQualifiedColumnReference.

@Test
public void shouldThrowOnPossibleSyntheticKeyColumnIfQualifiedColumnReference() {
    // Given:
    when(sourceSchemas.isJoin()).thenReturn(true);
    final Expression notSyntheticKey = new QualifiedColumnReferenceExp(SourceName.of("Bob"), ColumnName.of("ROWKEY"));
    // When:
    final Exception e = assertThrows(UnknownColumnException.class, () -> analyzer.analyzeExpression(notSyntheticKey, "SELECT"));
    // Then:
    assertThat(e.getMessage(), containsString("SELECT column 'Bob.ROWKEY' cannot be resolved."));
}
Also used : Expression(io.confluent.ksql.execution.expression.tree.Expression) QualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp) UnknownColumnException(io.confluent.ksql.util.UnknownColumnException) Test(org.junit.Test)

Aggregations

QualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp)18 Test (org.junit.Test)13 Expression (io.confluent.ksql.execution.expression.tree.Expression)9 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)6 Context (io.confluent.ksql.engine.rewrite.ExpressionTreeRewriter.Context)4 ColumnName (io.confluent.ksql.name.ColumnName)4 SingleColumn (io.confluent.ksql.parser.tree.SingleColumn)4 Optional (java.util.Optional)4 VisitParentExpressionVisitor (io.confluent.ksql.execution.expression.tree.VisitParentExpressionVisitor)3 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)3 KsqlWindowExpression (io.confluent.ksql.execution.windows.KsqlWindowExpression)3 SourceName (io.confluent.ksql.name.SourceName)3 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)3 KsqlException (io.confluent.ksql.util.KsqlException)3 ExpressionTreeRewriter (io.confluent.ksql.engine.rewrite.ExpressionTreeRewriter)2 CodeGenRunner (io.confluent.ksql.execution.codegen.CodeGenRunner)2 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)2 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)2 ColumnReferenceExp (io.confluent.ksql.execution.expression.tree.ColumnReferenceExp)2 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)2