use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class DefaultSchemaInjector method buildElements.
private static TableElements buildElements(final ConfiguredStatement<CreateSource> preparedStatement, final Optional<SchemaAndId> keySchema, final Optional<SchemaAndId> valueSchema) {
final List<TableElement> elements = new ArrayList<>();
if (keySchema.isPresent()) {
final ColumnConstraints constraints = getKeyConstraints(preparedStatement.getStatement());
keySchema.get().columns.stream().map(col -> new TableElement(col.name(), new Type(col.type()), constraints)).forEach(elements::add);
} else {
getKeyColumns(preparedStatement).forEach(elements::add);
}
if (valueSchema.isPresent()) {
valueSchema.get().columns.stream().map(col -> new TableElement(col.name(), new Type(col.type()))).forEach(elements::add);
} else {
getValueColumns(preparedStatement).forEach(elements::add);
}
return TableElements.of(elements);
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteTypeUsingPlugin.
@Test
public void shouldRewriteTypeUsingPlugin() {
final Type type = new Type(SqlPrimitiveType.of("INTEGER"));
shouldRewriteUsingPlugin(type);
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class CreateSourceFactoryTest method shouldThrowOnRowTimeKeyColumn.
@Test
public void shouldThrowOnRowTimeKeyColumn() {
// Given:
final CreateStream statement = new CreateStream(SOME_NAME, TableElements.of(tableElement(ROWTIME_NAME.text(), new Type(BIGINT), KEY_CONSTRAINT)), false, true, withProperties, false);
// When:
final Exception e = assertThrows(KsqlException.class, () -> createSourceFactory.createStreamCommand(statement, ksqlConfig));
// Then:
assertThat(e.getMessage(), containsString("'ROWTIME' is a reserved column name."));
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class CreateSourceFactoryTest method shouldNotThrowOnKeyColumnThatIsNotCalledRowKey.
@Test
public void shouldNotThrowOnKeyColumnThatIsNotCalledRowKey() {
// Given:
final CreateStream statement = new CreateStream(SOME_NAME, TableElements.of(tableElement("someKey", new Type(SqlTypes.STRING), KEY_CONSTRAINT)), false, true, withProperties, false);
// When:
final CreateStreamCommand result = createSourceFactory.createStreamCommand(statement, ksqlConfig);
// Then:
assertThat(result.getSchema().key(), contains(keyColumn(ColumnName.of("someKey"), SqlTypes.STRING)));
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class CreateSourceFactoryTest method shouldCreateCommandForCreateSourceTable.
@Test
public void shouldCreateCommandForCreateSourceTable() {
// Given:
final CreateTable ddlStatement = new CreateTable(SOME_NAME, TableElements.of(tableElement("COL1", new Type(BIGINT), PRIMARY_KEY_CONSTRAINT), tableElement("COL2", new Type(SqlTypes.STRING))), false, true, withProperties, true);
// When:
final CreateTableCommand result = createSourceFactory.createTableCommand(ddlStatement, ksqlConfig);
// Then:
assertThat(result.getSourceName(), is(SOME_NAME));
assertThat(result.getTopicName(), is(TOPIC_NAME));
assertThat(result.getIsSource(), is(true));
}
Aggregations