use of io.crate.execution.dml.SysUpdateResultSetProjector 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());
}
}
Aggregations