Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the nested-struct IS_NULL row-group pruning fix.
No open issues 🎉
What changed in this PR
This PR fixes Java ORC row-group pruning for IS_NULL predicates on fields nested in structs, whose statistics omit rows with null ancestors.
Changes:
- Track struct ancestry and return
YES_NO_NULLfor affected predicates so matching row groups are not skipped. - Preserve existing behavior for other operators and top-level columns.
- Add a regression test verifying that a row group containing a null parent struct is read.
| File | Description |
|---|---|
java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java |
Adds regression coverage for IS_NULL under a null struct. |
java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java |
Prevents statistics-based pruning for nested-struct IS_NULL predicates. |
Review effort: Balanced
| sargLeaves.get(pred).getOperator() == PredicateLeaf.Operator.IS_NULL) { | ||
| // The column statistics only cover rows where every ancestor struct is present, | ||
| // so they cannot show that a row group has no nulls for this field. | ||
| leafValues[pred] = TruthValue.YES_NO_NULL; |
There was a problem hiding this comment.
Thanks for the fix! The root cause makes sense to me: a nested field has no values in rows where an ancestor struct is null, so its hasNull can't rule out IS NULL matches.
One concern is that treating every field under a struct as unsafe is quite broad. Many structs are rarely or never null in practice, but IS NULL on any of their fields would no longer skip any row groups.
Could we check the ancestors' statistics per row group instead? A field's statistics are complete for a row group whenever none of its ancestor structs has a null there. The ancestors' row indexes are already loaded, since all included columns' ROW_INDEX streams are read and the parents of an included column are always included, so this costs no extra I/O. Roughly:
// in the constructor: struct ancestors between the root and the leaf column,
// or null if any of them is not a struct (list/map/union)
leafAncestors[i] = evolution == null || filterColumns[i] <= 0 ? new int[0] :
findAncestors(evolution.getFileSchema().findSubtype(filterColumns[i]));
// in pickRowGroups
} else if (sargLeaves.get(pred).getOperator() == PredicateLeaf.Operator.IS_NULL &&
!ancestorsHaveNoNulls(leafAncestors[pred], indexes, rowGroup)) {
leafValues[pred] = TruthValue.YES_NO_NULL;
}
private static boolean ancestorsHaveNoNulls(int[] ancestors,
OrcProto.RowIndex[] indexes,
int rowGroup) {
if (ancestors == null) {
return false;
}
for (int column : ancestors) {
if (indexes[column] == null) {
return false;
}
OrcProto.ColumnStatistics stats = indexes[column].getEntry(rowGroup).getStatistics();
if (!stats.hasHasNull() || stats.getHasNull()) {
return false;
}
}
return true;
}This also covers fields under a list/map/union. There the statistics are counted per element rather than per row, so the current patch, which only checks for struct ancestors, would still use them.
I tried this locally with a test that writes struct<a:struct<b:struct<c:int>>> with 3 row groups of 1000 rows, where a.b is null only in the second one. a.b.c IS NULL reads 1000 rows with the per-row-group check and 3000 with the current patch. The existing TestRecordReaderImpl tests pass, including yours.
Check ancestor row-group statistics before evaluating nested IS_NULL. Cover nulls at each nesting depth and verify unaffected groups are skipped. Suggested-by: cxzl25 Generated-by: ChatGPT
What changes were proposed in this pull request?
SargApplierchecks the struct ancestors of anIS_NULLleaf for each row group. When all ancestors are known to have no nulls, the existing leaf statistics can still be used for pruning. Otherwise, or when the path contains a non-struct ancestor, evaluation falls back toYES_NO_NULL. Other operators and top-level columns are unchanged. Thanks to @cxzl25 for suggesting and testing the per-row-group approach.Why are the changes needed?
ORC writes a struct field only in rows where all of its ancestors are present, so the field's statistics do not count rows where a parent struct is null. When the field itself is never null,
hasNullis false andIS_NULLevaluates toNO, which skips row groups that contain matching rows:Reproduced on 1.9.8, 2.1.4 and 2.3.1. Spark (SPARK-60362) and Iceberg (apache/iceberg#19064) hit the same case through their ORC readers.
How was this patch tested?
Extended
TestRecordReaderImpl#testIsNullOnFieldUnderNullStructto cover five row groups with nulls at either struct depth or at the leaf. The test fails on the previous patch and passes with the revised implementation, reading exactly the three affected groups (3,000 rows). The nine targeted test classes (TestRecordReaderImpl,TestVectorOrcFile,TestReaderImpl,TestFilters,TestPluginFilters,TestOrcFilterContext,TestRowFilteringIOSkip,TestStringDictionaryandTestEncryption) reported 293 passed, 18 skipped, and no failures or errors.Was this patch authored or co-authored using generative AI tooling?
Yes. Generated-by: an AI coding assistant, used to draft the change and the test; I reviewed and tested both.