use of io.crate.analyze.relations.AnalyzedRelation 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.relations.AnalyzedRelation in project crate by crate.
the class SubqueryPlanner method planSubquery.
private void planSubquery(SelectSymbol selectSymbol) {
AnalyzedRelation relation = selectSymbol.relation();
SelectAnalyzedStatement selectAnalyzedStatement = new SelectAnalyzedStatement(((QueriedRelation) relation));
Plan subPlan = plannerContext.planSingleRowSubselect(selectAnalyzedStatement);
subQueries.put(subPlan, selectSymbol);
}
use of io.crate.analyze.relations.AnalyzedRelation in project crate by crate.
the class InternalCountOperationTest method testCount.
@Test
public void testCount() throws Exception {
execute("create table t (name string) clustered into 1 shards with (number_of_replicas = 0)");
ensureYellow();
execute("insert into t (name) values ('Marvin'), ('Arthur'), ('Trillian')");
execute("refresh table t");
CountOperation countOperation = internalCluster().getDataNodeInstance(CountOperation.class);
assertThat(countOperation.count("t", 0, WhereClause.MATCH_ALL), is(3L));
Schemas schemas = internalCluster().getInstance(Schemas.class);
TableInfo tableInfo = schemas.getTableInfo(new TableIdent(null, "t"));
TableRelation tableRelation = new TableRelation(tableInfo);
Map<QualifiedName, AnalyzedRelation> tableSources = ImmutableMap.<QualifiedName, AnalyzedRelation>of(new QualifiedName(tableInfo.ident().name()), tableRelation);
SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation);
WhereClause whereClause = new WhereClause(sqlExpressions.normalize(sqlExpressions.asSymbol("name = 'Marvin'")));
assertThat(countOperation.count("t", 0, whereClause), is(1L));
}
Aggregations