From f7caea4e58c6fb7cdfa3329fa4894eef21f2a6d0 Mon Sep 17 00:00:00 2001 From: yangjie01 Date: Tue, 21 Jul 2026 13:38:16 +0800 Subject: [PATCH] [MINOR][CORE] Seal `GlutenCost` and drop unreachable case in LongCostModel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up dead-code cleanup missed by #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. --- .../extension/columnar/cost/GlutenCost.scala | 4 +++- .../extension/columnar/cost/LongCost.scala | 19 ------------------- .../columnar/cost/LongCostModel.scala | 1 - 3 files changed, 3 insertions(+), 21 deletions(-) delete mode 100644 gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/LongCost.scala diff --git a/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/GlutenCost.scala b/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/GlutenCost.scala index 08a21549a0f..68619b9f2cc 100644 --- a/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/GlutenCost.scala +++ b/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/GlutenCost.scala @@ -16,4 +16,6 @@ */ package org.apache.gluten.extension.columnar.cost -trait GlutenCost +sealed trait GlutenCost + +case class LongCost(value: Long) extends GlutenCost diff --git a/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/LongCost.scala b/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/LongCost.scala deleted file mode 100644 index 7de8407ffe6..00000000000 --- a/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/LongCost.scala +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.gluten.extension.columnar.cost - -case class LongCost(value: Long) extends GlutenCost diff --git a/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/LongCostModel.scala b/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/LongCostModel.scala index d1455c81e63..8c189338f05 100644 --- a/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/LongCostModel.scala +++ b/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/cost/LongCostModel.scala @@ -61,7 +61,6 @@ abstract class LongCostModel extends GlutenCostModel { override def costComparator(): Ordering[GlutenCost] = Ordering.Long.on { case LongCost(value) => value - case _ => throw new IllegalStateException("Unexpected cost type") } override def makeInfCost(): GlutenCost = LongCost(infLongCost)