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;
}
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);
}
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);
}
Aggregations