Search in sources :

Example 1 with ParamTypeHints

use of io.crate.analyze.ParamTypeHints in project crate by crate.

the class CreateViewPlan method ensureFormattedQueryCanStillBeAnalyzed.

private static void ensureFormattedQueryCanStillBeAnalyzed(RelationName viewName, NodeContext nodeCtx, Schemas schemas, CoordinatorTxnCtx txnCtx, String formattedQuery, boolean replaceExisting) {
    RelationAnalyzer analyzer = new RelationAnalyzer(nodeCtx, schemas);
    Query query = (Query) SqlParser.createStatement(formattedQuery);
    if (replaceExisting) {
        new EnsureNoSelfReference(viewName, txnCtx.sessionContext().searchPath()).raiseOnSelfReference(query);
    }
    analyzer.analyze(query, txnCtx, new ParamTypeHints(List.of()) {

        @Override
        public Symbol apply(@Nullable ParameterExpression input) {
            throw new UnsupportedOperationException("View definition must not contain any parameter placeholders");
        }
    });
}
Also used : Query(io.crate.sql.tree.Query) RelationAnalyzer(io.crate.analyze.relations.RelationAnalyzer) Symbol(io.crate.expression.symbol.Symbol) ParameterExpression(io.crate.sql.tree.ParameterExpression) ParamTypeHints(io.crate.analyze.ParamTypeHints)

Example 2 with ParamTypeHints

use of io.crate.analyze.ParamTypeHints in project crate by crate.

the class Session method analyze.

public void analyze(String statementName, Statement statement, List<DataType> paramTypes, @Nullable String query) {
    AnalyzedStatement analyzedStatement;
    DataType[] parameterTypes;
    try {
        analyzedStatement = analyzer.analyze(statement, sessionContext, new ParamTypeHints(paramTypes));
        parameterTypes = parameterTypeExtractor.getParameterTypes(x -> Relations.traverseDeepSymbols(analyzedStatement, x));
    } catch (Throwable t) {
        jobsLogs.logPreExecutionFailure(UUIDs.dirtyUUID(), query == null ? statementName : query, SQLExceptions.messageOf(t), sessionContext.sessionUser());
        throw t;
    }
    preparedStatements.put(statementName, new PreparedStmt(statement, analyzedStatement, query, parameterTypes));
}
Also used : ParamTypeHints(io.crate.analyze.ParamTypeHints) RetryOnFailureResultReceiver(io.crate.protocols.postgres.RetryOnFailureResultReceiver) Analyzer(io.crate.analyze.Analyzer) DependencyCarrier(io.crate.planner.DependencyCarrier) ClusterState(org.elasticsearch.cluster.ClusterState) Relations(io.crate.analyze.Relations) RowN(io.crate.data.RowN) TransactionState(io.crate.protocols.postgres.TransactionState) Map(java.util.Map) JobsLogsUpdateListener(io.crate.protocols.postgres.JobsLogsUpdateListener) TableInfo(io.crate.metadata.table.TableInfo) NodeContext(io.crate.metadata.NodeContext) AnalyzedStatement(io.crate.analyze.AnalyzedStatement) UUIDs(org.elasticsearch.common.UUIDs) UUID(java.util.UUID) Lists2(io.crate.common.collections.Lists2) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AnalyzedDiscard(io.crate.analyze.AnalyzedDiscard) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) AnalyzedBegin(io.crate.analyze.AnalyzedBegin) SubQueryResults(io.crate.planner.operators.SubQueryResults) Statement(io.crate.sql.tree.Statement) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) AnalyzedCommit(io.crate.analyze.AnalyzedCommit) AccessControl(io.crate.auth.AccessControl) QueriedSelectRelation(io.crate.analyze.QueriedSelectRelation) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Portal(io.crate.protocols.postgres.Portal) Symbols(io.crate.expression.symbol.Symbols) FormatCodes(io.crate.protocols.postgres.FormatCodes) SqlParser(io.crate.sql.parser.SqlParser) Nullable(javax.annotation.Nullable) Iterator(java.util.Iterator) RelationInfo(io.crate.metadata.RelationInfo) Target(io.crate.sql.tree.DiscardStatement.Target) DataType(io.crate.types.DataType) Planner(io.crate.planner.Planner) RoutingProvider(io.crate.metadata.RoutingProvider) RowConsumer(io.crate.data.RowConsumer) StatementClassifier(io.crate.planner.operators.StatementClassifier) AbstractTableRelation(io.crate.analyze.relations.AbstractTableRelation) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) ReadOnlyException(io.crate.exceptions.ReadOnlyException) SQLExceptions(io.crate.exceptions.SQLExceptions) LogManager(org.apache.logging.log4j.LogManager) Randomness(org.elasticsearch.common.Randomness) AnalyzedDeallocate(io.crate.analyze.AnalyzedDeallocate) DataType(io.crate.types.DataType) AnalyzedStatement(io.crate.analyze.AnalyzedStatement) ParamTypeHints(io.crate.analyze.ParamTypeHints)

Aggregations

ParamTypeHints (io.crate.analyze.ParamTypeHints)2 Symbol (io.crate.expression.symbol.Symbol)2 AnalyzedBegin (io.crate.analyze.AnalyzedBegin)1 AnalyzedCommit (io.crate.analyze.AnalyzedCommit)1 AnalyzedDeallocate (io.crate.analyze.AnalyzedDeallocate)1 AnalyzedDiscard (io.crate.analyze.AnalyzedDiscard)1 AnalyzedStatement (io.crate.analyze.AnalyzedStatement)1 Analyzer (io.crate.analyze.Analyzer)1 QueriedSelectRelation (io.crate.analyze.QueriedSelectRelation)1 Relations (io.crate.analyze.Relations)1 AbstractTableRelation (io.crate.analyze.relations.AbstractTableRelation)1 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)1 RelationAnalyzer (io.crate.analyze.relations.RelationAnalyzer)1 AccessControl (io.crate.auth.AccessControl)1 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)1 Lists2 (io.crate.common.collections.Lists2)1 Row (io.crate.data.Row)1 Row1 (io.crate.data.Row1)1 RowConsumer (io.crate.data.RowConsumer)1 RowN (io.crate.data.RowN)1