Search in sources :

Example 11 with CreateTableCommand

use of io.confluent.ksql.execution.ddl.commands.CreateTableCommand in project ksql by confluentinc.

the class CreateSourceFactoryTest method shouldBuildTimestampColumnForTable.

@Test
public void shouldBuildTimestampColumnForTable() {
    // Given:
    givenProperty(CommonCreateConfigs.TIMESTAMP_NAME_PROPERTY, new StringLiteral(quote(ELEMENT2.getName().text())));
    final CreateTable statement = new CreateTable(SOME_NAME, TABLE_ELEMENTS, false, true, withProperties, false);
    // When:
    final CreateTableCommand cmd = createSourceFactory.createTableCommand(statement, ksqlConfig);
    // Then:
    assertThat(cmd.getTimestampColumn(), is(Optional.of(new TimestampColumn(ELEMENT2.getName(), Optional.empty()))));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateTable(io.confluent.ksql.parser.tree.CreateTable) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) CreateTableCommand(io.confluent.ksql.execution.ddl.commands.CreateTableCommand) Test(org.junit.Test)

Example 12 with CreateTableCommand

use of io.confluent.ksql.execution.ddl.commands.CreateTableCommand 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));
}
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) CreateTableCommand(io.confluent.ksql.execution.ddl.commands.CreateTableCommand) Test(org.junit.Test)

Example 13 with CreateTableCommand

use of io.confluent.ksql.execution.ddl.commands.CreateTableCommand in project ksql by confluentinc.

the class CreateSourceFactoryTest method shouldCreateCommandForCreateTable.

@Test
public void shouldCreateCommandForCreateTable() {
    // 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, false);
    // 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(false));
}
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) CreateTableCommand(io.confluent.ksql.execution.ddl.commands.CreateTableCommand) Test(org.junit.Test)

Example 14 with CreateTableCommand

use of io.confluent.ksql.execution.ddl.commands.CreateTableCommand in project ksql by confluentinc.

the class CreateSourceFactoryTest method shouldCreateTableCommandWithSingleValueWrappingFromPropertiesNotConfig.

@Test
public void shouldCreateTableCommandWithSingleValueWrappingFromPropertiesNotConfig() {
    // Given:
    ksqlConfig = new KsqlConfig(ImmutableMap.of(KsqlConfig.KSQL_WRAP_SINGLE_VALUES, true));
    final ImmutableMap<String, Object> overrides = ImmutableMap.of(KsqlConfig.KSQL_WRAP_SINGLE_VALUES, true);
    givenProperty(CommonCreateConfigs.WRAP_SINGLE_VALUE, new BooleanLiteral("false"));
    final CreateTable statement = new CreateTable(SOME_NAME, TABLE_ELEMENTS_1_VALUE, false, true, withProperties, false);
    // When:
    final CreateTableCommand cmd = createSourceFactory.createTableCommand(statement, ksqlConfig.cloneWithPropertyOverwrite(overrides));
    // Then:
    assertThat(cmd.getFormats().getValueFeatures(), is(SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES)));
}
Also used : BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) CreateTable(io.confluent.ksql.parser.tree.CreateTable) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Matchers.containsString(org.hamcrest.Matchers.containsString) CreateTableCommand(io.confluent.ksql.execution.ddl.commands.CreateTableCommand) Test(org.junit.Test)

Example 15 with CreateTableCommand

use of io.confluent.ksql.execution.ddl.commands.CreateTableCommand in project ksql by confluentinc.

the class KsqlPlanV1Test method shouldReturnCreateAsPersistentQueryTypeOnCreateTable.

@Test
public void shouldReturnCreateAsPersistentQueryTypeOnCreateTable() {
    // Given:
    final CreateTableCommand ddlCommand = Mockito.mock(CreateTableCommand.class);
    when(ddlCommand.getIsSource()).thenReturn(false);
    final KsqlPlanV1 plan = new KsqlPlanV1("stmt", Optional.of(ddlCommand), Optional.of(queryPlan1));
    // When/Then:
    assertThat(plan.getPersistentQueryType(), is(Optional.of(KsqlConstants.PersistentQueryType.CREATE_AS)));
}
Also used : CreateTableCommand(io.confluent.ksql.execution.ddl.commands.CreateTableCommand) Test(org.junit.Test)

Aggregations

CreateTableCommand (io.confluent.ksql.execution.ddl.commands.CreateTableCommand)15 Test (org.junit.Test)13 CreateTable (io.confluent.ksql.parser.tree.CreateTable)8 DataSourceType (io.confluent.ksql.metastore.model.DataSource.DataSourceType)4 Type (io.confluent.ksql.execution.expression.tree.Type)3 KsqlTable (io.confluent.ksql.metastore.model.KsqlTable)3 KsqlException (io.confluent.ksql.util.KsqlException)3 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)2 TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)2 DataSource (io.confluent.ksql.metastore.model.DataSource)2 SourceName (io.confluent.ksql.name.SourceName)2 KsqlStructuredDataOutputNode (io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode)2 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)2 KsqlConfig (io.confluent.ksql.util.KsqlConfig)2 Throwables (com.google.common.base.Throwables)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ExecuteResult (io.confluent.ksql.KsqlExecutionContext.ExecuteResult)1