use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class CreateSourceFactoryTest method shouldThrowIfTableExists.
@Test
public void shouldThrowIfTableExists() {
// Given
final CreateTable ddlStatement = new CreateTable(TABLE_NAME, TableElements.of(tableElement("COL1", new Type(BIGINT), PRIMARY_KEY_CONSTRAINT), tableElement("COL2", new Type(SqlTypes.STRING))), false, false, withProperties, false);
// When:
final Exception e = assertThrows(KsqlException.class, () -> createSourceFactory.createTableCommand(ddlStatement, ksqlConfig));
// Then:
assertThat(e.getMessage(), containsString("Cannot add table 'table_bob': A table with the same name already exists"));
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class CreateSourceFactoryTest method shouldNotThrowOnRowKeyKeyColumn.
@Test
public void shouldNotThrowOnRowKeyKeyColumn() {
// Given:
final CreateStream statement = new CreateStream(SOME_NAME, TableElements.of(tableElement("k", new Type(SqlTypes.STRING), KEY_CONSTRAINT)), false, true, withProperties, false);
// When:
createSourceFactory.createStreamCommand(statement, ksqlConfig);
// Then: did not throw
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class CreateSourceFactoryTest method shouldThrowOnRowTimeValueColumn.
@Test
public void shouldThrowOnRowTimeValueColumn() {
// Given:
final CreateStream statement = new CreateStream(SOME_NAME, TableElements.of(tableElement(ROWTIME_NAME.text(), new Type(BIGINT))), 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 shouldThrowInCreateStreamOrReplaceOnSourceTables.
@Test
public void shouldThrowInCreateStreamOrReplaceOnSourceTables() {
// Given:
final SourceName existingTableName = SourceName.of("existingTableName");
final KsqlTable existingTable = mock(KsqlTable.class);
when(existingTable.getDataSourceType()).thenReturn(DataSourceType.KTABLE);
when(existingTable.isSource()).thenReturn(true);
when(metaStore.getSource(existingTableName)).thenReturn(existingTable);
final CreateTable ddlStatement = new CreateTable(existingTableName, TableElements.of(tableElement("COL1", new Type(BIGINT), PRIMARY_KEY_CONSTRAINT), tableElement("COL2", new Type(SqlTypes.STRING))), true, false, withProperties, false);
// When:
final Exception e = assertThrows(KsqlException.class, () -> createSourceFactory.createTableCommand(ddlStatement, ksqlConfig));
// Then:
assertThat(e.getMessage(), containsString("Cannot add table 'existingTableName': CREATE OR REPLACE is not supported on " + "source tables."));
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class CreateSourceFactoryTest method shouldBuildSchemaWithExplicitKeyFieldForStream.
@Test
public void shouldBuildSchemaWithExplicitKeyFieldForStream() {
// Given:
final CreateStream statement = new CreateStream(SOME_NAME, TableElements.of(tableElement("k", new Type(SqlTypes.STRING), KEY_CONSTRAINT), ELEMENT1, ELEMENT2), false, true, withProperties, false);
// When:
final CreateStreamCommand result = createSourceFactory.createStreamCommand(statement, ksqlConfig);
// Then:
assertThat(result.getSchema(), is(LogicalSchema.builder().keyColumn(ColumnName.of("k"), SqlTypes.STRING).valueColumn(ColumnName.of("bob"), SqlTypes.STRING).valueColumn(ColumnName.of("hojjat"), BIGINT).build()));
}
Aggregations