Search in sources :

Example 41 with Type

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"));
}
Also used : DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Type(io.confluent.ksql.execution.expression.tree.Type) CreateTable(io.confluent.ksql.parser.tree.CreateTable) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 42 with Type

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
}
Also used : DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Type(io.confluent.ksql.execution.expression.tree.Type) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Example 43 with Type

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."));
}
Also used : DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Type(io.confluent.ksql.execution.expression.tree.Type) CreateStream(io.confluent.ksql.parser.tree.CreateStream) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 44 with Type

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."));
}
Also used : DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Type(io.confluent.ksql.execution.expression.tree.Type) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) CreateTable(io.confluent.ksql.parser.tree.CreateTable) SourceName(io.confluent.ksql.name.SourceName) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 45 with Type

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()));
}
Also used : DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Type(io.confluent.ksql.execution.expression.tree.Type) CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Aggregations

Type (io.confluent.ksql.execution.expression.tree.Type)73 Test (org.junit.Test)71 SqlPrimitiveType (io.confluent.ksql.schema.ksql.types.SqlPrimitiveType)23 DataSourceType (io.confluent.ksql.metastore.model.DataSource.DataSourceType)19 Matchers.containsString (org.hamcrest.Matchers.containsString)16 Cast (io.confluent.ksql.execution.expression.tree.Cast)13 CreateStream (io.confluent.ksql.parser.tree.CreateStream)13 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)12 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)12 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)12 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)12 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)12 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)12 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)12 Expression (io.confluent.ksql.execution.expression.tree.Expression)12 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)12 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)12 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)12 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)12 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)12