Search in sources :

Example 6 with CreateTableCommand

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

the class KsqlPlanV1Test method shouldReturnCreateSourcePersistentQueryTypeOnCreateSourceTable.

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

Example 7 with CreateTableCommand

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

the class DdlCommandExecTest method shouldAddSourceTable.

@Test
public void shouldAddSourceTable() {
    // Given:
    final CreateTableCommand cmd = buildCreateTable(TABLE_NAME, false, true);
    // When:
    cmdExec.execute(SQL_TEXT, cmd, true, ImmutableSet.of(TABLE_NAME));
    // Then:
    final KsqlTable ksqlTable = (KsqlTable) metaStore.getSource(TABLE_NAME);
    assertThat(ksqlTable.isSource(), is(true));
    // Check query source was not added as constraints for source tables
    assertThat(metaStore.getSourceConstraints(TABLE_NAME), is(NO_QUERY_SOURCES));
}
Also used : KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) CreateTableCommand(io.confluent.ksql.execution.ddl.commands.CreateTableCommand) Test(org.junit.Test)

Example 8 with CreateTableCommand

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

the class DdlCommandExecTest method shouldAddNormalTableWhenNoTypeIsSpecified.

@Test
public void shouldAddNormalTableWhenNoTypeIsSpecified() {
    // Given:
    final CreateTableCommand cmd = buildCreateTable(SourceName.of("t1"), false, null);
    // When:
    cmdExec.execute(SQL_TEXT, cmd, true, NO_QUERY_SOURCES);
    // Then:
    final KsqlTable ksqlTable = (KsqlTable) metaStore.getSource(SourceName.of("t1"));
    assertThat(ksqlTable.isSource(), is(false));
}
Also used : KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) CreateTableCommand(io.confluent.ksql.execution.ddl.commands.CreateTableCommand) Test(org.junit.Test)

Example 9 with CreateTableCommand

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

the class DdlCommandExecTest method shouldThrowOnDropTableWhenConstraintExist.

@Test
public void shouldThrowOnDropTableWhenConstraintExist() {
    // Given:
    final CreateTableCommand table1 = buildCreateTable(SourceName.of("t1"), false, false);
    final CreateTableCommand table2 = buildCreateTable(SourceName.of("t2"), false, false);
    final CreateTableCommand table3 = buildCreateTable(SourceName.of("t3"), false, false);
    cmdExec.execute(SQL_TEXT, table1, true, Collections.emptySet());
    cmdExec.execute(SQL_TEXT, table2, true, Collections.singleton(SourceName.of("t1")));
    cmdExec.execute(SQL_TEXT, table3, true, Collections.singleton(SourceName.of("t1")));
    // When:
    final DropSourceCommand dropStream = buildDropSourceCommand(SourceName.of("t1"));
    final Exception e = assertThrows(KsqlReferentialIntegrityException.class, () -> cmdExec.execute(SQL_TEXT, dropStream, false, Collections.emptySet()));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot drop t1."));
    assertThat(e.getMessage(), containsString("The following streams and/or tables read from this source: [t2, t3]."));
    assertThat(e.getMessage(), containsString("You need to drop them before dropping t1."));
}
Also used : DropSourceCommand(io.confluent.ksql.execution.ddl.commands.DropSourceCommand) CreateTableCommand(io.confluent.ksql.execution.ddl.commands.CreateTableCommand) KsqlReferentialIntegrityException(io.confluent.ksql.util.KsqlReferentialIntegrityException) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 10 with CreateTableCommand

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

the class CreateSourceFactoryTest method shouldCreateTableCommandWithSingleValueWrappingFromConfig.

@Test
public void shouldCreateTableCommandWithSingleValueWrappingFromConfig() {
    // Given:
    ksqlConfig = new KsqlConfig(ImmutableMap.of(KsqlConfig.KSQL_WRAP_SINGLE_VALUES, false));
    final CreateTable statement = new CreateTable(SOME_NAME, TABLE_ELEMENTS_1_VALUE, false, true, withProperties, false);
    // When:
    final CreateTableCommand cmd = createSourceFactory.createTableCommand(statement, ksqlConfig);
    // Then:
    assertThat(cmd.getFormats().getValueFeatures(), is(SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES)));
}
Also used : CreateTable(io.confluent.ksql.parser.tree.CreateTable) KsqlConfig(io.confluent.ksql.util.KsqlConfig) 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