Skip to content

[KYUUBI #7568][AUTHZ] Eliminate TypeOfPlaceHolder across the whole plan#7569

Closed
j1wonpark wants to merge 2 commits into
apache:masterfrom
j1wonpark:fix/authz-eliminate-typeof-whole-plan
Closed

[KYUUBI #7568][AUTHZ] Eliminate TypeOfPlaceHolder across the whole plan#7569
j1wonpark wants to merge 2 commits into
apache:masterfrom
j1wonpark:fix/authz-eliminate-typeof-whole-plan

Conversation

@j1wonpark

Copy link
Copy Markdown
Contributor

Why are the changes needed?

Fixes #7568.

RuleApplyTypeOfMarker marks every TypeOf in the whole plan (transformAllExpressions), but since #5997 RuleEliminateTypeOf reverts them with transformExpressionsUp, which only visits the root node's expressions. A TypeOfPlaceHolder below the root — under Sort, Union, Aggregate, or a subquery — survives into execution and fails with CLASS_NOT_OVERRIDE_EXPECTED_METHOD, since it implements doGenCode but no eval.

This change uses transformAllExpressions on the eliminating side as well, so both rules cover the same scope in a single pass.

Affects 1.9.0 onwards, including master.

How was this patch tested?

Added a test to RangerSparkExtensionSuite covering the root shapes the existing Project-root-only test misses: Sort, Union, Aggregate, and a subquery. It fails on master and passes with this change. Full extensions/spark/kyuubi-spark-authz suite: 657 passed, 0 failed.

Was this patch authored or co-authored using generative AI tooling?

Assisted-by: Claude:claude-opus-4-8

…ole plan

RuleApplyTypeOfMarker replaces every TypeOf in the plan with a
TypeOfPlaceHolder using transformAllExpressions, but RuleEliminateTypeOf
reverts them with transformExpressionsUp, which only visits the root
node's expressions. Any placeholder living below the root -- under Sort,
Union, Aggregate, or a subquery -- therefore survives into execution and
fails, because TypeOfPlaceHolder implements doGenCode but no eval:

  [CLASS_NOT_OVERRIDE_EXPECTED_METHOD] TypeOfPlaceHolder must override
  either eval or nullSafeEval

  SELECT typeof(id) AS t FROM t1 ORDER BY t          -- fails
  SELECT typeof(id) FROM t1 UNION ALL SELECT ...     -- fails
  SELECT typeof(id) FROM t1                          -- works (root is Project)

The whole-plan walk was dropped in KYUUBI apache#5997, which removed the outer
transformUp as an unnecessary loop. It was not: transformExpressionsUp
does not descend into children. Use transformAllExpressions instead,
mirroring RuleApplyTypeOfMarker and keeping the single-pass traversal
that apache#5997 aimed for.

The existing test only covers queries whose root node is a Project, which
is why the regression went unnoticed. Add coverage for Sort, Union,
Aggregate, and subquery roots.

Signed-off-by: Jiwon Park <jpark92@outlook.kr>
…hile keeping Union as the root node

Signed-off-by: Jiwon Park <jpark92@outlook.kr>
@pan3793 pan3793 added this to the v1.10.4 milestone Jul 16, 2026
@pan3793 pan3793 closed this in 8fe59c5 Jul 16, 2026
pan3793 pushed a commit that referenced this pull request Jul 16, 2026
### Why are the changes needed?

Fixes #7568.

`RuleApplyTypeOfMarker` marks every `TypeOf` in the whole plan (`transformAllExpressions`), but since #5997 `RuleEliminateTypeOf` reverts them with `transformExpressionsUp`, which only visits the root node's expressions. A `TypeOfPlaceHolder` below the root — under `Sort`, `Union`, `Aggregate`, or a subquery — survives into execution and fails with `CLASS_NOT_OVERRIDE_EXPECTED_METHOD`, since it implements `doGenCode` but no `eval`.

This change uses `transformAllExpressions` on the eliminating side as well, so both rules cover the same scope in a single pass.

Affects 1.9.0 onwards, including master.

### How was this patch tested?

Added a test to `RangerSparkExtensionSuite` covering the root shapes the existing `Project`-root-only test misses: `Sort`, `Union`, `Aggregate`, and a subquery. It fails on master and passes with this change. Full `extensions/spark/kyuubi-spark-authz` suite: 657 passed, 0 failed.

### Was this patch authored or co-authored using generative AI tooling?

Assisted-by: Claude:claude-opus-4-8

Closes #7569 from j1wonpark/fix/authz-eliminate-typeof-whole-plan.

Closes #7568

38464f1 [Jiwon Park] Sort collected rows in the UNION ALL case to avoid order dependency while keeping Union as the root node
9ffea2d [Jiwon Park] [KYUUBI #7568][AUTHZ] Eliminate TypeOfPlaceHolder across the whole plan

Authored-by: Jiwon Park <jpark92@outlook.kr>
Signed-off-by: Cheng Pan <chengpan@apache.org>
(cherry picked from commit 8fe59c5)
Signed-off-by: Cheng Pan <chengpan@apache.org>
pan3793 pushed a commit that referenced this pull request Jul 16, 2026
### Why are the changes needed?

Fixes #7568.

`RuleApplyTypeOfMarker` marks every `TypeOf` in the whole plan (`transformAllExpressions`), but since #5997 `RuleEliminateTypeOf` reverts them with `transformExpressionsUp`, which only visits the root node's expressions. A `TypeOfPlaceHolder` below the root — under `Sort`, `Union`, `Aggregate`, or a subquery — survives into execution and fails with `CLASS_NOT_OVERRIDE_EXPECTED_METHOD`, since it implements `doGenCode` but no `eval`.

This change uses `transformAllExpressions` on the eliminating side as well, so both rules cover the same scope in a single pass.

Affects 1.9.0 onwards, including master.

### How was this patch tested?

Added a test to `RangerSparkExtensionSuite` covering the root shapes the existing `Project`-root-only test misses: `Sort`, `Union`, `Aggregate`, and a subquery. It fails on master and passes with this change. Full `extensions/spark/kyuubi-spark-authz` suite: 657 passed, 0 failed.

### Was this patch authored or co-authored using generative AI tooling?

Assisted-by: Claude:claude-opus-4-8

Closes #7569 from j1wonpark/fix/authz-eliminate-typeof-whole-plan.

Closes #7568

38464f1 [Jiwon Park] Sort collected rows in the UNION ALL case to avoid order dependency while keeping Union as the root node
9ffea2d [Jiwon Park] [KYUUBI #7568][AUTHZ] Eliminate TypeOfPlaceHolder across the whole plan

Authored-by: Jiwon Park <jpark92@outlook.kr>
Signed-off-by: Cheng Pan <chengpan@apache.org>
(cherry picked from commit 8fe59c5)
Signed-off-by: Cheng Pan <chengpan@apache.org>
@pan3793

pan3793 commented Jul 16, 2026

Copy link
Copy Markdown
Member

thanks, merged to master/1.11/1.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] typeof() fails with CLASS_NOT_OVERRIDE_EXPECTED_METHOD when it is not in the root plan node

2 participants