use of io.confluent.ksql.ddl.commands.DropSourceCommand 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;
}
use of io.confluent.ksql.ddl.commands.DropSourceCommand in project ksql by confluentinc.
the class KsqlResource method registerDdlCommandTasks.
private void registerDdlCommandTasks() {
ddlCommandTasks.put(Query.class, (statement, statementText, properties) -> ksqlEngine.getQueryExecutionPlan((Query) statement).getExecutionPlan());
ddlCommandTasks.put(CreateStreamAsSelect.class, (statement, statementText, properties) -> {
QueryMetadata queryMetadata = ksqlEngine.getQueryExecutionPlan(((CreateStreamAsSelect) statement).getQuery());
if (queryMetadata.getDataSourceType() == DataSource.DataSourceType.KTABLE) {
throw new KsqlException("Invalid result type. Your SELECT query produces a TABLE. Please " + "use CREATE TABLE AS SELECT statement instead.");
}
if (queryMetadata instanceof PersistentQueryMetadata) {
new AvroUtil().validatePersistentQueryResults((PersistentQueryMetadata) queryMetadata, ksqlEngine.getSchemaRegistryClient());
}
queryMetadata.close();
return queryMetadata.getExecutionPlan();
});
ddlCommandTasks.put(CreateTableAsSelect.class, (statement, statementText, properties) -> {
QueryMetadata queryMetadata = ksqlEngine.getQueryExecutionPlan(((CreateTableAsSelect) statement).getQuery());
if (queryMetadata.getDataSourceType() != DataSource.DataSourceType.KTABLE) {
throw new KsqlException("Invalid result type. Your SELECT query produces a STREAM. Please " + "use CREATE STREAM AS SELECT statement instead.");
}
if (queryMetadata instanceof PersistentQueryMetadata) {
new AvroUtil().validatePersistentQueryResults((PersistentQueryMetadata) queryMetadata, ksqlEngine.getSchemaRegistryClient());
}
queryMetadata.close();
return queryMetadata.getExecutionPlan();
});
ddlCommandTasks.put(RegisterTopic.class, (statement, statementText, properties) -> {
RegisterTopicCommand registerTopicCommand = new RegisterTopicCommand((RegisterTopic) statement);
new DdlCommandExec(ksqlEngine.getMetaStore().clone()).execute(registerTopicCommand);
return statement.toString();
});
ddlCommandTasks.put(CreateStream.class, (statement, statementText, properties) -> {
CreateStreamCommand createStreamCommand = new CreateStreamCommand(statementText, (CreateStream) statement, properties, ksqlEngine.getTopicClient(), true);
executeDdlCommand(createStreamCommand);
return statement.toString();
});
ddlCommandTasks.put(CreateTable.class, (statement, statementText, properties) -> {
CreateTableCommand createTableCommand = new CreateTableCommand(statementText, (CreateTable) statement, properties, ksqlEngine.getTopicClient(), true);
executeDdlCommand(createTableCommand);
return statement.toString();
});
ddlCommandTasks.put(DropTopic.class, (statement, statementText, properties) -> {
DropTopicCommand dropTopicCommand = new DropTopicCommand((DropTopic) statement);
new DdlCommandExec(ksqlEngine.getMetaStore().clone()).execute(dropTopicCommand);
return statement.toString();
});
ddlCommandTasks.put(DropStream.class, (statement, statementText, properties) -> {
DropSourceCommand dropSourceCommand = new DropSourceCommand((DropStream) statement, DataSource.DataSourceType.KSTREAM, ksqlEngine);
executeDdlCommand(dropSourceCommand);
return statement.toString();
});
ddlCommandTasks.put(DropTable.class, (statement, statementText, properties) -> {
DropSourceCommand dropSourceCommand = new DropSourceCommand((DropTable) statement, DataSource.DataSourceType.KTABLE, ksqlEngine);
executeDdlCommand(dropSourceCommand);
return statement.toString();
});
ddlCommandTasks.put(TerminateQuery.class, (statement, statementText, properties) -> statement.toString());
}
Aggregations