Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

/**
* Handles deserializing a JSON object into a Spark InternalRow. This is accomplished via Spark's JacksonParser.
Expand All @@ -44,7 +45,9 @@ public JsonRowDeserializer(StructType schema) {
}

public InternalRow deserializeJson(String json) {
return this.jacksonParser.parse(json, this.jsonParserCreator, this.utf8StringCreator).head();
var parsedResult = this.jacksonParser.parse(json, this.jsonParserCreator, this.utf8StringCreator);
Objects.requireNonNull(parsedResult, "The output from parsing the JSON should never be null");
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message should be more specific about what happens when null is encountered and provide actionable information for debugging, such as 'Failed to parse JSON input - received null result from JacksonParser'.

Suggested change
Objects.requireNonNull(parsedResult, "The output from parsing the JSON should never be null");
Objects.requireNonNull(parsedResult,
"Failed to parse JSON input - received null result from JacksonParser. " +
"Input (truncated to 100 chars): " +
(json == null ? "null" : json.substring(0, Math.min(json.length(), 100)))
);

Copilot uses AI. Check for mistakes.
return parsedResult.head();
}

private JacksonParser newJacksonParser(StructType schema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ static ZipEntry findNextFileEntry(ZipInputStream zipInputStream) throws IOExcept
}

static FilePartition[] makeFilePartitions(String[] files, int numPartitions) {
int filesPerPartition = (int) Math.ceil((double) files.length / (double) numPartitions);
if (numPartitions <= 0) {
// Divide-by-zero protection.
numPartitions = 1;
}

final int filesPerPartition = (int) Math.ceil((double) files.length / (double) numPartitions);
if (files.length < numPartitions) {
numPartitions = files.length;
}

final FilePartition[] partitions = new FilePartition[numPartitions];

List<String> currentPartition = new ArrayList<>();
int partitionIndex = 0;
for (int i = 0; i < files.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ void morePartitionsThanFiles() {
assertEquals("B", partitions[1].getPaths().get(0));
assertEquals("C", partitions[2].getPaths().get(0));
}

@Test
void zeroPartitions() {
FilePartition[] partitions = FileUtil.makeFilePartitions(new String[]{"A", "B", "C"}, 0);
assertEquals(1, partitions.length, "If a value less than 1 is passed in, partitions should default to 1.");
}
}