use of io.confluent.ksql.parser.properties.with.CreateSourceProperties in project ksql by confluentinc.
the class DefaultSchemaInjector method addSchemaFields.
private static CreateSource addSchemaFields(final ConfiguredStatement<CreateSource> preparedStatement, final Optional<SchemaAndId> keySchema, final Optional<SchemaAndId> valueSchema) {
final TableElements elements = buildElements(preparedStatement, keySchema, valueSchema);
final CreateSource statement = preparedStatement.getStatement();
final CreateSourceProperties properties = statement.getProperties();
final Optional<String> keySchemaName;
final Optional<String> valueSchemaName;
// Only populate key and value schema names when schema ids are explicitly provided
if (properties.getKeySchemaId().isPresent() && keySchema.isPresent()) {
keySchemaName = Optional.ofNullable(keySchema.get().rawSchema.name());
} else {
keySchemaName = Optional.empty();
}
if (properties.getValueSchemaId().isPresent() && valueSchema.isPresent()) {
valueSchemaName = Optional.ofNullable(valueSchema.get().rawSchema.name());
} else {
valueSchemaName = Optional.empty();
}
final CreateSourceProperties newProperties = statement.getProperties().withKeyValueSchemaName(keySchemaName, valueSchemaName);
return statement.copyWith(elements, newProperties);
}
use of io.confluent.ksql.parser.properties.with.CreateSourceProperties in project ksql by confluentinc.
the class DefaultSchemaInjector method getValueSchema.
private Optional<SchemaAndId> getValueSchema(final ConfiguredStatement<CreateSource> statement) {
final CreateSourceProperties props = statement.getStatement().getProperties();
final FormatInfo valueFormat = SourcePropertiesUtil.getValueFormat(props);
if (!shouldInferSchema(props.getValueSchemaId(), statement, valueFormat, false)) {
return Optional.empty();
}
return Optional.of(getSchema(Optional.of(props.getKafkaTopic()), props.getValueSchemaId(), valueFormat, props.getValueSerdeFeatures(), statement.getStatementText(), false));
}
use of io.confluent.ksql.parser.properties.with.CreateSourceProperties in project ksql by confluentinc.
the class TopicCreateInjectorTest method shouldPassThroughWithClauseToBuilderForCreate.
@Test
public void shouldPassThroughWithClauseToBuilderForCreate() {
// Given:
givenStatement("CREATE STREAM x (FOO VARCHAR) WITH(value_format='avro', kafka_topic='topic', partitions=2);");
final CreateSourceProperties props = ((CreateSource) statement.getStatement()).getProperties();
// When:
injector.inject(statement, builder);
// Then:
verify(builder).withWithClause(Optional.of(props.getKafkaTopic()), props.getPartitions(), props.getReplicas());
}
use of io.confluent.ksql.parser.properties.with.CreateSourceProperties in project ksql by confluentinc.
the class SqlFormatterTest method shouldFormatCreateTableStatementWithExplicitTimestamp.
@Test
public void shouldFormatCreateTableStatementWithExplicitTimestamp() {
// Given:
final CreateSourceProperties props = CreateSourceProperties.from(new ImmutableMap.Builder<String, Literal>().putAll(SOME_WITH_PROPS.copyOfOriginalLiterals()).put(CommonCreateConfigs.TIMESTAMP_NAME_PROPERTY, new StringLiteral("Foo")).put(CommonCreateConfigs.TIMESTAMP_FORMAT_PROPERTY, new StringLiteral("%s")).build());
final CreateTable createTable = new CreateTable(TEST, ELEMENTS_WITH_PRIMARY_KEY, false, false, props, false);
// When:
final String sql = SqlFormatter.formatSql(createTable);
// Then:
assertThat(sql, is("CREATE TABLE TEST (`k3` STRING PRIMARY KEY, `Foo` STRING) " + "WITH (KAFKA_TOPIC='topic_test', " + "TIMESTAMP='Foo', TIMESTAMP_FORMAT='%s', VALUE_FORMAT='JSON');"));
}
use of io.confluent.ksql.parser.properties.with.CreateSourceProperties in project ksql by confluentinc.
the class SqlFormatterTest method shouldFormatCreateSourceTableStatement.
@Test
public void shouldFormatCreateSourceTableStatement() {
// Given:
final CreateSourceProperties props = CreateSourceProperties.from(new ImmutableMap.Builder<String, Literal>().putAll(SOME_WITH_PROPS.copyOfOriginalLiterals()).build());
final CreateTable createTable = new CreateTable(TEST, ELEMENTS_WITH_PRIMARY_KEY, false, false, props, true);
// When:
final String sql = SqlFormatter.formatSql(createTable);
// Then:
assertThat(sql, is("CREATE SOURCE TABLE TEST (`k3` STRING PRIMARY KEY, `Foo` STRING) " + "WITH (KAFKA_TOPIC='topic_test', VALUE_FORMAT='JSON');"));
}
Aggregations