Search in sources :

Example 1 with CreateViewRequest

use of io.crate.execution.ddl.views.CreateViewRequest in project crate by crate.

the class CreateViewPlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    User owner = createViewStmt.owner();
    String formattedQuery = SqlFormatter.formatSql(createViewStmt.query(), makeExpressions(params));
    ensureFormattedQueryCanStillBeAnalyzed(createViewStmt.name(), dependencies.nodeContext(), dependencies.schemas(), plannerContext.transactionContext(), formattedQuery, createViewStmt.replaceExisting());
    CreateViewRequest request = new CreateViewRequest(createViewStmt.name(), formattedQuery, createViewStmt.replaceExisting(), owner == null ? null : owner.name());
    dependencies.createViewAction().execute(request, new OneRowActionListener<>(consumer, resp -> {
        if (resp.alreadyExistsFailure()) {
            throw new RelationAlreadyExists(createViewStmt.name());
        }
        return new Row1(1L);
    }));
}
Also used : ParamTypeHints(io.crate.analyze.ParamTypeHints) Literal(io.crate.sql.tree.Literal) RelationName(io.crate.metadata.RelationName) SearchPath(io.crate.metadata.SearchPath) DefaultTraversalVisitor(io.crate.sql.tree.DefaultTraversalVisitor) ArrayList(java.util.ArrayList) CreateViewStmt(io.crate.analyze.CreateViewStmt) SqlParser(io.crate.sql.parser.SqlParser) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Query(io.crate.sql.tree.Query) Nullable(javax.annotation.Nullable) NodeContext(io.crate.metadata.NodeContext) ParameterExpression(io.crate.sql.tree.ParameterExpression) User(io.crate.user.User) CreateViewRequest(io.crate.execution.ddl.views.CreateViewRequest) SqlFormatter(io.crate.sql.SqlFormatter) Table(io.crate.sql.tree.Table) RowConsumer(io.crate.data.RowConsumer) List(java.util.List) Row(io.crate.data.Row) RelationAlreadyExists(io.crate.exceptions.RelationAlreadyExists) Symbol(io.crate.expression.symbol.Symbol) RelationAnalyzer(io.crate.analyze.relations.RelationAnalyzer) SubQueryResults(io.crate.planner.operators.SubQueryResults) Schemas(io.crate.metadata.Schemas) Expression(io.crate.sql.tree.Expression) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Row1(io.crate.data.Row1) User(io.crate.user.User) RelationAlreadyExists(io.crate.exceptions.RelationAlreadyExists) CreateViewRequest(io.crate.execution.ddl.views.CreateViewRequest)

Aggregations

CreateViewStmt (io.crate.analyze.CreateViewStmt)1 ParamTypeHints (io.crate.analyze.ParamTypeHints)1 RelationAnalyzer (io.crate.analyze.relations.RelationAnalyzer)1 Row (io.crate.data.Row)1 Row1 (io.crate.data.Row1)1 RowConsumer (io.crate.data.RowConsumer)1 RelationAlreadyExists (io.crate.exceptions.RelationAlreadyExists)1 CreateViewRequest (io.crate.execution.ddl.views.CreateViewRequest)1 OneRowActionListener (io.crate.execution.support.OneRowActionListener)1 Symbol (io.crate.expression.symbol.Symbol)1 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)1 NodeContext (io.crate.metadata.NodeContext)1 RelationName (io.crate.metadata.RelationName)1 Schemas (io.crate.metadata.Schemas)1 SearchPath (io.crate.metadata.SearchPath)1 SubQueryResults (io.crate.planner.operators.SubQueryResults)1 SqlFormatter (io.crate.sql.SqlFormatter)1 SqlParser (io.crate.sql.parser.SqlParser)1 DefaultTraversalVisitor (io.crate.sql.tree.DefaultTraversalVisitor)1 Expression (io.crate.sql.tree.Expression)1