use of io.crate.planner.operators.Insert 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);
}
Aggregations