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

GH-3133: Fix SizeStatistics to handle omitted histogram #3134

Merged
merged 1 commit into from
Jan 21, 2025
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 @@ -148,8 +148,10 @@ public SizeStatistics(
List<Long> definitionLevelHistogram) {
this.type = type;
this.unencodedByteArrayDataBytes = unencodedByteArrayDataBytes;
this.repetitionLevelHistogram = repetitionLevelHistogram;
this.definitionLevelHistogram = definitionLevelHistogram;
this.repetitionLevelHistogram =
repetitionLevelHistogram == null ? Collections.emptyList() : repetitionLevelHistogram;
this.definitionLevelHistogram =
definitionLevelHistogram == null ? Collections.emptyList() : definitionLevelHistogram;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,20 @@ public void testCopyStatistics() {
Assert.assertEquals(Arrays.asList(1L, 1L, 1L), copy.getRepetitionLevelHistogram());
Assert.assertEquals(Arrays.asList(1L, 1L, 1L), copy.getDefinitionLevelHistogram());
}

@Test
public void testOmittedHistogram() {
PrimitiveType type = Types.optional(PrimitiveType.PrimitiveTypeName.BINARY)
.as(LogicalTypeAnnotation.stringType())
.named("a");
SizeStatistics statistics = new SizeStatistics(type, 1024L, null, null);
Assert.assertEquals(Optional.of(1024L), statistics.getUnencodedByteArrayDataBytes());
Assert.assertEquals(Collections.emptyList(), statistics.getRepetitionLevelHistogram());
Assert.assertEquals(Collections.emptyList(), statistics.getDefinitionLevelHistogram());

SizeStatistics copy = statistics.copy();
Assert.assertEquals(Optional.of(1024L), copy.getUnencodedByteArrayDataBytes());
Assert.assertEquals(Collections.emptyList(), copy.getRepetitionLevelHistogram());
Assert.assertEquals(Collections.emptyList(), copy.getDefinitionLevelHistogram());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2382,8 +2382,14 @@ public static SizeStatistics toParquetSizeStatistics(org.apache.parquet.column.s
formatStats.setUnencoded_byte_array_data_bytes(
stats.getUnencodedByteArrayDataBytes().get());
}
formatStats.setRepetition_level_histogram(stats.getRepetitionLevelHistogram());
formatStats.setDefinition_level_histogram(stats.getDefinitionLevelHistogram());
List<Long> repLevelHistogram = stats.getRepetitionLevelHistogram();
if (repLevelHistogram != null && !repLevelHistogram.isEmpty()) {
formatStats.setRepetition_level_histogram(repLevelHistogram);
}
List<Long> defLevelHistogram = stats.getDefinitionLevelHistogram();
if (defLevelHistogram != null && !defLevelHistogram.isEmpty()) {
formatStats.setDefinition_level_histogram(defLevelHistogram);
}
return formatStats;
}
}
Loading