Search in sources :

Example 1 with DropTable

use of io.confluent.ksql.parser.tree.DropTable in project ksql by confluentinc.

the class CommandFactoriesTest method shouldCreateCommandForDropTable.

@Test
public void shouldCreateCommandForDropTable() {
    final DdlCommand result = commandFactories.create(sqlExpression, new DropTable(QualifiedName.of("foo"), true), Collections.emptyMap());
    assertThat(result, instanceOf(DropSourceCommand.class));
}
Also used : DropTable(io.confluent.ksql.parser.tree.DropTable) Test(org.junit.Test)

Example 2 with DropTable

use of io.confluent.ksql.parser.tree.DropTable in project ksql by confluentinc.

the class KsqlParserTest method testDrop.

@Test
public void testDrop() throws Exception {
    String simpleQuery = "DROP STREAM STREAM1; DROP TABLE TABLE1;";
    List<Statement> statements = KSQL_PARSER.buildAst(simpleQuery, metaStore);
    Statement statement0 = statements.get(0);
    Statement statement1 = statements.get(1);
    Assert.assertTrue(statement0 instanceof DropStream);
    Assert.assertTrue(statement1 instanceof DropTable);
    DropStream dropStream = (DropStream) statement0;
    DropTable dropTable = (DropTable) statement1;
    Assert.assertTrue(dropStream.getName().toString().equalsIgnoreCase("STREAM1"));
    Assert.assertTrue(dropTable.getName().toString().equalsIgnoreCase("TABLE1"));
}
Also used : Statement(io.confluent.ksql.parser.tree.Statement) DropTable(io.confluent.ksql.parser.tree.DropTable) DropStream(io.confluent.ksql.parser.tree.DropStream) Test(org.junit.Test)

Example 3 with DropTable

use of io.confluent.ksql.parser.tree.DropTable in project ksql by confluentinc.

the class KsqlEngine method buildSingleQueryAst.

private Pair<String, Statement> buildSingleQueryAst(final Statement statement, final String statementString, final MetaStore tempMetaStore, final MetaStore tempMetaStoreForParser, final Map<String, Object> overriddenProperties) {
    log.info("Building AST for {}.", statementString);
    if (statement instanceof Query) {
        return new Pair<>(statementString, statement);
    } else if (statement instanceof CreateAsSelect) {
        CreateAsSelect createAsSelect = (CreateAsSelect) statement;
        QuerySpecification querySpecification = (QuerySpecification) createAsSelect.getQuery().getQueryBody();
        Query query = addInto(createAsSelect.getQuery(), querySpecification, createAsSelect.getName().getSuffix(), createAsSelect.getProperties(), createAsSelect.getPartitionByColumn());
        tempMetaStoreForParser.putSource(queryEngine.getResultDatasource(querySpecification.getSelect(), createAsSelect.getName().getSuffix()).cloneWithTimeKeyColumns());
        return new Pair<>(statementString, query);
    } else if (statement instanceof RegisterTopic) {
        ddlCommandExec.tryExecute(new RegisterTopicCommand((RegisterTopic) statement), tempMetaStoreForParser);
        ddlCommandExec.tryExecute(new RegisterTopicCommand((RegisterTopic) statement), tempMetaStore);
        return new Pair<>(statementString, statement);
    } else if (statement instanceof CreateStream) {
        ddlCommandExec.tryExecute(new CreateStreamCommand(statementString, (CreateStream) statement, overriddenProperties, topicClient, false), tempMetaStoreForParser);
        ddlCommandExec.tryExecute(new CreateStreamCommand(statementString, (CreateStream) statement, overriddenProperties, topicClient, false), tempMetaStore);
        return new Pair<>(statementString, statement);
    } else if (statement instanceof CreateTable) {
        ddlCommandExec.tryExecute(new CreateTableCommand(statementString, (CreateTable) statement, overriddenProperties, topicClient, false), tempMetaStoreForParser);
        ddlCommandExec.tryExecute(new CreateTableCommand(statementString, (CreateTable) statement, overriddenProperties, topicClient, false), tempMetaStore);
        return new Pair<>(statementString, statement);
    } else if (statement instanceof DropStream) {
        ddlCommandExec.tryExecute(new DropSourceCommand((DropStream) statement, DataSource.DataSourceType.KSTREAM, this), tempMetaStore);
        ddlCommandExec.tryExecute(new DropSourceCommand((DropStream) statement, DataSource.DataSourceType.KSTREAM, this), tempMetaStoreForParser);
        return new Pair<>(statementString, statement);
    } else if (statement instanceof DropTable) {
        ddlCommandExec.tryExecute(new DropSourceCommand((DropTable) statement, DataSource.DataSourceType.KTABLE, this), tempMetaStore);
        ddlCommandExec.tryExecute(new DropSourceCommand((DropTable) statement, DataSource.DataSourceType.KTABLE, this), tempMetaStoreForParser);
        return new Pair<>(statementString, statement);
    } else if (statement instanceof DropTopic) {
        ddlCommandExec.tryExecute(new DropTopicCommand((DropTopic) statement), tempMetaStore);
        ddlCommandExec.tryExecute(new DropTopicCommand((DropTopic) statement), tempMetaStoreForParser);
        return new Pair<>(statementString, statement);
    } else if (statement instanceof SetProperty) {
        return new Pair<>(statementString, statement);
    }
    return null;
}
Also used : DropTopicCommand(io.confluent.ksql.ddl.commands.DropTopicCommand) Query(io.confluent.ksql.parser.tree.Query) RegisterTopic(io.confluent.ksql.parser.tree.RegisterTopic) DropSourceCommand(io.confluent.ksql.ddl.commands.DropSourceCommand) CreateTable(io.confluent.ksql.parser.tree.CreateTable) CreateStream(io.confluent.ksql.parser.tree.CreateStream) CreateAsSelect(io.confluent.ksql.parser.tree.CreateAsSelect) RegisterTopicCommand(io.confluent.ksql.ddl.commands.RegisterTopicCommand) DropTable(io.confluent.ksql.parser.tree.DropTable) CreateTableCommand(io.confluent.ksql.ddl.commands.CreateTableCommand) QuerySpecification(io.confluent.ksql.parser.tree.QuerySpecification) CreateStreamCommand(io.confluent.ksql.ddl.commands.CreateStreamCommand) DropTopic(io.confluent.ksql.parser.tree.DropTopic) DropStream(io.confluent.ksql.parser.tree.DropStream) SetProperty(io.confluent.ksql.parser.tree.SetProperty) Pair(io.confluent.ksql.util.Pair)

Aggregations

DropTable (io.confluent.ksql.parser.tree.DropTable)3 DropStream (io.confluent.ksql.parser.tree.DropStream)2 Test (org.junit.Test)2 CreateStreamCommand (io.confluent.ksql.ddl.commands.CreateStreamCommand)1 CreateTableCommand (io.confluent.ksql.ddl.commands.CreateTableCommand)1 DropSourceCommand (io.confluent.ksql.ddl.commands.DropSourceCommand)1 DropTopicCommand (io.confluent.ksql.ddl.commands.DropTopicCommand)1 RegisterTopicCommand (io.confluent.ksql.ddl.commands.RegisterTopicCommand)1 CreateAsSelect (io.confluent.ksql.parser.tree.CreateAsSelect)1 CreateStream (io.confluent.ksql.parser.tree.CreateStream)1 CreateTable (io.confluent.ksql.parser.tree.CreateTable)1 DropTopic (io.confluent.ksql.parser.tree.DropTopic)1 Query (io.confluent.ksql.parser.tree.Query)1 QuerySpecification (io.confluent.ksql.parser.tree.QuerySpecification)1 RegisterTopic (io.confluent.ksql.parser.tree.RegisterTopic)1 SetProperty (io.confluent.ksql.parser.tree.SetProperty)1 Statement (io.confluent.ksql.parser.tree.Statement)1 Pair (io.confluent.ksql.util.Pair)1