yupeng9 commented on a change in pull request #6930:
URL: https://github.com/apache/incubator-pinot/pull/6930#discussion_r634039713



##########
File path: pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java
##########
@@ -380,4 +389,120 @@ private static void unnestResults(List<Map<String, 
String>> currentResults,
       unnestResults(newCurrentResults, nestedResultsList, index + 1, 
nonNestedResult, outputResults);
     }
   }
+
+  public static Schema getPinotSchemaFromJsonFile(File jsonFile,

Review comment:
       It's used for the command to read from somewhere. I think the command 
can be improved to first the first JSON object if there're multiple, but not 
necessary for this PR.

##########
File path: pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java
##########
@@ -380,4 +389,120 @@ private static void unnestResults(List<Map<String, 
String>> currentResults,
       unnestResults(newCurrentResults, nestedResultsList, index + 1, 
nonNestedResult, outputResults);
     }
   }
+
+  public static Schema getPinotSchemaFromJsonFile(File jsonFile,
+      @Nullable Map<String, FieldSpec.FieldType> fieldTypeMap, @Nullable 
TimeUnit timeUnit, List<String> unnestFields,
+      String delimiter)
+      throws IOException {
+    JsonNode jsonNode = fileToJsonNode(jsonFile);
+    Preconditions.checkState(jsonNode.isObject(), "the JSON data shall be an 
object");
+    return getPinotSchemaFromJsonNode(jsonNode, fieldTypeMap, timeUnit, 
unnestFields, delimiter);
+  }
+
+  public static Schema getPinotSchemaFromJsonNode(JsonNode jsonNode,
+      @Nullable Map<String, FieldSpec.FieldType> fieldTypeMap, @Nullable 
TimeUnit timeUnit, List<String> unnestFields,
+      String delimiter) {
+    Schema pinotSchema = new Schema();
+    Iterator<Map.Entry<String, JsonNode>> fieldIterator = jsonNode.fields();
+    while (fieldIterator.hasNext()) {
+      Map.Entry<String, JsonNode> fieldEntry = fieldIterator.next();
+      JsonNode childNode = fieldEntry.getValue();
+      inferPinotSchemaFromJsonNode(childNode, pinotSchema, 
fieldEntry.getKey(), fieldTypeMap, timeUnit, unnestFields,
+          delimiter);
+    }
+    return pinotSchema;
+  }
+
+  private static void inferPinotSchemaFromJsonNode(JsonNode jsonNode, Schema 
pinotSchema, String path,
+      @Nullable Map<String, FieldSpec.FieldType> fieldTypeMap, @Nullable 
TimeUnit timeUnit, List<String> unnestFields,
+      String delimiter) {
+    if (jsonNode.isNull()) {
+      // do nothing
+      return;

Review comment:
       anything wrong ignoring this field?




-- 
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:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to