use of io.confluent.ksql.parser.tree.DdlStatement in project ksql by confluentinc.
the class StatementExecutor method executeStatement.
private void executeStatement(Statement statement, Command command, CommandId commandId, Map<QueryId, CommandId> terminatedQueries, boolean wasDropped) throws Exception {
String statementStr = command.getStatement();
DdlCommandResult result = null;
String successMessage = "";
if (statement instanceof DdlStatement) {
result = ksqlEngine.executeDdlStatement(statementStr, (DdlStatement) statement, command.getKsqlProperties());
} else if (statement instanceof CreateAsSelect) {
successMessage = handleCreateAsSelect((CreateAsSelect) statement, command, commandId, terminatedQueries, statementStr, wasDropped);
if (successMessage == null) {
return;
}
} else if (statement instanceof TerminateQuery) {
terminateQuery((TerminateQuery) statement);
successMessage = "Query terminated.";
} else if (statement instanceof RunScript) {
handleRunScript(command);
} else {
throw new Exception(String.format("Unexpected statement type: %s", statement.getClass().getName()));
}
// TODO: change to unified return message
CommandStatus successStatus = new CommandStatus(CommandStatus.Status.SUCCESS, result != null ? result.getMessage() : successMessage);
statusStore.put(commandId, successStatus);
completeStatusFuture(commandId, successStatus);
}
use of io.confluent.ksql.parser.tree.DdlStatement in project ksql by confluentinc.
the class QueryEngine method handleDdlStatement.
DdlCommandResult handleDdlStatement(String sqlExpression, DdlStatement statement, final Map<String, Object> overriddenProperties) {
if (statement instanceof AbstractStreamCreateStatement) {
AbstractStreamCreateStatement streamCreateStatement = (AbstractStreamCreateStatement) statement;
Pair<DdlStatement, String> avroCheckResult = maybeAddFieldsFromSchemaRegistry(streamCreateStatement);
if (avroCheckResult.getRight() != null) {
statement = avroCheckResult.getLeft();
sqlExpression = avroCheckResult.getRight();
}
}
DdlCommand command = ddlCommandFactory.create(sqlExpression, statement, overriddenProperties);
return ksqlEngine.getDdlCommandExec().execute(command);
}
use of io.confluent.ksql.parser.tree.DdlStatement in project ksql by confluentinc.
the class QueryEngine method buildPhysicalPlans.
List<QueryMetadata> buildPhysicalPlans(final List<Pair<String, PlanNode>> logicalPlans, final List<Pair<String, Statement>> statementList, final Map<String, Object> overriddenProperties, final boolean updateMetastore) throws Exception {
List<QueryMetadata> physicalPlans = new ArrayList<>();
for (int i = 0; i < logicalPlans.size(); i++) {
Pair<String, PlanNode> statementPlanPair = logicalPlans.get(i);
if (statementPlanPair.getRight() == null) {
Statement statement = statementList.get(i).getRight();
if (!(statement instanceof DdlStatement)) {
throw new KsqlException("expecting a statement implementing DDLStatement but got: " + statement.getClass());
}
handleDdlStatement(statementPlanPair.getLeft(), (DdlStatement) statement, overriddenProperties);
} else {
buildQueryPhysicalPlan(physicalPlans, statementPlanPair, overriddenProperties, updateMetastore);
}
}
return physicalPlans;
}
Aggregations