Search in sources :

Example 56 with LogicalSchema

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

the class StepSchemaResolverTest method shouldResolveSchemaForTableSourceV1.

@Test
public void shouldResolveSchemaForTableSourceV1() {
    // Given:
    final TableSourceV1 step = new TableSourceV1(PROPERTIES, "foo", formats, Optional.empty(), SCHEMA, Optional.of(true), OptionalInt.of(SystemColumns.CURRENT_PSEUDOCOLUMN_VERSION_NUMBER));
    // When:
    final LogicalSchema result = resolver.resolve(step, SCHEMA);
    // Then:
    assertThat(result, is(SCHEMA.withPseudoAndKeyColsInValue(false)));
}
Also used : TableSourceV1(io.confluent.ksql.execution.plan.TableSourceV1) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 57 with LogicalSchema

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

the class StepSchemaResolverTest method shouldResolveSchemaForStreamSelectWithoutColumnNames.

@Test
public void shouldResolveSchemaForStreamSelectWithoutColumnNames() {
    // Given:
    final StreamSelect<?> step = new StreamSelect<>(PROPERTIES, streamSource, ImmutableList.of(ColumnName.of("NEW_KEY")), ImmutableList.of(add("JUICE", "ORANGE", "APPLE"), ref("PLANTAIN", "BANANA"), ref("CITRUS", "ORANGE")));
    // When:
    final LogicalSchema result = resolver.resolve(step, SCHEMA);
    // Then:
    assertThat(result, is(LogicalSchema.builder().keyColumn(ColumnName.of("NEW_KEY"), SqlTypes.INTEGER).valueColumn(ColumnName.of("JUICE"), SqlTypes.BIGINT).valueColumn(ColumnName.of("PLANTAIN"), SqlTypes.STRING).valueColumn(ColumnName.of("CITRUS"), SqlTypes.INTEGER).build()));
}
Also used : StreamSelect(io.confluent.ksql.execution.plan.StreamSelect) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 58 with LogicalSchema

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

the class StepSchemaResolverTest method shouldResolveSchemaForStreamSource.

@Test
public void shouldResolveSchemaForStreamSource() {
    final StreamSource step = new StreamSource(PROPERTIES, "foo", formats, Optional.empty(), SCHEMA, OptionalInt.of(SystemColumns.CURRENT_PSEUDOCOLUMN_VERSION_NUMBER));
    // When:
    final LogicalSchema result = resolver.resolve(step, SCHEMA);
    // Then:
    assertThat(result, is(SCHEMA.withPseudoAndKeyColsInValue(false)));
}
Also used : WindowedStreamSource(io.confluent.ksql.execution.plan.WindowedStreamSource) StreamSource(io.confluent.ksql.execution.plan.StreamSource) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 59 with LogicalSchema

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

the class StepSchemaResolverTest method shouldResolveSchemaForTableSelectKey.

@Test
public void shouldResolveSchemaForTableSelectKey() {
    // Given:
    final UnqualifiedColumnReferenceExp keyExpression1 = new UnqualifiedColumnReferenceExp(ColumnName.of("ORANGE"));
    final UnqualifiedColumnReferenceExp keyExpression2 = new UnqualifiedColumnReferenceExp(ColumnName.of("APPLE"));
    final TableSelectKey<GenericKey> step = new TableSelectKey<>(PROPERTIES, tableSource, formats, ImmutableList.of(keyExpression1, keyExpression2));
    // When:
    final LogicalSchema result = resolver.resolve(step, SCHEMA);
    // Then:
    assertThat(result, is(LogicalSchema.builder().keyColumn(keyExpression1.getColumnName(), SqlTypes.INTEGER).keyColumn(keyExpression2.getColumnName(), SqlTypes.BIGINT).valueColumns(SCHEMA.value()).build()));
}
Also used : TableSelectKey(io.confluent.ksql.execution.plan.TableSelectKey) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) GenericKey(io.confluent.ksql.GenericKey) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 60 with LogicalSchema

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

the class StepSchemaResolverTest method shouldResolveSchemaForStreamAggregate.

@Test
public void shouldResolveSchemaForStreamAggregate() {
    // Given:
    givenAggregateFunction("SUM", SqlTypes.BIGINT);
    final StreamAggregate step = new StreamAggregate(PROPERTIES, groupedStreamSource, formats, ImmutableList.of(ColumnName.of("ORANGE")), ImmutableList.of(functionCall("SUM", "APPLE")));
    // When:
    final LogicalSchema result = resolver.resolve(step, SCHEMA);
    // Then:
    assertThat(result, is(LogicalSchema.builder().keyColumn(ColumnName.of("K0"), SqlTypes.INTEGER).valueColumn(ColumnName.of("ORANGE"), SqlTypes.INTEGER).valueColumn(ColumnNames.aggregateColumn(0), SqlTypes.BIGINT).build()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) StreamAggregate(io.confluent.ksql.execution.plan.StreamAggregate) Test(org.junit.Test)

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