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();
}
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()));
}
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"));
}
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);
}
}
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);
}
Aggregations