Skip to content

[MINOR][CORE] Seal GlutenCost and drop unreachable case in LongCostModel - #12586

Closed
LuciferYang wants to merge 1 commit into
apache:mainfrom
LuciferYang:gluten-minor-core-seal-glutencost
Closed

[MINOR][CORE] Seal GlutenCost and drop unreachable case in LongCostModel#12586
LuciferYang wants to merge 1 commit into
apache:mainfrom
LuciferYang:gluten-minor-core-seal-glutencost

Conversation

@LuciferYang

@LuciferYang LuciferYang commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Follow-up dead-code cleanup missed by #12522. GlutenCost in extension/columnar/cost/ has always had exactly one implementation (LongCost), yet was declared as an open trait and the costComparator fell back through a case _ => throw new IllegalStateException("Unexpected cost type") branch that was unreachable in practice.

Changes

  • Seal the trait: trait GlutenCostsealed trait GlutenCost. Scala 2 requires sealed subclasses to live in the same compilation unit, so LongCost is co-located in GlutenCost.scala.
  • Delete LongCost.scala (its contents were merged into GlutenCost.scala).
  • Remove the unreachable case _ => throw new IllegalStateException("Unexpected cost type") branch in LongCostModel.costComparator. After sealing, case LongCost(value) => value is exhaustive by construction.

The two other match expressions in LongCostModelsum and diff — already destructure (LongCost(_), LongCost(_)) and remain exhaustive after sealing. Downstream imports of GlutenCost across gluten-core, backends-velox, and backends-clickhouse are unaffected. This is a compile-time-only tightening with no behavior change.

How was this patch tested?

  • ./build/mvn -Pbackends-velox -Pspark-3.5 -pl gluten-core -am test-compile -DskipTests: SUCCESS
  • ./build/mvn -Pbackends-velox -Pspark-3.5 -pl backends-velox -am test-compile -DskipTests: SUCCESS
  • ./build/mvn -Pbackends-clickhouse -Pspark-3.3 -Pdelta -pl backends-clickhouse -am test-compile -DskipTests: SUCCESS
  • ./dev/format-scala-code.sh: no additional diff
  • Compilation runs under -Wconf:any:e (fatal warnings), so exhaustiveness of the two remaining LongCost(_), LongCost(_) destructure matches is compiler-verified after the seal.
  • Verified via grep -rn 'extends GlutenCost\|with GlutenCost' that LongCost is the sole implementation across the whole repository.

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

Generated-by: Claude claude-opus-4-7

…Model

Follow-up dead-code cleanup missed by apache#12522 (L3 planner-core review R6):

* `GlutenCost` in `extension/columnar/cost/` has always had exactly one
  implementation (`LongCost`). Turn the trait into a `sealed trait` and
  co-locate `LongCost` in the same file so the sealed hierarchy is
  enforced at compile time. Scala 2 requires sealed subclasses to live
  in the same compilation unit.
* Delete `LongCost.scala` (contents merged into `GlutenCost.scala`).
* Remove the unreachable `case _ => throw new IllegalStateException(...)`
  branch in `LongCostModel.costComparator`; after sealing, the compiler
  proves exhaustiveness on `case LongCost(value) => value`.

The two other `match` expressions in `LongCostModel` (`sum` and `diff`)
already destructure `(LongCost(_), LongCost(_))` and remain exhaustive
after sealing. Downstream call sites of `GlutenCost` (imports listed
across `gluten-core`, `backends-velox`, `backends-clickhouse`) are
unaffected — this is a compile-time-only tightening with no behavior
change.
Copilot AI review requested due to automatic review settings July 21, 2026 05:38
@github-actions github-actions Bot added the CORE works for Gluten Core label Jul 21, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Tightens the columnar planner cost type hierarchy by sealing GlutenCost (which is effectively a single-implementation ADT) and cleaning up a now-unnecessary fallback branch in LongCostModel’s comparator.

Changes:

  • Change GlutenCost from an open trait to a sealed trait.
  • Co-locate the sole implementation LongCost into GlutenCost.scala and delete LongCost.scala.
  • Remove the unreachable default match case in LongCostModel.costComparator now that LongCost matching is exhaustive.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/LongCostModel.scala Removes the unreachable fallback branch in the cost comparator match.
gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/GlutenCost.scala Seals GlutenCost and defines LongCost in the same compilation unit.
gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/LongCost.scala Deleted; implementation moved into GlutenCost.scala.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

CORE works for Gluten Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants