jihoonson commented on a change in pull request #10383:
URL: https://github.com/apache/druid/pull/10383#discussion_r487371583



##########
File path: core/src/main/java/org/apache/druid/data/input/impl/JsonReader.java
##########
@@ -49,41 +55,99 @@
       boolean keepNullColumns
   )
   {
-    super(inputRowSchema, source);
+    this.inputRowSchema = inputRowSchema;
+    this.source = source;
     this.flattener = ObjectFlatteners.create(flattenSpec, new 
JSONFlattenerMaker(keepNullColumns));
     this.mapper = mapper;
   }
 
-  @Override
-  public List<InputRow> parseInputRows(String line) throws IOException, 
ParseException
-  {
-    final JsonNode document = mapper.readValue(line, JsonNode.class);
-    final Map<String, Object> flattened = flattener.flatten(document);
-    return 
Collections.singletonList(MapInputRowParser.parse(getInputRowSchema(), 
flattened));
-  }
 
   @Override
-  public Map<String, Object> toMap(String intermediateRow) throws IOException
+  public CloseableIterator<InputRow> read() throws IOException
   {
-    //noinspection unchecked
-    return mapper.readValue(intermediateRow, Map.class);
+    final MappingIterator<JsonNode> delegate = mapper.readValues(
+        new JsonFactory().createParser(this.source.open()),

Review comment:
       The `parser` created from `JsonFactory` is `Closeable` which should be 
closed when the below `CloseableIterator` is closed. 

##########
File path: core/src/main/java/org/apache/druid/data/input/impl/JsonReader.java
##########
@@ -49,41 +55,99 @@
       boolean keepNullColumns
   )
   {
-    super(inputRowSchema, source);
+    this.inputRowSchema = inputRowSchema;
+    this.source = source;
     this.flattener = ObjectFlatteners.create(flattenSpec, new 
JSONFlattenerMaker(keepNullColumns));
     this.mapper = mapper;
   }
 
-  @Override
-  public List<InputRow> parseInputRows(String line) throws IOException, 
ParseException
-  {
-    final JsonNode document = mapper.readValue(line, JsonNode.class);
-    final Map<String, Object> flattened = flattener.flatten(document);
-    return 
Collections.singletonList(MapInputRowParser.parse(getInputRowSchema(), 
flattened));
-  }
 
   @Override
-  public Map<String, Object> toMap(String intermediateRow) throws IOException
+  public CloseableIterator<InputRow> read() throws IOException
   {
-    //noinspection unchecked
-    return mapper.readValue(intermediateRow, Map.class);
+    final MappingIterator<JsonNode> delegate = mapper.readValues(
+        new JsonFactory().createParser(this.source.open()),

Review comment:
       I haven't looked through the PR yet, but found that the `parser` created 
from `JsonFactory` is `Closeable` which should be closed when the below 
`CloseableIterator` is closed. I will review again when you update the PR.

##########
File path: core/src/main/java/org/apache/druid/data/input/impl/JsonReader.java
##########
@@ -49,41 +55,99 @@
       boolean keepNullColumns
   )
   {
-    super(inputRowSchema, source);
+    this.inputRowSchema = inputRowSchema;
+    this.source = source;
     this.flattener = ObjectFlatteners.create(flattenSpec, new 
JSONFlattenerMaker(keepNullColumns));
     this.mapper = mapper;
   }
 
-  @Override
-  public List<InputRow> parseInputRows(String line) throws IOException, 
ParseException
-  {
-    final JsonNode document = mapper.readValue(line, JsonNode.class);
-    final Map<String, Object> flattened = flattener.flatten(document);
-    return 
Collections.singletonList(MapInputRowParser.parse(getInputRowSchema(), 
flattened));
-  }
 
   @Override
-  public Map<String, Object> toMap(String intermediateRow) throws IOException
+  public CloseableIterator<InputRow> read() throws IOException
   {
-    //noinspection unchecked
-    return mapper.readValue(intermediateRow, Map.class);
+    final MappingIterator<JsonNode> delegate = mapper.readValues(
+        new JsonFactory().createParser(this.source.open()),

Review comment:
       The `parser` created from `JsonFactory` is `Closeable` which should be 
closed when the below `CloseableIterator` is closed. 

##########
File path: core/src/main/java/org/apache/druid/data/input/impl/JsonReader.java
##########
@@ -49,41 +55,99 @@
       boolean keepNullColumns
   )
   {
-    super(inputRowSchema, source);
+    this.inputRowSchema = inputRowSchema;
+    this.source = source;
     this.flattener = ObjectFlatteners.create(flattenSpec, new 
JSONFlattenerMaker(keepNullColumns));
     this.mapper = mapper;
   }
 
-  @Override
-  public List<InputRow> parseInputRows(String line) throws IOException, 
ParseException
-  {
-    final JsonNode document = mapper.readValue(line, JsonNode.class);
-    final Map<String, Object> flattened = flattener.flatten(document);
-    return 
Collections.singletonList(MapInputRowParser.parse(getInputRowSchema(), 
flattened));
-  }
 
   @Override
-  public Map<String, Object> toMap(String intermediateRow) throws IOException
+  public CloseableIterator<InputRow> read() throws IOException
   {
-    //noinspection unchecked
-    return mapper.readValue(intermediateRow, Map.class);
+    final MappingIterator<JsonNode> delegate = mapper.readValues(
+        new JsonFactory().createParser(this.source.open()),

Review comment:
       I haven't looked through the PR yet, but found that the `parser` created 
from `JsonFactory` is `Closeable` which should be closed when the below 
`CloseableIterator` is closed. I will review again when you update the PR.

##########
File path: core/src/main/java/org/apache/druid/data/input/impl/JsonReader.java
##########
@@ -49,41 +55,99 @@
       boolean keepNullColumns
   )
   {
-    super(inputRowSchema, source);
+    this.inputRowSchema = inputRowSchema;
+    this.source = source;
     this.flattener = ObjectFlatteners.create(flattenSpec, new 
JSONFlattenerMaker(keepNullColumns));
     this.mapper = mapper;
   }
 
-  @Override
-  public List<InputRow> parseInputRows(String line) throws IOException, 
ParseException
-  {
-    final JsonNode document = mapper.readValue(line, JsonNode.class);
-    final Map<String, Object> flattened = flattener.flatten(document);
-    return 
Collections.singletonList(MapInputRowParser.parse(getInputRowSchema(), 
flattened));
-  }
 
   @Override
-  public Map<String, Object> toMap(String intermediateRow) throws IOException
+  public CloseableIterator<InputRow> read() throws IOException
   {
-    //noinspection unchecked
-    return mapper.readValue(intermediateRow, Map.class);
+    final MappingIterator<JsonNode> delegate = mapper.readValues(
+        new JsonFactory().createParser(this.source.open()),

Review comment:
       The `parser` created from `JsonFactory` is `Closeable` which should be 
closed when the below `CloseableIterator` is closed. 

##########
File path: core/src/main/java/org/apache/druid/data/input/impl/JsonReader.java
##########
@@ -49,41 +55,99 @@
       boolean keepNullColumns
   )
   {
-    super(inputRowSchema, source);
+    this.inputRowSchema = inputRowSchema;
+    this.source = source;
     this.flattener = ObjectFlatteners.create(flattenSpec, new 
JSONFlattenerMaker(keepNullColumns));
     this.mapper = mapper;
   }
 
-  @Override
-  public List<InputRow> parseInputRows(String line) throws IOException, 
ParseException
-  {
-    final JsonNode document = mapper.readValue(line, JsonNode.class);
-    final Map<String, Object> flattened = flattener.flatten(document);
-    return 
Collections.singletonList(MapInputRowParser.parse(getInputRowSchema(), 
flattened));
-  }
 
   @Override
-  public Map<String, Object> toMap(String intermediateRow) throws IOException
+  public CloseableIterator<InputRow> read() throws IOException
   {
-    //noinspection unchecked
-    return mapper.readValue(intermediateRow, Map.class);
+    final MappingIterator<JsonNode> delegate = mapper.readValues(
+        new JsonFactory().createParser(this.source.open()),

Review comment:
       I haven't looked through the PR yet, but found that the `parser` created 
from `JsonFactory` is `Closeable` which should be closed when the below 
`CloseableIterator` is closed. I will review again when you update the PR.

##########
File path: core/src/main/java/org/apache/druid/data/input/impl/JsonReader.java
##########
@@ -49,41 +55,99 @@
       boolean keepNullColumns
   )
   {
-    super(inputRowSchema, source);
+    this.inputRowSchema = inputRowSchema;
+    this.source = source;
     this.flattener = ObjectFlatteners.create(flattenSpec, new 
JSONFlattenerMaker(keepNullColumns));
     this.mapper = mapper;
   }
 
-  @Override
-  public List<InputRow> parseInputRows(String line) throws IOException, 
ParseException
-  {
-    final JsonNode document = mapper.readValue(line, JsonNode.class);
-    final Map<String, Object> flattened = flattener.flatten(document);
-    return 
Collections.singletonList(MapInputRowParser.parse(getInputRowSchema(), 
flattened));
-  }
 
   @Override
-  public Map<String, Object> toMap(String intermediateRow) throws IOException
+  public CloseableIterator<InputRow> read() throws IOException
   {
-    //noinspection unchecked
-    return mapper.readValue(intermediateRow, Map.class);
+    final MappingIterator<JsonNode> delegate = mapper.readValues(
+        new JsonFactory().createParser(this.source.open()),

Review comment:
       The `parser` created from `JsonFactory` is `Closeable` which should be 
closed when the below `CloseableIterator` is closed. 

##########
File path: core/src/main/java/org/apache/druid/data/input/impl/JsonReader.java
##########
@@ -49,41 +55,99 @@
       boolean keepNullColumns
   )
   {
-    super(inputRowSchema, source);
+    this.inputRowSchema = inputRowSchema;
+    this.source = source;
     this.flattener = ObjectFlatteners.create(flattenSpec, new 
JSONFlattenerMaker(keepNullColumns));
     this.mapper = mapper;
   }
 
-  @Override
-  public List<InputRow> parseInputRows(String line) throws IOException, 
ParseException
-  {
-    final JsonNode document = mapper.readValue(line, JsonNode.class);
-    final Map<String, Object> flattened = flattener.flatten(document);
-    return 
Collections.singletonList(MapInputRowParser.parse(getInputRowSchema(), 
flattened));
-  }
 
   @Override
-  public Map<String, Object> toMap(String intermediateRow) throws IOException
+  public CloseableIterator<InputRow> read() throws IOException
   {
-    //noinspection unchecked
-    return mapper.readValue(intermediateRow, Map.class);
+    final MappingIterator<JsonNode> delegate = mapper.readValues(
+        new JsonFactory().createParser(this.source.open()),

Review comment:
       I haven't looked through the PR yet, but found that the `parser` created 
from `JsonFactory` is `Closeable` which should be closed when the below 
`CloseableIterator` is closed. I will review again when you update the PR.

##########
File path: core/src/main/java/org/apache/druid/data/input/impl/JsonReader.java
##########
@@ -49,41 +55,99 @@
       boolean keepNullColumns
   )
   {
-    super(inputRowSchema, source);
+    this.inputRowSchema = inputRowSchema;
+    this.source = source;
     this.flattener = ObjectFlatteners.create(flattenSpec, new 
JSONFlattenerMaker(keepNullColumns));
     this.mapper = mapper;
   }
 
-  @Override
-  public List<InputRow> parseInputRows(String line) throws IOException, 
ParseException
-  {
-    final JsonNode document = mapper.readValue(line, JsonNode.class);
-    final Map<String, Object> flattened = flattener.flatten(document);
-    return 
Collections.singletonList(MapInputRowParser.parse(getInputRowSchema(), 
flattened));
-  }
 
   @Override
-  public Map<String, Object> toMap(String intermediateRow) throws IOException
+  public CloseableIterator<InputRow> read() throws IOException
   {
-    //noinspection unchecked
-    return mapper.readValue(intermediateRow, Map.class);
+    final MappingIterator<JsonNode> delegate = mapper.readValues(
+        new JsonFactory().createParser(this.source.open()),

Review comment:
       The `parser` created from `JsonFactory` is `Closeable` which should be 
closed when the below `CloseableIterator` is closed. 

##########
File path: core/src/main/java/org/apache/druid/data/input/impl/JsonReader.java
##########
@@ -49,41 +55,99 @@
       boolean keepNullColumns
   )
   {
-    super(inputRowSchema, source);
+    this.inputRowSchema = inputRowSchema;
+    this.source = source;
     this.flattener = ObjectFlatteners.create(flattenSpec, new 
JSONFlattenerMaker(keepNullColumns));
     this.mapper = mapper;
   }
 
-  @Override
-  public List<InputRow> parseInputRows(String line) throws IOException, 
ParseException
-  {
-    final JsonNode document = mapper.readValue(line, JsonNode.class);
-    final Map<String, Object> flattened = flattener.flatten(document);
-    return 
Collections.singletonList(MapInputRowParser.parse(getInputRowSchema(), 
flattened));
-  }
 
   @Override
-  public Map<String, Object> toMap(String intermediateRow) throws IOException
+  public CloseableIterator<InputRow> read() throws IOException
   {
-    //noinspection unchecked
-    return mapper.readValue(intermediateRow, Map.class);
+    final MappingIterator<JsonNode> delegate = mapper.readValues(
+        new JsonFactory().createParser(this.source.open()),

Review comment:
       I haven't looked through the PR yet, but found that the `parser` created 
from `JsonFactory` is `Closeable` which should be closed when the below 
`CloseableIterator` is closed. I will review again when you update the PR.




----------------------------------------------------------------
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]

Reply via email to