Repository navigation
GH-55614: [C++][Gandiva] Build the expression cache key from the expression tree - #55608
dmitry-chirkov-dremio wants to merge 3 commits into
Conversation
The tests cover Boolean AND/OR structure, string literal boundaries, IN value lists, the output field type and field nullability, and the compact forms of type parameters and floating point literals. Most of them fail on main because different expressions get the same cache key. The fix is in the next commit.
…ession tree The cache key was built from Expression::ToString(), so different expressions could print the same text and share one compiled entry. Build the key from the expression tree and the output field type instead, with length-prefixed tokens and child counts.
|
Thanks for opening a pull request! This pull request has been automatically converted to a draft because its title doesn't match Arrow's required format. If this is not a minor PR, could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project. Then could you also rename the pull request title in the following format? or After updating the title, you can mark the pull request as ready for review. See also: |
|
Benchmark of building the cache key. Measured locally on an Apple M3 (macOS arm64), compiled with
What this shows:
|
…ty and null nodes Add tests for projectors and filters built from two schemas that differ only in nullability, for a FieldNode whose nullability differs from the schema field, and for null child nodes in the cache key. Two schemas that differ only in nullability already get separate cache entries. A cached FieldNode with the wrong nullability was accepted on the old key and is rejected now. A null child node crashed the old key.
|
|
|
CI results for the new tests. Tests-only commit, before the fix: 10 of the 11 new tests fail, as predicted.
None of them crash. They fail on an expectation, for example two different expressions with the same key, or wrong output after a cache hit.
With the fix commit, both test binaries pass on all four platforms. I added four more regression tests after that, checked locally on the old key:
On the current head ( A few known failures seen previously also appeared. They are not related to this PR. |
Rationale for this change
The cache key is built from
Expression::ToString(). Different expressions can print the same text, so the secondProjector::Makereuses the compiled code of the first. The result is wrong, with no error. Four cases on main:a AND (b OR c)and(a AND b) OR cprint the same text.IFexpressions can print the same text.int64output skips validation after anint32one was compiled, and returns garbage.Make, but accepted when a valid one was compiled before.What changes are included in this PR?
The PR has the tests first, then the fix in
expression_cache_key.h.The fix builds the key with a visitor over the expression tree, with the output field type. It is a compact binary form. Every node starts with a tag, tokens carry their length, and child lists carry their count. Types and names that repeat are written once and then as a short reference. It also sorts
INlists and findslikeby node, not by text. The key handles null child nodes, so it no longer crashes before validation.Are these changes tested?
Yes. 15 new tests: key unit tests in
cache_test.cc, and end-to-end tests forProjectorandFilterinprojector_test.cc,filter_test.cc,boolean_expr_test.cc,if_expr_test.ccandprojector_build_validation_test.cc. They cover the cases above,INvalue lists, type parameters, floating point literals, null child nodes, and two schemas that differ only in nullability.On main, 12 of them fail (one crashes with SIGSEGV). Three pass on both keys:
FloatingPointBitsAndNulls, because float and double literals already print their bits, and the two tests for schemas that differ only in nullability, which record current behavior.See the comments for the time to build the key and its size.
Are there any user-facing changes?
No.
This PR contains a "Critical Fix". It fixes a bug that returned incorrect data without an error.
Was AI used for this PR?
AI tools helped investigate the bug and write the fix, tests, and description.
PR code and description written by:
Reviewed before submission by: