use of io.crate.analyze.relations.ExcludedFieldProvider in project crate by crate.
the class InsertAnalyzer method getUpdateAssignments.
private static Map<Reference, Symbol> getUpdateAssignments(DocTableRelation targetTable, List<Reference> targetCols, ExpressionAnalyzer exprAnalyzer, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, ParamTypeHints paramTypeHints, Insert.DuplicateKeyContext<Expression> duplicateKeyContext) {
if (duplicateKeyContext.getAssignments().isEmpty()) {
return Collections.emptyMap();
}
ExpressionAnalysisContext exprCtx = new ExpressionAnalysisContext(txnCtx.sessionContext());
ValuesResolver valuesResolver = new ValuesResolver(targetCols);
final FieldProvider<?> fieldProvider;
if (duplicateKeyContext.getType() == Insert.DuplicateKeyContext.Type.ON_CONFLICT_DO_UPDATE_SET) {
fieldProvider = new ExcludedFieldProvider(new NameFieldProvider(targetTable), valuesResolver);
} else {
fieldProvider = new NameFieldProvider(targetTable);
}
var expressionAnalyzer = new ExpressionAnalyzer(txnCtx, nodeCtx, paramTypeHints, fieldProvider, null);
var normalizer = new EvaluatingNormalizer(nodeCtx, RowGranularity.CLUSTER, null, targetTable);
Map<Reference, Symbol> updateAssignments = new HashMap<>(duplicateKeyContext.getAssignments().size());
for (Assignment<Expression> assignment : duplicateKeyContext.getAssignments()) {
Reference targetCol = (Reference) exprAnalyzer.convert(assignment.columnName(), exprCtx);
Symbol valueSymbol = ValueNormalizer.normalizeInputForReference(normalizer.normalize(expressionAnalyzer.convert(assignment.expression(), exprCtx), txnCtx), targetCol, targetTable.tableInfo(), s -> normalizer.normalize(s, txnCtx));
updateAssignments.put(targetCol, valueSymbol);
}
return updateAssignments;
}
Aggregations