Search in sources :

Example 1 with DdlStatement

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);
}
Also used : DdlCommandResult(io.confluent.ksql.ddl.commands.DdlCommandResult) TerminateQuery(io.confluent.ksql.parser.tree.TerminateQuery) DdlStatement(io.confluent.ksql.parser.tree.DdlStatement) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) RunScript(io.confluent.ksql.parser.tree.RunScript) CreateAsSelect(io.confluent.ksql.parser.tree.CreateAsSelect) WakeupException(org.apache.kafka.common.errors.WakeupException) KsqlException(io.confluent.ksql.util.KsqlException)

Example 2 with DdlStatement

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);
}
Also used : DdlCommand(io.confluent.ksql.ddl.commands.DdlCommand) DdlStatement(io.confluent.ksql.parser.tree.DdlStatement) AbstractStreamCreateStatement(io.confluent.ksql.parser.tree.AbstractStreamCreateStatement)

Example 3 with DdlStatement

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;
}
Also used : QueryMetadata(io.confluent.ksql.util.QueryMetadata) PlanNode(io.confluent.ksql.planner.plan.PlanNode) DdlStatement(io.confluent.ksql.parser.tree.DdlStatement) AbstractStreamCreateStatement(io.confluent.ksql.parser.tree.AbstractStreamCreateStatement) Statement(io.confluent.ksql.parser.tree.Statement) ArrayList(java.util.ArrayList) DdlStatement(io.confluent.ksql.parser.tree.DdlStatement) KsqlException(io.confluent.ksql.util.KsqlException)

Aggregations

DdlStatement (io.confluent.ksql.parser.tree.DdlStatement)3 AbstractStreamCreateStatement (io.confluent.ksql.parser.tree.AbstractStreamCreateStatement)2 KsqlException (io.confluent.ksql.util.KsqlException)2 DdlCommand (io.confluent.ksql.ddl.commands.DdlCommand)1 DdlCommandResult (io.confluent.ksql.ddl.commands.DdlCommandResult)1 CreateAsSelect (io.confluent.ksql.parser.tree.CreateAsSelect)1 RunScript (io.confluent.ksql.parser.tree.RunScript)1 Statement (io.confluent.ksql.parser.tree.Statement)1 TerminateQuery (io.confluent.ksql.parser.tree.TerminateQuery)1 PlanNode (io.confluent.ksql.planner.plan.PlanNode)1 CommandStatus (io.confluent.ksql.rest.entity.CommandStatus)1 QueryMetadata (io.confluent.ksql.util.QueryMetadata)1 ArrayList (java.util.ArrayList)1 WakeupException (org.apache.kafka.common.errors.WakeupException)1