amrishlal commented on a change in pull request #6918:
URL: https://github.com/apache/incubator-pinot/pull/6918#discussion_r633917206
##########
File path:
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/recordtransformer/ComplexTypeTransformer.java
##########
@@ -212,25 +234,65 @@ protected void flattenMap(GenericRow record, List<String>
columns) {
}
}
flattenMap(record, mapColumns);
- } else if (value instanceof Collection &&
_unnestFields.contains(column)) {
- for (Object inner : (Collection) value) {
- if (inner instanceof Map) {
- Map<String, Object> innerMap = (Map<String, Object>) inner;
- flattenMap(column, innerMap, new ArrayList<>(innerMap.keySet()));
+ } else if (value instanceof Collection) {
+ Collection collection = (Collection) value;
+ if (_unnestFields.contains(column)) {
+ for (Object inner : collection) {
+ if (inner instanceof Map) {
+ Map<String, Object> innerMap = (Map<String, Object>) inner;
+ flattenMap(column, innerMap, new ArrayList<>(innerMap.keySet()));
+ }
+ }
+ } else if (shallConvertToJson(collection)) {
+ try {
+ // convert the collection to JSON string
+ String jsonString = JsonFunctions.jsonFormat(collection);
+ record.putValue(column, jsonString);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(
+ String.format("Caught exception while converting value to JSON
string %s", value), e);
}
}
- } else if (isArray(value) && _unnestFields.contains(column)) {
- for (Object inner : (Object[]) value) {
- if (inner instanceof Map) {
- Map<String, Object> innerMap = (Map<String, Object>) inner;
- flattenMap(column, innerMap, new ArrayList<>(innerMap.keySet()));
+ } else if (isArray(value)) {
+ Object[] array = (Object[]) value;
+ if (_unnestFields.contains(column)) {
+ for (Object inner : array) {
+ if (inner instanceof Map) {
+ Map<String, Object> innerMap = (Map<String, Object>) inner;
+ flattenMap(column, innerMap, new ArrayList<>(innerMap.keySet()));
+ }
+ }
+ } else if (shallConvertToJson(array)) {
+ try {
+ // convert the array to JSON string
+ String jsonString = JsonFunctions.jsonFormat(array);
+ record.putValue(column, jsonString);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(
+ String.format("Caught exception while converting value to JSON
string %s", value), e);
}
}
}
}
}
- static private boolean isArray(Object obj) {
+ private boolean containPrimitives(Object[] value) {
+ if (value.length == 0) {
+ return true;
+ }
+ Object element = value[0];
+ return !(element instanceof Map || element instanceof Collection ||
isArray(element));
+ }
+
+ private boolean containPrimitives(Collection value) {
+ if (value.isEmpty()) {
+ return true;
+ }
+ Object element = value.iterator().next();
+ return !(element instanceof Map || element instanceof Collection ||
isArray(element));
+ }
Review comment:
It seems like it should be possible to combine these two functions as
well or merge them with `shallConvertToJson`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]