Search in sources :

Example 1 with SysUpdateProjector

use of io.crate.execution.dml.SysUpdateProjector in project crate by crate.

the class ProjectionToProjectorVisitor method visitSysUpdateProjection.

@Override
public Projector visitSysUpdateProjection(SysUpdateProjection projection, Context context) {
    Map<Reference, Symbol> assignments = projection.assignments();
    assert !assignments.isEmpty() : "at least one assignment is required";
    List<Input<?>> valueInputs = new ArrayList<>(assignments.size());
    List<ColumnIdent> assignmentCols = new ArrayList<>(assignments.size());
    RelationName relationName = null;
    InputFactory.Context<NestableCollectExpression<?, ?>> readCtx = null;
    for (Map.Entry<Reference, Symbol> e : assignments.entrySet()) {
        Reference ref = e.getKey();
        assert relationName == null || relationName.equals(ref.ident().tableIdent()) : "mixed table assignments found";
        relationName = ref.ident().tableIdent();
        if (readCtx == null) {
            StaticTableDefinition<?> tableDefinition = staticTableDefinitionGetter.apply(relationName);
            readCtx = inputFactory.ctxForRefs(context.txnCtx, tableDefinition.getReferenceResolver());
        }
        assignmentCols.add(ref.column());
        Input<?> sourceInput = readCtx.add(e.getValue());
        valueInputs.add(sourceInput);
    }
    SysRowUpdater<?> rowUpdater = sysUpdaterGetter.apply(relationName);
    assert readCtx != null : "readCtx must not be null";
    assert rowUpdater != null : "row updater needs to exist";
    Consumer<Object> rowWriter = rowUpdater.newRowWriter(assignmentCols, valueInputs, readCtx.expressions());
    if (projection.returnValues() == null) {
        return new SysUpdateProjector(rowWriter);
    } else {
        InputFactory.Context<NestableCollectExpression<SysNodeCheck, ?>> cntx = new InputFactory(nodeCtx).ctxForRefs(context.txnCtx, new StaticTableReferenceResolver<>(SysNodeChecksTableInfo.create().expressions()));
        cntx.add(List.of(projection.returnValues()));
        return new SysUpdateResultSetProjector(rowUpdater, rowWriter, cntx.expressions(), cntx.topLevelInputs());
    }
}
Also used : InputFactory(io.crate.expression.InputFactory) Reference(io.crate.metadata.Reference) Symbol(io.crate.expression.symbol.Symbol) NestableCollectExpression(io.crate.execution.engine.collect.NestableCollectExpression) ArrayList(java.util.ArrayList) ColumnIdent(io.crate.metadata.ColumnIdent) Input(io.crate.data.Input) SysUpdateProjector(io.crate.execution.dml.SysUpdateProjector) SysUpdateResultSetProjector(io.crate.execution.dml.SysUpdateResultSetProjector) RelationName(io.crate.metadata.RelationName) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Input (io.crate.data.Input)1 SysUpdateProjector (io.crate.execution.dml.SysUpdateProjector)1 SysUpdateResultSetProjector (io.crate.execution.dml.SysUpdateResultSetProjector)1 NestableCollectExpression (io.crate.execution.engine.collect.NestableCollectExpression)1 InputFactory (io.crate.expression.InputFactory)1 Symbol (io.crate.expression.symbol.Symbol)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 Reference (io.crate.metadata.Reference)1 RelationName (io.crate.metadata.RelationName)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1