Search in sources :

Example 1 with ParameterContext

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

the class SimplePortal method bind.

@Override
public Portal bind(String statementName, String query, Statement statement, List<Object> params, @Nullable FormatCodes.FormatCode[] resultFormatCodes) {
    if (statement.equals(this.statement)) {
        if (portalContext.isReadOnly()) {
            // Cannot have a bulk operation in read only mode
            throw new ReadOnlyException();
        }
        assert consumer == null : "Existing portal must not have a consumer";
        BulkPortal portal = new BulkPortal(name, this.query, this.statement, outputTypes, fields(), resultReceiver, maxRows, this.params, sessionContext, portalContext);
        return portal.bind(statementName, query, statement, params, resultFormatCodes);
    } else if (this.statement != null) {
        assert consumer == null : "Existing portal must not have a consumer";
        if (portalContext.isReadOnly()) {
            // Cannot have a batch operation in read only mode
            throw new ReadOnlyException();
        }
        BatchPortal portal = new BatchPortal(name, this.query, analysis, outputTypes, resultReceiver, this.params, sessionContext, portalContext);
        return portal.bind(statementName, query, statement, params, resultFormatCodes);
    }
    this.query = query;
    this.statement = statement;
    this.params = params;
    this.rowParams = new RowN(params.toArray());
    this.resultFormatCodes = resultFormatCodes;
    if (analysis == null) {
        analysis = portalContext.getAnalyzer().boundAnalyze(statement, sessionContext, new ParameterContext(this.rowParams, Collections.<Row>emptyList()));
        AnalyzedRelation rootRelation = analysis.rootRelation();
        if (rootRelation != null) {
            this.outputTypes = new ArrayList<>(Symbols.extractTypes(rootRelation.fields()));
        }
    }
    return this;
}
Also used : RowN(io.crate.data.RowN) ParameterContext(io.crate.analyze.ParameterContext) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) ReadOnlyException(io.crate.exceptions.ReadOnlyException)

Example 2 with ParameterContext

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

the class SQLTransportIntegrationTest method plan.

public PlanForNode plan(String stmt) {
    String[] nodeNames = internalCluster().getNodeNames();
    String nodeName = nodeNames[randomIntBetween(1, nodeNames.length) - 1];
    Analyzer analyzer = internalCluster().getInstance(Analyzer.class, nodeName);
    Planner planner = internalCluster().getInstance(Planner.class, nodeName);
    ParameterContext parameterContext = new ParameterContext(Row.EMPTY, Collections.<Row>emptyList());
    Plan plan = planner.plan(analyzer.boundAnalyze(SqlParser.createStatement(stmt), SessionContext.SYSTEM_SESSION, parameterContext), UUID.randomUUID(), 0, 0);
    return new PlanForNode(plan, nodeName);
}
Also used : Planner(io.crate.planner.Planner) ParameterContext(io.crate.analyze.ParameterContext) Analyzer(io.crate.analyze.Analyzer) Plan(io.crate.planner.Plan)

Example 3 with ParameterContext

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

the class BulkPortal method sync.

@Override
public CompletableFuture<?> sync(Planner planner, JobsLogs jobsLogs) {
    List<Row> bulkParams = Rows.of(bulkArgs);
    Analysis analysis = portalContext.getAnalyzer().boundAnalyze(statement, sessionContext, new ParameterContext(Row.EMPTY, bulkParams));
    UUID jobId = UUID.randomUUID();
    Plan plan;
    try {
        plan = planner.plan(analysis, jobId, 0, maxRows);
    } catch (Throwable t) {
        jobsLogs.logPreExecutionFailure(jobId, query, SQLExceptions.messageOf(t));
        throw t;
    }
    jobsLogs.logExecutionStart(jobId, query);
    synced = true;
    return executeBulk(portalContext.getExecutor(), plan, jobId, jobsLogs);
}
Also used : Analysis(io.crate.analyze.Analysis) ParameterContext(io.crate.analyze.ParameterContext) Row(io.crate.data.Row) UUID(java.util.UUID) Plan(io.crate.planner.Plan)

Aggregations

ParameterContext (io.crate.analyze.ParameterContext)3 Plan (io.crate.planner.Plan)2 Analysis (io.crate.analyze.Analysis)1 Analyzer (io.crate.analyze.Analyzer)1 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)1 Row (io.crate.data.Row)1 RowN (io.crate.data.RowN)1 ReadOnlyException (io.crate.exceptions.ReadOnlyException)1 Planner (io.crate.planner.Planner)1 UUID (java.util.UUID)1