use of io.crate.planner.operators.LogicalPlan in project crate by crate.
the class FilterOnJoinsUtil method moveQueryBelowJoin.
static LogicalPlan moveQueryBelowJoin(Symbol query, LogicalPlan join) {
if (!WhereClause.canMatch(query)) {
return join.replaceSources(List.of(getNewSource(query, join.sources().get(0)), getNewSource(query, join.sources().get(1))));
}
Map<Set<RelationName>, Symbol> splitQuery = QuerySplitter.split(query);
int initialParts = splitQuery.size();
if (splitQuery.size() == 1 && splitQuery.keySet().iterator().next().size() > 1) {
return null;
}
assert join.sources().size() == 2 : "Join operator must only have 2 children, LHS and RHS";
LogicalPlan lhs = join.sources().get(0);
LogicalPlan rhs = join.sources().get(1);
Set<RelationName> leftName = lhs.getRelationNames();
Set<RelationName> rightName = rhs.getRelationNames();
Symbol queryForLhs = splitQuery.remove(leftName);
Symbol queryForRhs = splitQuery.remove(rightName);
LogicalPlan newLhs = getNewSource(queryForLhs, lhs);
LogicalPlan newRhs = getNewSource(queryForRhs, rhs);
LogicalPlan newJoin = join.replaceSources(List.of(newLhs, newRhs));
if (splitQuery.isEmpty()) {
return newJoin;
} else if (initialParts == splitQuery.size()) {
return null;
} else {
return new Filter(newJoin, AndOperator.join(splitQuery.values()));
}
}
use of io.crate.planner.operators.LogicalPlan in project crate by crate.
the class MoveOrderBeneathUnion method apply.
@Override
public LogicalPlan apply(Order order, Captures captures, TableStats tableStats, TransactionContext txnCtx, NodeContext nodeCtx) {
Union union = captures.get(unionCapture);
List<LogicalPlan> unionSources = union.sources();
assert unionSources.size() == 2 : "A UNION must have exactly 2 unionSources";
Order lhsOrder = updateSources(order, unionSources.get(0));
Order rhsOrder = updateSources(order, unionSources.get(1));
return union.replaceSources(List.of(lhsOrder, rhsOrder));
}
use of io.crate.planner.operators.LogicalPlan in project crate by crate.
the class SubqueryPlanner method planSubquery.
private void planSubquery(SelectSymbol selectSymbol, Map<LogicalPlan, SelectSymbol> subQueries) {
LogicalPlan subPlan = planSubSelects.apply(selectSymbol);
subQueries.put(subPlan, selectSymbol);
}
use of io.crate.planner.operators.LogicalPlan in project crate by crate.
the class InsertFromSubQueryPlanner method plan.
public static LogicalPlan plan(AnalyzedInsertStatement statement, PlannerContext plannerContext, LogicalPlanner logicalPlanner, SubqueryPlanner subqueryPlanner) {
if (statement.outputs() != null && !plannerContext.clusterState().getNodes().getMinNodeVersion().onOrAfter(Version.V_4_2_0)) {
throw new UnsupportedFeatureException(RETURNING_VERSION_ERROR_MSG);
}
List<Reference> targetColsExclPartitionCols = new ArrayList<>(statement.columns().size() - statement.tableInfo().partitionedBy().size());
for (Reference column : statement.columns()) {
if (statement.tableInfo().partitionedBy().contains(column.column())) {
continue;
}
targetColsExclPartitionCols.add(column);
}
List<Symbol> columnSymbols = InputColumns.create(targetColsExclPartitionCols, new InputColumns.SourceSymbols(statement.columns()));
// if fields are null default to number of rows imported
var outputs = statement.outputs() == null ? List.of(new InputColumn(0, DataTypes.LONG)) : statement.outputs();
ColumnIndexWriterProjection indexWriterProjection = new ColumnIndexWriterProjection(statement.tableInfo().ident(), null, statement.tableInfo().primaryKey(), statement.columns(), targetColsExclPartitionCols, columnSymbols, statement.isIgnoreDuplicateKeys(), statement.onDuplicateKeyAssignments(), statement.primaryKeySymbols(), statement.partitionedBySymbols(), statement.tableInfo().clusteredBy(), statement.clusteredBySymbol(), Settings.EMPTY, statement.tableInfo().isPartitioned(), outputs, statement.outputs() == null ? List.of() : statement.outputs());
LogicalPlan plannedSubQuery = logicalPlanner.plan(statement.subQueryRelation(), plannerContext, subqueryPlanner, true);
EvalProjection castOutputs = EvalProjection.castValues(Symbols.typeView(statement.columns()), plannedSubQuery.outputs());
return new Insert(plannedSubQuery, indexWriterProjection, castOutputs);
}
use of io.crate.planner.operators.LogicalPlan in project crate by crate.
the class MoveFilterBeneathWindowAggTest method test_filter_containing_columns_not_part_of_the_window_partition_cannot_be_moved.
@Test
public void test_filter_containing_columns_not_part_of_the_window_partition_cannot_be_moved() {
var collect = e.logicalPlan("SELECT id, x FROM t1");
WindowFunction windowFunction = (WindowFunction) e.asSymbol("ROW_NUMBER() OVER(PARTITION by id)");
WindowAgg windowAgg = (WindowAgg) WindowAgg.create(collect, List.of(windowFunction));
Symbol query = e.asSymbol("x = 1");
Filter filter = new Filter(windowAgg, query);
var rule = new MoveFilterBeneathWindowAgg();
Match<Filter> match = rule.pattern().accept(filter, Captures.empty());
assertThat(match.isPresent(), is(true));
assertThat(match.value(), Matchers.sameInstance(filter));
LogicalPlan newPlan = rule.apply(match.value(), match.captures(), new TableStats(), CoordinatorTxnCtx.systemTransactionContext(), e.nodeCtx);
assertThat(newPlan, nullValue());
}
Aggregations