Repository navigation
Conversation
|
Workflow [PR], commit [0843bf4] Summary: ❌
AI ReviewSummaryThis PR tries to make Iceberg manifest pruning understand filters such as PR Metadata
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Minimum required actions: make the rewrite predicate-aware and type-safe, prove or avoid temporal range rewrites where monotonicity does not hold, rebuild |
| [](const DataTypePtr & t) { return isNumber(t); }, | ||
| [](ActionsDAG & dag, const ActionsDAG::Node * sibling, const ContextPtr &) -> const ActionsDAG::Node * | ||
| { | ||
| auto year_val = (*sibling->column)[0].safeGet<UInt64>(); |
There was a problem hiding this comment.
accepts_const_type allows any numeric constant, but safeGet<UInt64>() only works when the folded literal is exactly UInt64.
For example, toYear(ts) = toInt32(2022) (or any signed/float numeric literal after typing) reaches this branch and throws BAD_GET while building pruning conditions, turning a valid query into an exception when use_iceberg_partition_pruning=1.
Please either restrict the accepted RHS types to ones you can safely extract here, or convert via a type-aware path (e.g. cast the constant to an integer type first and validate bounds) before subtracting 1970.
antonio2368
left a comment
There was a problem hiding this comment.
It seems like a really tricky thing to do. We should probably have more tests with as many edge cases as possible.
AI should be good in finding those edge cases.
| std::function<const ActionsDAG::Node *(ActionsDAG &, const ActionsDAG::Node *, const ContextPtr &)> convert_const; | ||
| }; | ||
|
|
||
| static std::vector<FunctionSubstitutionEntry> buildSubstitutionTable(const ContextPtr & context) |
There was a problem hiding this comment.
Something AI found:
This rewrite is not safe for range pruning on Iceberg historical temporal values. Iceberg date is imported as Date32, and timestamp / timestamptz are imported as DateTime64 (SchemaProcessor.cpp:301-308), so pre-1970 values are valid input for manifest pruning. But the replacement functions used here are the standard unsigned relative transforms: toRelativeDayNum is registered as UInt32 and its standard Date32 path casts through UInt16, while toRelativeHourNum is registered as UInt32 and its standard historical paths cast through unsigned values (toRelativeDayNum.cpp:10, toRelativeHourNum.cpp:10, DateTimeTransforms.h:2188-2204, 2220-2240).
That does not preserve ordering across the Unix epoch. For example:
SELECT
toDate32('1969-12-31') AS d1,
toDate32('1970-01-01') AS d2,
toRelativeDayNum(d1) AS r1,
toRelativeDayNum(d2) AS r2,
r1 < r2 AS relative_order_ok;returns r1 = 65535, r2 = 0, and relative_order_ok = 0. Similarly, toRelativeHourNum(toDateTime64('1969-12-31 23:00:00', 0, 'UTC')) is greater than the value for 1970-01-01 00:00:00.
So a range predicate over toDate / toStartOfHour can be converted into a predicate whose ordering is different from the original one, and KeyCondition can then prune a manifest that actually contains matching rows. Equality for post-1970 happy paths is not enough to justify using these substitutions for ranges.
Please either skip these substitutions when the source domain can include pre-1970 Date32 / DateTime64, or use a signed/extended transform and only enable range rewrites after proving the replacement is monotonic-equivalent for the source and constant domains.
| return &dag.addFunction(func_base, {const_node}, const_node->result_name); | ||
| }; | ||
|
|
||
| entries.push_back({"toDate", "toRelativeDayNum", |
There was a problem hiding this comment.
toDate accepts strings, while toRelativeDayNum doesn't. You should probably check argument types before transforming.
Potentially same is true for other parts.
| [](const DataTypePtr & t) { return isNumber(t); }, | ||
| [](ActionsDAG & dag, const ActionsDAG::Node * sibling, const ContextPtr &) -> const ActionsDAG::Node * | ||
| { | ||
| auto year_val = (*sibling->column)[0].safeGet<UInt64>(); |
There was a problem hiding this comment.
What gh reviewer said is true. You probably need to restrict it more.
|
|
||
| std::unordered_map<const ActionsDAG::Node *, size_t> substituted_nodes; | ||
|
|
||
| for (auto & node : const_cast<ActionsDAG::Nodes &>(dag.getNodes())) |
There was a problem hiding this comment.
Not sure if this is okay. I think you need to use ActionsDAG::addFunction.
|
|
||
| for (auto & node : const_cast<ActionsDAG::Nodes &>(dag.getNodes())) | ||
| { | ||
| if (node.type != ActionsDAG::ActionType::FUNCTION || node.children.size() != 2) |
There was a problem hiding this comment.
This seems a bit scary, what if it's not comparison operator? Even for comparison operators there can be strange edge cases:
WHERE toStartOfHour(ts) < toDateTime('2024-01-10 10:30:00') becomes toRelativeHourNum(ts) < toRelativeHourNum('2024-01-10 10:30:00') which would exclude some values that it didn't exclude before.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 37/85 (43.53%) | Lost baseline coverage: none · Uncovered code |
|
Dear @antonio2368, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
I'll close this PR and continue working here as this PR is too old: #118606 |
#103447 rewrote the filter itself, substituting `toDate` with `toRelativeDayNum` and recomputing the constant, and the review named two ways that loses rows: a constant that is not aligned to the transform's granularity (`toStartOfHour(ts) < '... 10:30:00'` must keep the 10:00 hour, the rewrite dropped it) and a value before 1970, where the unsigned relative transforms invert the ordering (`toRelativeDayNum('1969-12-31')` is `65535` while `1970-01-01` is `0`). Deriving the source range from the partition value leaves the predicate alone, so both are decided by `KeyCondition` over an exact range instead of by an equivalence that has to be proven. Test them: a non-aligned constant on the hour, day and month transforms, and a table whose `days` and `years` partition values are negative. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Partition pruning fix with date transforms. This closes #103433
Documentation entry for user-facing changes