Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid conversion to String in JsonReader, JsonNodeReader. #15693

Merged
merged 6 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes for static analysis.
  • Loading branch information
gianm committed Jan 16, 2024
commit b5f530a09832b0250e5212a55262c66d00a1a7f0
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.apache.druid.data.input.InputRowSchema;
import org.apache.druid.data.input.IntermediateRowParsingReader;
import org.apache.druid.java.util.common.CloseableIterators;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.parsers.CloseableIterator;
import org.apache.druid.java.util.common.parsers.JSONFlattenerMaker;
import org.apache.druid.java.util.common.parsers.JSONPathSpec;
Expand All @@ -43,6 +42,7 @@
import org.apache.druid.utils.CollectionUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -105,7 +105,7 @@ protected CloseableIterator<JsonNode> intermediateRowIterator() throws IOExcepti
//convert Jackson's JsonParseException into druid's exception for further processing
//JsonParseException will be thrown from MappingIterator#hasNext or MappingIterator#next when input json text is ill-formed
if (e.getCause() instanceof JsonParseException) {
final String rowAsString = IOUtils.toString(source.open(), StringUtils.UTF8_STRING);
final String rowAsString = IOUtils.toString(source.open(), StandardCharsets.UTF_8);
jsonNodes.add(
new ParseExceptionMarkerJsonNode(
new ParseException(rowAsString, e, "Unable to parse row [%s]", rowAsString)
Expand All @@ -117,7 +117,7 @@ protected CloseableIterator<JsonNode> intermediateRowIterator() throws IOExcepti
}

if (jsonNodes.isEmpty()) {
final String rowAsString = IOUtils.toString(source.open(), StringUtils.UTF8_STRING);
final String rowAsString = IOUtils.toString(source.open(), StandardCharsets.UTF_8);
jsonNodes.add(
new ParseExceptionMarkerJsonNode(
new ParseException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Charsets;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Iterators;
import org.apache.commons.io.IOUtils;
Expand All @@ -42,6 +41,7 @@
import org.apache.druid.java.util.common.parsers.ParseException;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -89,7 +89,7 @@ public class JsonReader extends IntermediateRowParsingReader<InputEntity>
}

@Override
protected CloseableIterator<InputEntity> intermediateRowIterator() throws IOException
protected CloseableIterator<InputEntity> intermediateRowIterator()
{
return CloseableIterators.withEmptyBaggage(Iterators.singletonIterator(source));
}
Expand All @@ -115,7 +115,7 @@ protected List<InputRow> parseInputRows(InputEntity entity) throws IOException,
//convert Jackson's JsonParseException into druid's exception for further processing
//JsonParseException will be thrown from MappingIterator#hasNext or MappingIterator#next when input json text is ill-formed
if (e.getCause() instanceof JsonParseException) {
final String rowAsString = IOUtils.toString(entity.open(), Charsets.UTF_8);
final String rowAsString = IOUtils.toString(entity.open(), StandardCharsets.UTF_8);
throw new ParseException(rowAsString, e, "Unable to parse row [%s]", rowAsString);
}

Expand All @@ -124,7 +124,7 @@ protected List<InputRow> parseInputRows(InputEntity entity) throws IOException,
}

if (inputRows.isEmpty()) {
final String rowAsString = IOUtils.toString(entity.open(), Charsets.UTF_8);
final String rowAsString = IOUtils.toString(entity.open(), StandardCharsets.UTF_8);
throw new ParseException(
rowAsString,
"Unable to parse [%s] as the intermediateRow resulted in empty input row",
Expand All @@ -148,7 +148,7 @@ protected List<Map<String, Object>> toMap(InputEntity entity) throws IOException
//convert Jackson's JsonParseException into druid's exception for further processing
//JsonParseException will be thrown from MappingIterator#hasNext or MappingIterator#next when input json text is ill-formed
if (e.getCause() instanceof JsonParseException) {
final String rowAsString = IOUtils.toString(entity.open(), Charsets.UTF_8);
final String rowAsString = IOUtils.toString(entity.open(), StandardCharsets.UTF_8);
throw new ParseException(rowAsString, e, "Unable to parse row [%s]", rowAsString);
}

Expand Down
Loading