Search in sources :

Example 31 with LogicalSchema

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

the class WindowedRowTest method shouldImplementEquals.

@SuppressWarnings("UnstableApiUsage")
@Test
public void shouldImplementEquals() {
    final LogicalSchema differentSchema = LogicalSchema.builder().keyColumn(ColumnName.of("k0"), SqlTypes.STRING).keyColumn(ColumnName.of("k1"), SqlTypes.INTEGER).valueColumn(ColumnName.of("diff0"), SqlTypes.STRING).valueColumn(ColumnName.of("diff1"), SqlTypes.DOUBLE).build();
    new EqualsTester().addEqualityGroup(WindowedRow.of(SCHEMA, A_WINDOWED_KEY, A_VALUE, A_ROWTIME), WindowedRow.of(SCHEMA, A_WINDOWED_KEY, A_VALUE, A_ROWTIME)).addEqualityGroup(WindowedRow.of(differentSchema, A_WINDOWED_KEY, A_VALUE, A_ROWTIME)).addEqualityGroup(WindowedRow.of(SCHEMA, new Windowed<>(GenericKey.genericKey(null, null), A_WINDOW), A_VALUE, A_ROWTIME)).addEqualityGroup(WindowedRow.of(SCHEMA, new Windowed<>(A_KEY, mock(TimeWindow.class, "diff")), A_VALUE, A_ROWTIME)).addEqualityGroup(WindowedRow.of(SCHEMA, A_WINDOWED_KEY, GenericRow.genericRow(null, null), A_ROWTIME)).addEqualityGroup(WindowedRow.of(SCHEMA, A_WINDOWED_KEY, A_VALUE, -1L)).testEquals();
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) EqualsTester(com.google.common.testing.EqualsTester) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 32 with LogicalSchema

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

the class GroupByParamsV1FactoryTest method shouldSetKeyNameFromSingleGroupByColumnName.

@Test
public void shouldSetKeyNameFromSingleGroupByColumnName() {
    // Given:
    when(groupBy0.getExpression()).thenReturn(new UnqualifiedColumnReferenceExp(ColumnName.of("Bob")));
    // When:
    final LogicalSchema schema = GroupByParamsV1Factory.buildSchema(SOURCE_SCHEMA, ImmutableList.of(groupBy0));
    // Then:
    assertThat(schema, is(LogicalSchema.builder().keyColumn(ColumnName.of("Bob"), SqlTypes.INTEGER).valueColumns(SOURCE_SCHEMA.value()).build()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 33 with LogicalSchema

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

the class JoinParamsFactoryTest method shouldThrowOnKeyTypeMismatch.

@Test
public void shouldThrowOnKeyTypeMismatch() {
    // Given:
    final LogicalSchema intKeySchema = LogicalSchema.builder().keyColumn(ColumnName.of("BOB"), SqlTypes.INTEGER).valueColumn(ColumnName.of("BLUE"), SqlTypes.STRING).valueColumn(ColumnName.of("GREEN"), SqlTypes.INTEGER).build().withPseudoAndKeyColsInValue(false);
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> JoinParamsFactory.create(ColumnName.of("BOB"), intKeySchema, RIGHT_SCHEMA));
    // Then:
    assertThat(e.getMessage(), containsString("Invalid join. Key types differ: INTEGER vs STRING"));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 34 with LogicalSchema

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

the class EngineExecutor method validateExistingSink.

private void validateExistingSink(final KsqlStructuredDataOutputNode outputNode) {
    final SourceName name = outputNode.getSinkName().get();
    final DataSource existing = engineContext.getMetaStore().getSource(name);
    if (existing == null) {
        throw new KsqlException(String.format("%s does not exist.", outputNode));
    }
    if (existing.getDataSourceType() != outputNode.getNodeOutputType()) {
        throw new KsqlException(String.format("Incompatible data sink and query result. Data sink" + " (%s) type is %s but select query result is %s.", name.text(), existing.getDataSourceType(), outputNode.getNodeOutputType()));
    }
    final LogicalSchema resultSchema = outputNode.getSchema();
    final LogicalSchema existingSchema = existing.getSchema();
    if (!resultSchema.compatibleSchema(existingSchema)) {
        throw new KsqlException("Incompatible schema between results and sink." + System.lineSeparator() + "Result schema is " + resultSchema + System.lineSeparator() + "Sink schema is " + existingSchema);
    }
}
Also used : SourceName(io.confluent.ksql.name.SourceName) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlException(io.confluent.ksql.util.KsqlException) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 35 with LogicalSchema

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

the class SourceSchemas method matchesNonValueField.

/**
 * Determines if the supplied {@code column} matches a source(s) meta or key fields.
 *
 * <p>The supplied name can be prefixed with a source name. In which case, only that specific
 * source is checked. If no prefix is present, all sources are checked.
 *
 * @param column the field name to search for. Can be prefixed by source name.
 * @return true if this the supplied {@code column} matches a non-value field
 */
boolean matchesNonValueField(final Optional<SourceName> source, final ColumnName column) {
    if (!source.isPresent()) {
        return sourceSchemas.values().stream().anyMatch(schema -> SystemColumns.isPseudoColumn(column, rowpartitionRowoffsetEnabled) || schema.isKeyColumn(column));
    }
    final SourceName sourceName = source.get();
    final LogicalSchema sourceSchema = sourceSchemas.get(sourceName);
    if (sourceSchema == null) {
        throw new IllegalArgumentException("Unknown source: " + sourceName);
    }
    return sourceSchema.isKeyColumn(column) || SystemColumns.isPseudoColumn(column, rowpartitionRowoffsetEnabled);
}
Also used : SourceName(io.confluent.ksql.name.SourceName) 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