From 3685ae7f1d36821952e78245277db03f128ceb69 Mon Sep 17 00:00:00 2001 From: yuye-aws Date: Mon, 26 Feb 2024 19:12:59 +0800 Subject: [PATCH] bug fix for map type Signed-off-by: yuye-aws --- .../processor/DocumentChunkingProcessor.java | 33 +++++++++---------- .../DocumentChunkingProcessorTests.java | 2 ++ 2 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 src/test/java/org/opensearch/neuralsearch/processor/DocumentChunkingProcessorTests.java diff --git a/src/main/java/org/opensearch/neuralsearch/processor/DocumentChunkingProcessor.java b/src/main/java/org/opensearch/neuralsearch/processor/DocumentChunkingProcessor.java index 95e3a0084..e0575e2b9 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/DocumentChunkingProcessor.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/DocumentChunkingProcessor.java @@ -129,6 +129,7 @@ private void validateDocumentChunkingFieldMap(Map fieldMap) { private void validateContent(Object content, String inputField) { // content can be a map, a list of strings or a list if (content instanceof Map) { + System.out.println("map type"); @SuppressWarnings("unchecked") Map contentMap = (Map) content; for (Map.Entry contentEntry : contentMap.entrySet()) { @@ -137,32 +138,31 @@ private void validateContent(Object content, String inputField) { // the map value can also be a map, list or string validateContent(contentValue, inputField + "." + contentKey); } - } - if (content instanceof List) { + } else if (content instanceof List) { List contentList = (List) content; for (Object contentElement : contentList) { if (!(contentElement instanceof String)) { throw new IllegalArgumentException( - "some element in input field list [" - + inputField - + "] of type [" - + contentElement.getClass().getName() - + "] cannot be cast to [" - + String.class.getName() - + "]" + "some element in input field list [" + + inputField + + "] of type [" + + contentElement.getClass().getName() + + "] cannot be cast to [" + + String.class.getName() + + "]" ); } } } if (!(content instanceof String)) { throw new IllegalArgumentException( - "input field [" - + inputField - + "] of type [" - + content.getClass().getName() - + "] cannot be cast to [" - + String.class.getName() - + "]" + "input field [" + + inputField + + "] of type [" + + content.getClass().getName() + + "] cannot be cast to [" + + String.class.getName() + + "]" ); } } @@ -191,7 +191,6 @@ private Object chunk(IFieldChunker chunker, Object content, Map } } - @Override public IngestDocument execute(IngestDocument document) { for (Map.Entry fieldMapEntry : fieldMap.entrySet()) { diff --git a/src/test/java/org/opensearch/neuralsearch/processor/DocumentChunkingProcessorTests.java b/src/test/java/org/opensearch/neuralsearch/processor/DocumentChunkingProcessorTests.java new file mode 100644 index 000000000..3da358f41 --- /dev/null +++ b/src/test/java/org/opensearch/neuralsearch/processor/DocumentChunkingProcessorTests.java @@ -0,0 +1,2 @@ +package org.opensearch.neuralsearch.processor;public class DocumentChunkingProcessorTests { +}