Search in sources :

Example 11 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class QueryProjectNodeTest method shouldBuildPullQueryOutputSchemaSelectKeyAndWindowBounds.

@Test
public void shouldBuildPullQueryOutputSchemaSelectKeyAndWindowBounds() {
    // Given:
    when(keyFormat.isWindowed()).thenReturn(true);
    when(source.getSchema()).thenReturn(INPUT_SCHEMA.withPseudoAndKeyColsInValue(true));
    final UnqualifiedColumnReferenceExp windowstartRef = new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWSTART_NAME);
    final UnqualifiedColumnReferenceExp windowendRef = new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWEND_NAME);
    selects = ImmutableList.<SelectItem>builder().add(new SingleColumn(windowstartRef, Optional.of(SystemColumns.WINDOWSTART_NAME))).add((new SingleColumn(windowendRef, Optional.of(SystemColumns.WINDOWEND_NAME)))).add((new SingleColumn(K_REF, Optional.of(K)))).build();
    when(analysis.getSelectColumnNames()).thenReturn(ImmutableSet.of(SystemColumns.WINDOWSTART_NAME, SystemColumns.WINDOWEND_NAME, K));
    // When:
    final QueryProjectNode projectNode = new QueryProjectNode(NODE_ID, source, selects, metaStore, ksqlConfig, analysis, true, plannerOptions, false);
    // Then:
    final LogicalSchema expected = LogicalSchema.builder().keyColumn(SystemColumns.WINDOWSTART_NAME, SqlTypes.BIGINT).keyColumn(SystemColumns.WINDOWEND_NAME, SqlTypes.BIGINT).keyColumn(K, SqlTypes.STRING).build();
    assertThat(expected, is(projectNode.getSchema()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 12 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class QueryProjectNodeTest method shouldBuildPullQueryOutputSchemaSelectStar.

@Test
public void shouldBuildPullQueryOutputSchemaSelectStar() {
    // Given:
    selects = ImmutableList.of(new AllColumns(Optional.of(SOURCE_NAME)));
    when(keyFormat.isWindowed()).thenReturn(false);
    when(analysis.getSelectColumnNames()).thenReturn(ImmutableSet.of());
    // When:
    final QueryProjectNode projectNode = new QueryProjectNode(NODE_ID, source, selects, metaStore, ksqlConfig, analysis, false, plannerOptions, false);
    // Then:
    final LogicalSchema expectedSchema = INPUT_SCHEMA;
    final LogicalSchema expectedIntermediateSchema = QueryLogicalPlanUtil.buildIntermediateSchema(INPUT_SCHEMA, true, false, true);
    assertThat(expectedIntermediateSchema, is(projectNode.getIntermediateSchema()));
    assertThat(expectedSchema.withoutPseudoAndKeyColsInValue(), is(projectNode.getSchema()));
    assertThrows(IllegalStateException.class, projectNode::getCompiledSelectExpressions);
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) AllColumns(io.confluent.ksql.parser.tree.AllColumns) Test(org.junit.Test)

Example 13 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class QueryProjectNodeTest method shouldBuildPullQueryOutputSchemaSelectValueAndWindowBounds.

@Test
public void shouldBuildPullQueryOutputSchemaSelectValueAndWindowBounds() {
    // Given:
    when(keyFormat.isWindowed()).thenReturn(true);
    when(source.getSchema()).thenReturn(INPUT_SCHEMA.withPseudoAndKeyColsInValue(true));
    final UnqualifiedColumnReferenceExp windowstartRef = new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWSTART_NAME);
    final UnqualifiedColumnReferenceExp windowendRef = new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWEND_NAME);
    selects = ImmutableList.<SelectItem>builder().add(new SingleColumn(windowstartRef, Optional.of(SystemColumns.WINDOWSTART_NAME))).add((new SingleColumn(windowendRef, Optional.of(SystemColumns.WINDOWEND_NAME)))).add((new SingleColumn(COL0_REF, Optional.of(COL0)))).build();
    when(analysis.getSelectColumnNames()).thenReturn(ImmutableSet.of(SystemColumns.WINDOWSTART_NAME, SystemColumns.WINDOWEND_NAME, COL0));
    // When:
    final QueryProjectNode projectNode = new QueryProjectNode(NODE_ID, source, selects, metaStore, ksqlConfig, analysis, true, plannerOptions, false);
    // Then:
    final LogicalSchema expected = LogicalSchema.builder().keyColumn(SystemColumns.WINDOWSTART_NAME, SqlTypes.BIGINT).keyColumn(SystemColumns.WINDOWEND_NAME, SqlTypes.BIGINT).valueColumn(COL0, SqlTypes.STRING).build();
    assertThat(expected, is(projectNode.getSchema()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 14 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class QueryFilterNodeTest method shouldNotExtractMultiColKeySchema.

@Test
public void shouldNotExtractMultiColKeySchema() {
    // Given:
    final LogicalSchema multiSchema = LogicalSchema.builder().keyColumn(ColumnName.of("K1"), SqlTypes.INTEGER).keyColumn(ColumnName.of("K2"), SqlTypes.INTEGER).valueColumn(ColumnName.of("C1"), SqlTypes.INTEGER).build();
    final Expression keyExp1 = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("K1")), new IntegerLiteral(1));
    final Expression keyExp2 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K2")), new IntegerLiteral(3));
    final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp1, keyExp2);
    when(source.getSchema()).thenReturn(multiSchema);
    QueryFilterNode filterNode = new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions);
    // When:
    final List<LookupConstraint> keys = filterNode.getLookupConstraints();
    // Then:
    assertThat(keys.size(), is(1));
    assertThat(keys.get(0), instanceOf(NonKeyConstraint.class));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 15 with LogicalSchema

use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.

the class DefaultSchemaInjectorFunctionalTest method constructCSASSource.

private void constructCSASSource(Schema valueSchema) {
    if (testType != TestType.CSAS_WITH_SCHEMA_ID) {
        return;
    }
    LogicalSchema.Builder builder = LogicalSchema.builder();
    valueSchema.fields().forEach(field -> {
        if (!field.name().equals("field1")) {
            builder.valueColumn(ColumnName.of(field.name()), SchemaConverters.connectToSqlConverter().toSqlType(field.schema()));
        }
    });
    builder.keyColumn(ColumnName.of("key"), SqlTypes.INTEGER);
    LogicalSchema schema = builder.build();
    when(metaStore.getSource(any())).thenReturn(ksqlStream);
    when(ksqlStream.getSchema()).thenReturn(schema);
    when(serviceContext.getSchemaRegistryClient()).thenReturn(srClient);
    when(serviceContext.getTopicClient()).thenReturn(topicClient);
    when(serviceContext.getConsumerGroupClient()).thenReturn(consumerGroupClient);
    when(executionContext.createSandbox(any())).thenReturn(executionSandbox);
    when(executionSandbox.plan(any(), any())).thenReturn(ksqlPlan);
    when(ksqlPlan.getDdlCommand()).thenReturn(Optional.of(ddlCommand));
    when(ddlCommand.getSchema()).thenReturn(schema);
    when(ddlCommand.getFormats()).thenReturn(Formats.of(FormatInfo.of(KafkaFormat.NAME), FormatInfo.of(AvroFormat.NAME), SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES), SerdeFeatures.of(SerdeFeature.WRAP_SINGLES)));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema)

Aggregations

LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)223 Test (org.junit.Test)152 Expression (io.confluent.ksql.execution.expression.tree.Expression)44 ColumnName (io.confluent.ksql.name.ColumnName)31 GenericRow (io.confluent.ksql.GenericRow)30 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)29 KsqlException (io.confluent.ksql.util.KsqlException)27 GenericKey (io.confluent.ksql.GenericKey)20 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)19 List (java.util.List)16 TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)14 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)14 Optional (java.util.Optional)14 Collectors (java.util.stream.Collectors)14 QueryContext (io.confluent.ksql.execution.context.QueryContext)13 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)12 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)12 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)12 Column (io.confluent.ksql.schema.ksql.Column)12 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)11