Search in sources :

Example 1 with Insert

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);
}
Also used : InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) Reference(io.crate.metadata.Reference) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) Insert(io.crate.planner.operators.Insert) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) InputColumn(io.crate.expression.symbol.InputColumn) LogicalPlan(io.crate.planner.operators.LogicalPlan)

Aggregations

UnsupportedFeatureException (io.crate.exceptions.UnsupportedFeatureException)1 ColumnIndexWriterProjection (io.crate.execution.dsl.projection.ColumnIndexWriterProjection)1 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)1 InputColumns (io.crate.execution.dsl.projection.builder.InputColumns)1 InputColumn (io.crate.expression.symbol.InputColumn)1 Symbol (io.crate.expression.symbol.Symbol)1 Reference (io.crate.metadata.Reference)1 Insert (io.crate.planner.operators.Insert)1 LogicalPlan (io.crate.planner.operators.LogicalPlan)1 ArrayList (java.util.ArrayList)1