use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class GenericRecordFactoryTest method shouldBuildPartialColumns.
@Test
public void shouldBuildPartialColumns() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).valueColumn(COL1, SqlTypes.STRING).build();
final List<ColumnName> names = ImmutableList.of(KEY, COL0);
final Expression exp = new StringLiteral("a");
// When:
final KsqlGenericRecord record = recordFactory.build(names, ImmutableList.of(exp, exp), schema, DataSourceType.KSTREAM);
// Then:
assertThat(record, is(KsqlGenericRecord.of(GenericKey.genericKey("a"), GenericRow.genericRow("a", null), 0)));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class GenericRecordFactoryTest method shouldThrowOnTableMissingKey.
@Test
public void shouldThrowOnTableMissingKey() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).valueColumn(COL1, SqlTypes.STRING).build();
final List<ColumnName> names = ImmutableList.of(COL0, COL1);
final Expression exp = new StringLiteral("a");
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> recordFactory.build(names, ImmutableList.of(exp, exp), schema, DataSourceType.KTABLE));
// Then:
assertThat(e.getMessage(), containsString("Value for primary key column"));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class GenericRecordFactoryTest method shouldThrowOnColumnMismatch.
@Test
public void shouldThrowOnColumnMismatch() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).valueColumn(COL1, SqlTypes.STRING).build();
final List<ColumnName> names = ImmutableList.of(KEY, COL0, COL1);
final Expression exp = new StringLiteral("a");
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> recordFactory.build(names, ImmutableList.of(exp, exp), schema, DataSourceType.KSTREAM));
// Then:
assertThat(e.getMessage(), containsString("Expected a value for each column"));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class GenericRecordFactoryTest method shouldThrowOnInsertRowoffset.
@Test
public void shouldThrowOnInsertRowoffset() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).build();
final Expression exp = new StringLiteral("a");
when(ksqlConfig.getBoolean(KsqlConfig.KSQL_ROWPARTITION_ROWOFFSET_ENABLED)).thenReturn(true);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> recordFactory.build(ImmutableList.of(SystemColumns.ROWTIME_NAME, KEY, SystemColumns.ROWOFFSET_NAME), ImmutableList.of(new LongLiteral(1L), exp, exp), schema, DataSourceType.KSTREAM));
// Then:
assertThat(e.getMessage(), containsString("Inserting into column `ROWOFFSET` is not allowed."));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class CreateSourceFactoryTest method shouldBuildSerdeFeaturesForStream.
@Test
public void shouldBuildSerdeFeaturesForStream() {
// Given:
givenCommandFactoriesWithMocks();
final CreateStream statement = new CreateStream(SOME_NAME, ONE_KEY_ONE_VALUE, false, true, withProperties, false);
final LogicalSchema schema = LogicalSchema.builder().keyColumn(ColumnName.of("k"), SqlTypes.INTEGER).valueColumn(ColumnName.of("bob"), SqlTypes.STRING).build();
when(keyOptionsSupplier.build(any(), any(), any(), any())).thenReturn(SerdeFeatures.of(SerdeFeature.WRAP_SINGLES));
when(valOptionsSupplier.build(any(), any(), any(), any())).thenReturn(SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES));
// When:
final CreateStreamCommand cmd = createSourceFactory.createStreamCommand(statement, ksqlConfig);
// Then:
verify(keyOptionsSupplier).build(schema, FormatFactory.of(SourcePropertiesUtil.getKeyFormat(statement.getProperties(), SOME_NAME)), SerdeFeatures.of(), ksqlConfig);
verify(valOptionsSupplier).build(schema, FormatFactory.of(SourcePropertiesUtil.getValueFormat(statement.getProperties())), statement.getProperties().getValueSerdeFeatures(), ksqlConfig);
assertThat(cmd.getFormats().getKeyFeatures(), is(SerdeFeatures.of(SerdeFeature.WRAP_SINGLES)));
assertThat(cmd.getFormats().getValueFeatures(), is(SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES)));
}
Aggregations