use of io.crate.expression.symbol.SelectSymbol in project crate by crate.
the class LogicalPlanner method tryOptimizeForInSubquery.
// In case the subselect is inside an IN() or = ANY() apply a "natural" OrderBy to optimize
// the building of TermInSetQuery which does a sort on the collection of values.
// See issue https://github.com/crate/crate/issues/6755
// If the output values are already sorted (even in desc order) no optimization is needed
private LogicalPlan tryOptimizeForInSubquery(SelectSymbol selectSymbol, AnalyzedRelation relation, LogicalPlan planBuilder) {
if (selectSymbol.getResultType() == SelectSymbol.ResultType.SINGLE_COLUMN_MULTIPLE_VALUES && relation instanceof QueriedSelectRelation) {
QueriedSelectRelation queriedRelation = (QueriedSelectRelation) relation;
OrderBy relationOrderBy = queriedRelation.orderBy();
Symbol firstOutput = queriedRelation.outputs().get(0);
if ((relationOrderBy == null || relationOrderBy.orderBySymbols().get(0).equals(firstOutput) == false) && DataTypes.isPrimitive(firstOutput.valueType())) {
return Order.create(planBuilder, new OrderBy(Collections.singletonList(firstOutput)));
}
}
return planBuilder;
}
use of io.crate.expression.symbol.SelectSymbol in project crate by crate.
the class MultiPhaseExecutor method execute.
public static CompletableFuture<SubQueryResults> execute(Map<LogicalPlan, SelectSymbol> dependencies, DependencyCarrier executor, PlannerContext plannerContext, Row params) {
List<CompletableFuture<?>> dependencyFutures = new ArrayList<>(dependencies.size());
IdentityHashMap<SelectSymbol, Object> valueBySubQuery = new IdentityHashMap<>();
for (Map.Entry<LogicalPlan, SelectSymbol> entry : dependencies.entrySet()) {
LogicalPlan depPlan = entry.getKey();
SelectSymbol selectSymbol = entry.getValue();
CollectingRowConsumer<?, ?> rowConsumer = getConsumer(selectSymbol.getResultType());
depPlan.execute(executor, PlannerContext.forSubPlan(plannerContext), rowConsumer, params, SubQueryResults.EMPTY);
dependencyFutures.add(rowConsumer.completionFuture().thenAccept(val -> {
synchronized (valueBySubQuery) {
valueBySubQuery.put(selectSymbol, val);
}
}));
}
return CompletableFuture.allOf(dependencyFutures.toArray(new CompletableFuture[0])).thenApply(ignored -> new SubQueryResults(valueBySubQuery));
}
use of io.crate.expression.symbol.SelectSymbol in project crate by crate.
the class SQLExecutor method planInternal.
private <T> T planInternal(AnalyzedStatement analyzedStatement, UUID jobId, int fetchSize, Row params) {
RoutingProvider routingProvider = new RoutingProvider(random.nextInt(), emptyList());
PlannerContext plannerContext = new PlannerContext(planner.currentClusterState(), routingProvider, jobId, coordinatorTxnCtx, nodeCtx, fetchSize, null);
Plan plan = planner.plan(analyzedStatement, plannerContext);
if (plan instanceof LogicalPlan) {
return (T) ((LogicalPlan) plan).build(plannerContext, Set.of(), new ProjectionBuilder(nodeCtx), TopN.NO_LIMIT, 0, null, null, params, new SubQueryResults(emptyMap()) {
@Override
public Object getSafe(SelectSymbol key) {
return Literal.of(key.valueType(), null);
}
});
}
return (T) plan;
}
use of io.crate.expression.symbol.SelectSymbol in project crate by crate.
the class SelectStatementAnalyzerTest method testArraySubqueryExpression.
@Test
public void testArraySubqueryExpression() throws Exception {
var executor = SQLExecutor.builder(clusterService).build();
AnalyzedRelation relation = executor.analyze("select array(select id from sys.shards) as shards_id_array from sys.shards");
SelectSymbol arrayProjection = (SelectSymbol) ((AliasSymbol) relation.outputs().get(0)).symbol();
assertThat(arrayProjection.getResultType(), is(SelectSymbol.ResultType.SINGLE_COLUMN_MULTIPLE_VALUES));
assertThat(arrayProjection.valueType().id(), is(ArrayType.ID));
}
use of io.crate.expression.symbol.SelectSymbol in project crate by crate.
the class CollectQueryCastRulesTest method assertCollectQuery.
private void assertCollectQuery(String query, String expected) {
var collect = new Collect(tr1, Collections.emptyList(), new WhereClause(e.asSymbol(query)), 100, 10);
var plan = (io.crate.planner.node.dql.Collect) collect.build(plannerContext, Set.of(), new ProjectionBuilder(e.nodeCtx), TopN.NO_LIMIT, 0, null, null, Row.EMPTY, new SubQueryResults(emptyMap()) {
@Override
public Object getSafe(SelectSymbol key) {
return Literal.of(key.valueType(), null);
}
});
assertThat(((RoutedCollectPhase) plan.collectPhase()).where().toString(), is(expected));
}
Aggregations