Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
Signed-off-by: Yaliang Wu <[email protected]>
  • Loading branch information
ylwu-amzn committed Apr 30, 2024
1 parent 84abae7 commit 4ad1719
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.opensearch.ml.processor;

import static org.opensearch.ml.common.utils.StringUtils.toJson;
import static org.opensearch.ml.processor.InferenceProcessorAttributes.*;

import java.util.*;
Expand Down Expand Up @@ -235,7 +236,7 @@ private void getMappedModelInputFromDocuments(
String originalFieldPath = getFieldPath(ingestDocument, documentFieldName);
if (originalFieldPath != null) {
Object documentFieldValue = ingestDocument.getFieldValue(originalFieldPath, Object.class);
String documentFieldValueAsString = toString(documentFieldValue);
String documentFieldValueAsString = toJson(documentFieldValue);
updateModelParameters(modelInputFieldName, documentFieldValueAsString, modelParameters);
}
// else when cannot find field path in document, try check for nested array using json path
Expand All @@ -248,7 +249,7 @@ private void getMappedModelInputFromDocuments(
.parse(sourceObject)
.read(documentFieldName);
if (!fieldValueList.isEmpty()) {
updateModelParameters(modelInputFieldName, toString(fieldValueList), modelParameters);
updateModelParameters(modelInputFieldName, toJson(fieldValueList), modelParameters);
} else if (!ignoreMissing) {
throw new IllegalArgumentException("cannot find field name defined from input map: " + documentFieldName);
}
Expand All @@ -275,7 +276,7 @@ private void updateModelParameters(String modelInputFieldName, String originalFi
Object existingValue = modelParameters.get(modelInputFieldName);
List<Object> updatedList = (List<Object>) existingValue;
updatedList.add(originalFieldValueAsString);
modelParameters.put(modelInputFieldName, toString(updatedList));
modelParameters.put(modelInputFieldName, toJson(updatedList));
} else {
modelParameters.put(modelInputFieldName, originalFieldValueAsString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,6 @@ default Object getModelOutputField(Map<String, ?> modelTensorOutputMap, String f
}
}

/**
* Converts the given Object to its JSON string representation using the Gson library.
*
* @param originalFieldValue the Object to be converted to JSON string
* @return the JSON string representation of the input Object
*/

default String toString(Object originalFieldValue) {
return gson.toJson(originalFieldValue);
}

/**
* Writes a new dot path for a nested object within the given JSON object.
* This method is useful when dealing with arrays or nested objects in the JSON structure.
Expand Down

0 comments on commit 4ad1719

Please sign in to comment.