Search in sources :

Example 96 with UnqualifiedColumnReferenceExp

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

the class SchemaKTableTest method shouldBuildSchemaForSelectKey.

@Test
public void shouldBuildSchemaForSelectKey() {
    // Given:
    final String selectQuery = "SELECT col0 AS K, col2, col3 FROM test2 WHERE col0 > 100 EMIT CHANGES;";
    final PlanNode logicalPlan = buildLogicalPlan(selectQuery);
    initialSchemaKTable = buildSchemaKTableFromPlan(logicalPlan);
    // When:
    final SchemaKTable<?> resultSchemaKTable = initialSchemaKTable.selectKey(valueFormat.getFormatInfo(), ImmutableList.of(new UnqualifiedColumnReferenceExp(ColumnName.of("COL0"))), Optional.empty(), childContextStacker, true);
    // Then:
    assertThat(resultSchemaKTable.getSchema(), is(schemaResolver.resolve(resultSchemaKTable.getSourceStep(), initialSchemaKTable.getSchema())));
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 97 with UnqualifiedColumnReferenceExp

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

the class SchemaKTableTest method shouldFailSelectKeyForceRepartitionOnNonKeyColumn.

@Test
public void shouldFailSelectKeyForceRepartitionOnNonKeyColumn() {
    // Given:
    final String selectQuery = "SELECT col0, col2, col3 FROM test2 WHERE col0 > 100 EMIT CHANGES;";
    final PlanNode logicalPlan = buildLogicalPlan(selectQuery);
    initialSchemaKTable = buildSchemaKTableFromPlan(logicalPlan);
    // When:
    final UnsupportedOperationException e = assertThrows(UnsupportedOperationException.class, () -> initialSchemaKTable.selectKey(valueFormat.getFormatInfo(), ImmutableList.of(new UnqualifiedColumnReferenceExp(ColumnName.of("COL1"))), Optional.empty(), childContextStacker, true));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot repartition a TABLE source."));
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 98 with UnqualifiedColumnReferenceExp

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

the class SchemaKTableTest method shouldRewriteTimeComparisonInFilter.

@Test
public void shouldRewriteTimeComparisonInFilter() {
    // Given:
    final String selectQuery = "SELECT col0, col2, col3 FROM test2 " + "WHERE ROWTIME = '1984-01-01T00:00:00+00:00' EMIT CHANGES;";
    final PlanNode logicalPlan = buildLogicalPlan(selectQuery);
    final FilterNode filterNode = (FilterNode) logicalPlan.getSources().get(0).getSources().get(0);
    initialSchemaKTable = buildSchemaKTableFromPlan(logicalPlan);
    // When:
    final SchemaKTable<?> filteredSchemaKTable = initialSchemaKTable.filter(filterNode.getPredicate(), childContextStacker);
    // Then:
    final TableFilter<?> step = (TableFilter) filteredSchemaKTable.getSourceTableStep();
    assertThat(step.getFilterExpression(), Matchers.equalTo(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("ROWTIME")), new LongLiteral(441763200000L))));
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) PlanNode(io.confluent.ksql.planner.plan.PlanNode) TableFilter(io.confluent.ksql.execution.plan.TableFilter) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) FilterNode(io.confluent.ksql.planner.plan.FilterNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 99 with UnqualifiedColumnReferenceExp

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

the class ColumnReferenceValidatorTest method shouldThrowOnPossibleSyntheticKeyColumnIfNotValidSyntheticKeyColumnName.

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

Example 100 with UnqualifiedColumnReferenceExp

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

the class AggregateAnalyzerTest method shouldNotCaptureWindowStartAsRequiredColumn.

@Test
public void shouldNotCaptureWindowStartAsRequiredColumn() {
    // Given:
    givenWindowExpression();
    givenSelectExpression(new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWSTART_NAME));
    // When:
    final AggregateAnalysisResult result = analyzer.analyze(analysis, selects);
    // Then:
    final List<ColumnName> requiredColumnNames = result.getRequiredColumns().stream().map(ColumnReferenceExp::getColumnName).collect(Collectors.toList());
    assertThat(requiredColumnNames, not(hasItem(SystemColumns.WINDOWSTART_NAME)));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) 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