This is an automated email from the ASF dual-hosted git repository.
zhztheplayer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git
The following commit(s) were added to refs/heads/main by this push:
new be1afa4bc8 [GLUTEN-13700][CORE] Name the cost model when the backend
has no coster for it (#13701)
be1afa4bc8 is described below
commit be1afa4bc884789070f65d5b7689b05f24954ef6
Author: YangJie <[email protected]>
AuthorDate: Mon Nov 23 11:48:13 2026 -0500
[GLUTEN-13700][CORE] Name the cost model when the backend has no coster for
it (#13701)
---
.../extension/columnar/cost/LongCostModel.scala | 13 ++++-
.../columnar/cost/LongCostModelSuite.scala | 56 ++++++++++++++++++++++
2 files changed, 68 insertions(+), 1 deletion(-)
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 2a2f4a6077..2c787a6c80 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
@@ -16,6 +16,7 @@
*/
package org.apache.gluten.extension.columnar.cost
+import org.apache.gluten.config.GlutenCoreConfig
import org.apache.gluten.exception.GlutenException
import org.apache.spark.internal.Logging
@@ -92,7 +93,12 @@ object LongCostModel extends Logging {
object Kind {
private val all: mutable.Map[String, Kind] = mutable.Map()
- def values(): Map[String, Kind] = all.toMap
+ def values(): Map[String, Kind] = {
+ // Kinds register themselves on first access. Touch the built-in ones so
a built-in kind
+ // that no coster refers to is still known.
+ Seq(Legacy, Rough).foreach(_.name())
+ all.toMap
+ }
}
/**
@@ -119,6 +125,11 @@ object LongCostModel extends Logging {
}
def get(kind: Kind): LongCostModel = synchronized {
+ if (!lookup.contains(kind)) {
+ throw new GlutenException(
+ s"No coster is registered for cost model '${kind.name()}'. Set " +
+ s"${GlutenCoreConfig.GLUTEN_COST_MODEL.key} to a cost model the
backend supports.")
+ }
builderOf(kind).build()
}
diff --git
a/gluten-core/src/test/scala/org/apache/gluten/extension/columnar/cost/LongCostModelSuite.scala
b/gluten-core/src/test/scala/org/apache/gluten/extension/columnar/cost/LongCostModelSuite.scala
new file mode 100644
index 0000000000..94c4c1c07e
--- /dev/null
+++
b/gluten-core/src/test/scala/org/apache/gluten/extension/columnar/cost/LongCostModelSuite.scala
@@ -0,0 +1,56 @@
+/*
+ * 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
+
+import org.apache.gluten.component.WithDummyBackend
+import org.apache.gluten.exception.GlutenException
+import org.apache.gluten.extension.columnar.cost.LongCostModel.{Legacy, Rough}
+
+import org.apache.spark.sql.execution.SparkPlan
+
+import org.scalatest.funsuite.AnyFunSuite
+
+class LongCostModelSuite extends AnyFunSuite with WithDummyBackend {
+
+ private def legacyOnlyRegistry(): LongCostModel.Registry = {
+ val registry = LongCostModel.registry()
+ registry.register(new LongCoster {
+ override def kind(): LongCostModel.Kind = Legacy
+ override def selfCostOf(node: SparkPlan): Option[Long] = Some(1)
+ })
+ registry
+ }
+
+ // Keep first: the last test touches Rough, which registers it and would
hide a
+ // Kind.values() that misses it.
+ test("a built-in cost model the backend has no coster for is rejected by
name") {
+ // The dummy backend only registers a legacy coster.
+ val error = intercept[GlutenException](GlutenCostModel.find("rough"))
+ assert(error.getMessage.contains("'rough'"))
+ assert(error.getMessage.contains("spark.gluten.costModel"))
+ }
+
+ test("a cost model with registered costers is returned") {
+ assert(legacyOnlyRegistry().get(Legacy) != null)
+ }
+
+ test("a cost model without registered costers is rejected with its name") {
+ val error = intercept[GlutenException](legacyOnlyRegistry().get(Rough))
+ assert(error.getMessage.contains("'rough'"))
+ assert(error.getMessage.contains("spark.gluten.costModel"))
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]