From cb9eec50c7e84e3c4bbeab6f419cd86d1d30be1d Mon Sep 17 00:00:00 2001 From: Matus Faro Date: Fri, 29 Nov 2024 20:24:29 -0500 Subject: [PATCH] Fix multiple field mappings conflict with each other, replacing own value --- .../io/dataspray/singletable/ExpressionBuilder.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/single-table/src/main/java/io/dataspray/singletable/ExpressionBuilder.java b/single-table/src/main/java/io/dataspray/singletable/ExpressionBuilder.java index 09c5023..2660eae 100644 --- a/single-table/src/main/java/io/dataspray/singletable/ExpressionBuilder.java +++ b/single-table/src/main/java/io/dataspray/singletable/ExpressionBuilder.java @@ -210,9 +210,7 @@ public P delete(String fieldName, Object object) { @Override public String fieldMapping(String fieldName) { - String mappedName = "#" + sanitizeFieldMapping(fieldName); - nameMap.put(mappedName, fieldName); - return mappedName; + return fieldMapping(fieldName, fieldName); } @Override @@ -225,6 +223,9 @@ public String fieldMapping(ImmutableList fieldPath) { @Override public String fieldMapping(String fieldName, String fieldValue) { String mappedName = "#" + sanitizeFieldMapping(fieldName); + while (nameMap.containsKey(mappedName) && !nameMap.get(mappedName).equals(fieldName)) { + mappedName = mappedName + "_"; + } nameMap.put(mappedName, fieldValue); return mappedName; } @@ -238,6 +239,9 @@ public String valueMapping(String fieldName, Object object) { public String constantMapping(String name, Object object) { String mappedName = ":" + sanitizeFieldMapping(name); AttributeValue value = schema.toAttrValue(object); + while (valMap.containsKey(mappedName) && !valMap.get(mappedName).equals(value)) { + mappedName = mappedName + "_"; + } valMap.put(mappedName, value); return mappedName; }