From f777787ea4060021401fd012720f770b32664e99 Mon Sep 17 00:00:00 2001 From: huy Date: Wed, 10 Oct 2018 16:23:29 +0700 Subject: [PATCH] PLT-10915: merge fields / columns matching should be case insensitive --- .../output/mailchimp/MailChimpRecordBuffer.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/embulk/output/mailchimp/MailChimpRecordBuffer.java b/src/main/java/org/embulk/output/mailchimp/MailChimpRecordBuffer.java index 3b82233..3cad94b 100644 --- a/src/main/java/org/embulk/output/mailchimp/MailChimpRecordBuffer.java +++ b/src/main/java/org/embulk/output/mailchimp/MailChimpRecordBuffer.java @@ -208,17 +208,20 @@ public JsonNode apply(JsonNode input) // Update additional merge fields if exist if (task.getMergeFields().isPresent() && !task.getMergeFields().get().isEmpty()) { - Map columnNameLookup = new TreeMap<>(CASE_INSENSITIVE_ORDER); + Map columnNameCaseInsensitiveLookup = new TreeMap<>(CASE_INSENSITIVE_ORDER); for (Column col : schema.getColumns()) { - columnNameLookup.put(col.getName(), col.getName()); + columnNameCaseInsensitiveLookup.put(col.getName(), col.getName()); } + Map availableMergeFieldsCaseInsensitiveLookup = new TreeMap<>(CASE_INSENSITIVE_ORDER); + availableMergeFieldsCaseInsensitiveLookup.putAll(availableMergeFields); + for (String field : task.getMergeFields().get()) { - if (!columnNameLookup.containsKey(field)) { + if (!columnNameCaseInsensitiveLookup.containsKey(field)) { LOG.warn(format("Field '%s' is configured on data transfer but cannot be found on any columns.", field)); continue; } - String columnName = columnNameLookup.get(field); - if (!availableMergeFields.containsKey(columnName.toLowerCase())) { + String columnName = columnNameCaseInsensitiveLookup.get(field); + if (!availableMergeFieldsCaseInsensitiveLookup.containsKey(columnName)) { LOG.warn(format("Field '%s' is configured on data transfer but is not predefined on Mailchimp.", field)); continue; } @@ -226,8 +229,7 @@ public JsonNode apply(JsonNode input) String value = input.hasNonNull(columnName) ? input.findValue(columnName).asText() : ""; // Try to convert to Json from string with the merge field's type is address - if (availableMergeFields.get(columnName).getType() - .equals(MergeField.MergeFieldType.ADDRESS.getType())) { + if (availableMergeFieldsCaseInsensitiveLookup.get(columnName).getType().equals(MergeField.MergeFieldType.ADDRESS.getType())) { JsonNode addressNode = toJsonNode(value); if (addressNode instanceof NullNode) { mergeFields.put(columnName.toUpperCase(), value);