You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gluten.apache.org by ho...@apache.org on 2024/04/01 08:54:25 UTC
(incubator-gluten) branch main updated: [CORE] Rename acbo to ras (#5231)
This is an automated email from the ASF dual-hosted git repository.
hongze pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git
The following commit(s) were added to refs/heads/main by this push:
new 8bf9a7bb1 [CORE] Rename acbo to ras (#5231)
8bf9a7bb1 is described below
commit 8bf9a7bb1a1c796553ad42422f30cb8d01ca1197
Author: Hongze Zhang <ho...@intel.com>
AuthorDate: Mon Apr 1 16:54:21 2024 +0800
[CORE] Rename acbo to ras (#5231)
---
.github/workflows/velox_docker.yml | 6 +-
backends-velox/pom.xml | 2 +-
.../{VeloxCboSuite.scala => VeloxRasSuite.scala} | 40 ++---
docs/Configuration.md | 4 +-
gluten-core/pom.xml | 2 +-
.../apache/gluten/execution/LimitTransformer.scala | 6 +-
.../gluten/extension/ColumnarOverrides.scala | 6 +-
.../extension/columnar/EnumeratedTransform.scala | 16 +-
.../columnar/transform/ImplementSingleNode.scala | 2 +-
.../apache/gluten/planner/GlutenOptimization.scala | 12 +-
.../apache/gluten/planner/cost/GlutenCost.scala | 2 +-
.../gluten/planner/cost/GlutenCostModel.scala | 2 +-
.../gluten/planner/metadata/GlutenMetadata.scala | 2 +-
.../planner/metadata/GlutenMetadataModel.scala | 2 +-
.../gluten/planner/plan/GlutenPlanModel.scala | 4 +-
.../planner/property/GlutenPropertyModel.scala | 6 +-
.../apache/gluten/planner/rule/GlutenRules.scala | 4 +-
{gluten-cbo => gluten-ras}/common/pom.xml | 6 +-
.../scala/org/apache/gluten/ras}/CostModel.scala | 2 +-
.../org/apache/gluten/ras}/MetadataModel.scala | 2 +-
.../scala/org/apache/gluten/ras}/PlanModel.scala | 4 +-
.../org/apache/gluten/ras}/PropertyModel.scala | 6 +-
.../src/main/scala/org/apache/gluten/ras/Ras.scala | 78 ++++-----
.../scala/org/apache/gluten/ras/RasCluster.scala | 46 ++---
.../scala/org/apache/gluten/ras/RasConfig.scala | 8 +-
.../scala/org/apache/gluten/ras/RasExplain.scala | 4 +-
.../scala/org/apache/gluten/ras/RasGroup.scala | 34 ++--
.../main/scala/org/apache/gluten/ras/RasNode.scala | 56 +++----
.../scala/org/apache/gluten/ras/RasPlanner.scala | 62 +++----
.../org/apache/gluten/ras}/best/BestFinder.scala | 28 ++--
.../gluten/ras}/best/GroupBasedBestFinder.scala | 48 +++---
.../org/apache/gluten/ras}/dp/DpClusterAlgo.scala | 48 +++---
.../org/apache/gluten/ras}/dp/DpGroupAlgo.scala | 46 ++---
.../org/apache/gluten/ras}/dp/DpPlanner.scala | 80 ++++-----
.../org/apache/gluten/ras}/dp/DpZipperAlgo.scala | 4 +-
.../gluten/ras}/exaustive/ExhaustivePlanner.scala | 50 +++---
.../apache/gluten/ras}/memo/ForwardMemoTable.scala | 54 +++---
.../scala/org/apache/gluten/ras}/memo/Memo.scala | 106 ++++++------
.../org/apache/gluten/ras}/memo/MemoTable.scala | 40 ++---
.../org/apache/gluten/ras}/path/OutputFilter.scala | 10 +-
.../org/apache/gluten/ras}/path/OutputWizard.scala | 32 ++--
.../org/apache/gluten/ras}/path/PathFinder.scala | 68 ++++----
.../org/apache/gluten/ras}/path/PathKey.scala | 2 +-
.../org/apache/gluten/ras}/path/PathMask.scala | 2 +-
.../org/apache/gluten/ras}/path/Pattern.scala | 10 +-
.../scala/org/apache/gluten/ras/path/RasPath.scala | 94 +++++------
.../apache/gluten/ras}/property/PropertySet.scala | 4 +-
.../org/apache/gluten/ras}/rule/EnforcerRule.scala | 28 ++--
.../scala/org/apache/gluten/ras/rule/RasRule.scala | 14 +-
.../org/apache/gluten/ras}/rule/RuleApplier.scala | 40 ++---
.../scala/org/apache/gluten/ras}/rule/Shape.scala | 10 +-
.../apache/gluten/ras}/util/CycleDetector.scala | 2 +-
.../apache/gluten/ras}/util/IndexDisjointSet.scala | 2 +-
.../org/apache/gluten/ras}/util/NodeMap.scala | 14 +-
.../gluten/ras}/vis/GraphvizVisualizer.scala | 56 +++----
.../org/apache/gluten/ras/MetadataSuite.scala | 52 +++---
.../org/apache/gluten/ras/OperationSuite.scala | 90 +++++-----
.../org/apache/gluten/ras/PropertySuite.scala | 154 ++++++++---------
.../scala/org/apache/gluten/ras/RasSuite.scala | 186 ++++++++++-----------
.../scala/org/apache/gluten/ras/RasSuiteBase.scala | 34 ++--
.../apache/gluten/ras}/mock/MockMemoState.scala | 72 ++++----
.../org/apache/gluten/ras/mock/MockRasPath.scala | 28 ++--
.../apache/gluten/ras}/path/PathFinderSuite.scala | 120 ++++++-------
.../apache/gluten/ras}/path/PathMaskSuite.scala | 6 +-
.../org/apache/gluten/ras/path/RasPathSuite.scala | 54 +++---
.../org/apache/gluten/ras}/path/WizardSuite.scala | 92 +++++-----
.../org/apache/gluten/ras}/rule/PatternSuite.scala | 56 +++----
.../ras}/specific/CyclicSearchSpaceSuite.scala | 110 ++++++------
.../gluten/ras}/specific/DistributedSuite.scala | 90 +++++-----
.../gluten/ras}/specific/JoinReorderSuite.scala | 128 +++++++-------
.../gluten/ras}/util/IndexDisjointSetSuite.scala | 2 +-
{gluten-cbo => gluten-ras}/planner/pom.xml | 8 +-
.../main/scala/org/apache/gluten/planner/.gitkeep | 2 +-
.../test/scala/org/apache/gluten/planner/.gitkeep | 2 +-
{gluten-cbo => gluten-ras}/pom.xml | 4 +-
pom.xml | 2 +-
.../scala/org/apache/gluten/GlutenConfig.scala | 16 +-
77 files changed, 1312 insertions(+), 1314 deletions(-)
diff --git a/.github/workflows/velox_docker.yml b/.github/workflows/velox_docker.yml
index 124efc53a..40a8d4fff 100644
--- a/.github/workflows/velox_docker.yml
+++ b/.github/workflows/velox_docker.yml
@@ -191,16 +191,16 @@ jobs:
--local --preset=velox --benchmark-type=h --error-on-memleak --off-heap-size=10g -s=1.0 --threads=16 --iterations=1 \
&& GLUTEN_IT_JVM_ARGS=-Xmx5G sbin/gluten-it.sh queries-compare \
--local --preset=velox --benchmark-type=ds --error-on-memleak --off-heap-size=10g -s=1.0 --threads=16 --iterations=1
- - name: Run TPC-H / TPC-DS with ACBO
+ - name: Run TPC-H / TPC-DS with RAS
run: |
echo "JAVA_HOME: $JAVA_HOME"
cd $GITHUB_WORKSPACE/tools/gluten-it
GLUTEN_IT_JVM_ARGS=-Xmx5G sbin/gluten-it.sh queries-compare \
--local --preset=velox --benchmark-type=h --error-on-memleak --off-heap-size=10g -s=1.0 --threads=16 --iterations=1 \
- --extra-conf=spark.gluten.sql.advanced.cbo.enabled=true \
+ --extra-conf=spark.gluten.sql.ras.enabled=true \
&& GLUTEN_IT_JVM_ARGS=-Xmx5G sbin/gluten-it.sh queries-compare \
--local --preset=velox --benchmark-type=ds --error-on-memleak --off-heap-size=10g -s=1.0 --threads=16 --iterations=1 \
- --extra-conf=spark.gluten.sql.advanced.cbo.enabled=true
+ --extra-conf=spark.gluten.sql.ras.enabled=true
# run-tpc-test-centos8-oom-randomkill:
# needs: build-native-lib
diff --git a/backends-velox/pom.xml b/backends-velox/pom.xml
index 1369b110a..6a598e8c0 100755
--- a/backends-velox/pom.xml
+++ b/backends-velox/pom.xml
@@ -52,7 +52,7 @@
</dependency>
<dependency>
<groupId>org.apache.gluten</groupId>
- <artifactId>gluten-cbo-common</artifactId>
+ <artifactId>gluten-ras-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
diff --git a/backends-velox/src/test/scala/org/apache/gluten/planner/VeloxCboSuite.scala b/backends-velox/src/test/scala/org/apache/gluten/planner/VeloxRasSuite.scala
similarity index 79%
rename from backends-velox/src/test/scala/org/apache/gluten/planner/VeloxCboSuite.scala
rename to backends-velox/src/test/scala/org/apache/gluten/planner/VeloxRasSuite.scala
index ea06c0367..4b1ee935f 100644
--- a/backends-velox/src/test/scala/org/apache/gluten/planner/VeloxCboSuite.scala
+++ b/backends-velox/src/test/scala/org/apache/gluten/planner/VeloxRasSuite.scala
@@ -16,12 +16,12 @@
*/
package org.apache.gluten.planner
-import org.apache.gluten.cbo.Cbo
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.path.CboPath
-import org.apache.gluten.cbo.property.PropertySet
-import org.apache.gluten.cbo.rule.{CboRule, Shape, Shapes}
import org.apache.gluten.planner.property.GlutenProperties.Conventions
+import org.apache.gluten.ras.Ras
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.path.RasPath
+import org.apache.gluten.ras.property.PropertySet
+import org.apache.gluten.ras.rule.{RasRule, Shape, Shapes}
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.catalyst.InternalRow
@@ -29,12 +29,12 @@ import org.apache.spark.sql.catalyst.expressions.Attribute
import org.apache.spark.sql.execution._
import org.apache.spark.sql.test.SharedSparkSession
-class VeloxCboSuite extends SharedSparkSession {
- import VeloxCboSuite._
+class VeloxRasSuite extends SharedSparkSession {
+ import VeloxRasSuite._
test("C2R, R2C - basic") {
val in = RowUnary(RowLeaf())
- val planner = newCbo().newPlanner(in)
+ val planner = newRas().newPlanner(in)
val out = planner.plan()
assert(out == RowUnary(RowLeaf()))
}
@@ -42,7 +42,7 @@ class VeloxCboSuite extends SharedSparkSession {
test("C2R, R2C - explicitly requires any properties") {
val in = RowUnary(RowLeaf())
val planner =
- newCbo().newPlanner(in, PropertySet(List(Conventions.ANY)))
+ newRas().newPlanner(in, PropertySet(List(Conventions.ANY)))
val out = planner.plan()
assert(out == RowUnary(RowLeaf()))
}
@@ -50,7 +50,7 @@ class VeloxCboSuite extends SharedSparkSession {
test("C2R, R2C - requires columnar output") {
val in = RowUnary(RowLeaf())
val planner =
- newCbo().newPlanner(in, PropertySet(List(Conventions.VANILLA_COLUMNAR)))
+ newRas().newPlanner(in, PropertySet(List(Conventions.VANILLA_COLUMNAR)))
val out = planner.plan()
assert(out == RowToColumnarExec(RowUnary(RowLeaf())))
}
@@ -59,18 +59,18 @@ class VeloxCboSuite extends SharedSparkSession {
val in =
ColumnarUnary(RowUnary(RowUnary(ColumnarUnary(RowUnary(RowUnary(ColumnarUnary(RowLeaf())))))))
val planner =
- newCbo().newPlanner(in, PropertySet(List(Conventions.ROW_BASED)))
+ newRas().newPlanner(in, PropertySet(List(Conventions.ROW_BASED)))
val out = planner.plan()
assert(out == ColumnarToRowExec(ColumnarUnary(
RowToColumnarExec(RowUnary(RowUnary(ColumnarToRowExec(ColumnarUnary(RowToColumnarExec(
RowUnary(RowUnary(ColumnarToRowExec(ColumnarUnary(RowToColumnarExec(RowLeaf()))))))))))))))
- val paths = planner.newState().memoState().collectAllPaths(CboPath.INF_DEPTH).toList
+ val paths = planner.newState().memoState().collectAllPaths(RasPath.INF_DEPTH).toList
val pathCount = paths.size
assert(pathCount == 165)
}
test("C2R, R2C - Row unary convertible to Columnar") {
- object ConvertRowUnaryToColumnar extends CboRule[SparkPlan] {
+ object ConvertRowUnaryToColumnar extends RasRule[SparkPlan] {
override def shift(node: SparkPlan): Iterable[SparkPlan] = node match {
case RowUnary(child) => List(ColumnarUnary(child))
case other => List.empty
@@ -82,24 +82,24 @@ class VeloxCboSuite extends SharedSparkSession {
val in =
ColumnarUnary(RowUnary(RowUnary(ColumnarUnary(RowUnary(RowUnary(ColumnarUnary(RowLeaf())))))))
val planner =
- newCbo(List(ConvertRowUnaryToColumnar))
+ newRas(List(ConvertRowUnaryToColumnar))
.newPlanner(in, PropertySet(List(Conventions.ROW_BASED)))
val out = planner.plan()
assert(out == ColumnarToRowExec(ColumnarUnary(ColumnarUnary(ColumnarUnary(
ColumnarUnary(ColumnarUnary(ColumnarUnary(ColumnarUnary(RowToColumnarExec(RowLeaf()))))))))))
- val paths = planner.newState().memoState().collectAllPaths(CboPath.INF_DEPTH).toList
+ val paths = planner.newState().memoState().collectAllPaths(RasPath.INF_DEPTH).toList
val pathCount = paths.size
assert(pathCount == 1094)
}
}
-object VeloxCboSuite {
- def newCbo(): Cbo[SparkPlan] = {
- GlutenOptimization().asInstanceOf[Cbo[SparkPlan]]
+object VeloxRasSuite {
+ def newRas(): Ras[SparkPlan] = {
+ GlutenOptimization().asInstanceOf[Ras[SparkPlan]]
}
- def newCbo(cboRules: Seq[CboRule[SparkPlan]]): Cbo[SparkPlan] = {
- GlutenOptimization(cboRules).asInstanceOf[Cbo[SparkPlan]]
+ def newRas(RasRules: Seq[RasRule[SparkPlan]]): Ras[SparkPlan] = {
+ GlutenOptimization(RasRules).asInstanceOf[Ras[SparkPlan]]
}
case class RowLeaf() extends LeafExecNode {
diff --git a/docs/Configuration.md b/docs/Configuration.md
index b98cb1d82..715419457 100644
--- a/docs/Configuration.md
+++ b/docs/Configuration.md
@@ -19,10 +19,10 @@ You can add these configurations into spark-defaults.conf to enable or disable t
| spark.memory.offHeap.size | To set up how much memory to be used for Java OffHeap.<br /> Please notice Gluten Plugin will leverage this setting to allocate memory space for native usage even offHeap is disabled. <br /> The value is based on your system and it is recommended to set it larger if you are facing Out of Memory issue in Gluten Plugin [...]
| spark.sql.sources.useV1SourceList | Choose to use V1 source [...]
| spark.sql.join.preferSortMergeJoin | To turn off preferSortMergeJoin in Spark [...]
-| spark.plugins | To load Gluten's components by Spark's plug-in loader [...]
+| spark.plugins | To load Gluten's components by Spark's plug-in loader [...]
| spark.shuffle.manager | To turn on Gluten Columnar Shuffle Plugin [...]
| spark.gluten.enabled | Enable Gluten, default is true. Just an experimental property. Recommend to enable/disable Gluten through the setting for `spark.plugins`. [...]
-| spark.gluten.sql.advanced.cbo.enabled | Experimental: Enables Gluten's advanced CBO features during physical planning. E.g, More efficient fallback strategy, etc. The option can be turned on and off individually despite vanilla Spark's CBO settings. Note, Gluten's query optimizer may still adopt a subset of its advanced CBO capabilities even this option is off. Enabling it would cause Gluten consider using CBO for optimization more aggressively. Note, this feature [...]
+| spark.gluten.sql.ras.enabled | Experimental: Enables RAS (relation algebra selector) during physical planning to generate more efficient query plan. Note, this feature is still in development and may not bring performance profits. [...]
| spark.gluten.sql.columnar.maxBatchSize | Number of rows to be processed in each batch. Default value is 4096. [...]
| spark.gluten.memory.isolation | (Experimental) Enable isolated memory mode. If true, Gluten controls the maximum off-heap memory can be used by each task to X, X = executor memory / max task slots. It's recommended to set true if Gluten serves concurrent queries within a single session, since not all memory Gluten allocated is guaranteed to be spillable. In the case, the feature should be enabled to avoid OOM. Note when true, setting spark.memory.storageFra [...]
| spark.gluten.sql.columnar.scanOnly | When enabled, this config will overwrite all other operators' enabling, and only Scan and Filter pushdown will be offloaded to native. [...]
diff --git a/gluten-core/pom.xml b/gluten-core/pom.xml
index 836d7a51e..4af88a3b3 100644
--- a/gluten-core/pom.xml
+++ b/gluten-core/pom.xml
@@ -36,7 +36,7 @@
</dependency>
<dependency>
<groupId>org.apache.gluten</groupId>
- <artifactId>gluten-cbo-common</artifactId>
+ <artifactId>gluten-ras-common</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
diff --git a/gluten-core/src/main/scala/org/apache/gluten/execution/LimitTransformer.scala b/gluten-core/src/main/scala/org/apache/gluten/execution/LimitTransformer.scala
index 6c4e63d78..097aefa21 100644
--- a/gluten-core/src/main/scala/org/apache/gluten/execution/LimitTransformer.scala
+++ b/gluten-core/src/main/scala/org/apache/gluten/execution/LimitTransformer.scala
@@ -60,12 +60,12 @@ case class LimitTransformer(child: SparkPlan, offset: Long, count: Long)
case c: TransformSupport => c.doTransform(context).root
case _ => null
}
- // If ACBO is enabled and is capable to move limit operators up and down among the plan nodes,
+ // If RAS is enabled and is capable to move limit operators up and down among the plan nodes,
// It might become possible that an independent limit gets to be transited to a order-by-limit.
// In that case, we should tuning on the validation procedure. Either to move limit validation
- // To ACBO, or re-validate it in ACBO, or add properties or rules in ACBO to avoid such moves.
+ // To RAS, or re-validate it in RAS, or add properties or rules in RAS to avoid such moves.
//
- // It's not a issue for now since ACBO doesn't do such moves.
+ // It's not a issue for now since RAS doesn't do such moves.
val relNode = getRelNode(context, operatorId, offset, count, child.output, input, true)
doNativeValidation(context, relNode)
diff --git a/gluten-core/src/main/scala/org/apache/gluten/extension/ColumnarOverrides.scala b/gluten-core/src/main/scala/org/apache/gluten/extension/ColumnarOverrides.scala
index ff842839d..b664aa988 100644
--- a/gluten-core/src/main/scala/org/apache/gluten/extension/ColumnarOverrides.scala
+++ b/gluten-core/src/main/scala/org/apache/gluten/extension/ColumnarOverrides.scala
@@ -225,8 +225,8 @@ case class ColumnarOverrideRules(session: SparkSession)
*/
private def transformRules(outputsColumnar: Boolean): List[SparkSession => Rule[SparkPlan]] = {
- def maybeCbo(outputsColumnar: Boolean): List[SparkSession => Rule[SparkPlan]] = {
- if (GlutenConfig.getConf.enableAdvancedCbo) {
+ def maybeRas(outputsColumnar: Boolean): List[SparkSession => Rule[SparkPlan]] = {
+ if (GlutenConfig.getConf.enableRas) {
return List(
(_: SparkSession) => TransformPreOverrides(List(ImplementFilter()), List.empty),
(session: SparkSession) => EnumeratedTransform(session, outputsColumnar),
@@ -251,7 +251,7 @@ case class ColumnarOverrideRules(session: SparkSession)
(_: SparkSession) => AddTransformHintRule(),
(_: SparkSession) => FallbackBloomFilterAggIfNeeded()
) :::
- maybeCbo(outputsColumnar) :::
+ maybeRas(outputsColumnar) :::
List(
(_: SparkSession) => RemoveNativeWriteFilesSortAndProject(),
(spark: SparkSession) => RewriteTransformer(spark),
diff --git a/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/EnumeratedTransform.scala b/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/EnumeratedTransform.scala
index 983abfe23..832ff5883 100644
--- a/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/EnumeratedTransform.scala
+++ b/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/EnumeratedTransform.scala
@@ -16,11 +16,11 @@
*/
package org.apache.gluten.extension.columnar
-import org.apache.gluten.cbo.property.PropertySet
-import org.apache.gluten.cbo.rule.{CboRule, Shape, Shapes}
import org.apache.gluten.extension.columnar.transform.{ImplementExchange, ImplementJoin, ImplementOthers, ImplementSingleNode}
import org.apache.gluten.planner.GlutenOptimization
import org.apache.gluten.planner.property.GlutenProperties
+import org.apache.gluten.ras.property.PropertySet
+import org.apache.gluten.ras.rule.{RasRule, Shape, Shapes}
import org.apache.gluten.utils.LogLevelUtil
import org.apache.spark.sql.SparkSession
@@ -32,13 +32,13 @@ case class EnumeratedTransform(session: SparkSession, outputsColumnar: Boolean)
with LogLevelUtil {
import EnumeratedTransform._
- private val cboRules = List(
- CboImplement(ImplementOthers()),
- CboImplement(ImplementExchange()),
- CboImplement(ImplementJoin())
+ private val rasRules = List(
+ RasImplement(ImplementOthers()),
+ RasImplement(ImplementExchange()),
+ RasImplement(ImplementJoin())
)
- private val optimization = GlutenOptimization(cboRules)
+ private val optimization = GlutenOptimization(rasRules)
private val reqConvention = GlutenProperties.Conventions.ANY
private val altConventions =
@@ -55,7 +55,7 @@ case class EnumeratedTransform(session: SparkSession, outputsColumnar: Boolean)
}
object EnumeratedTransform {
- private case class CboImplement(delegate: ImplementSingleNode) extends CboRule[SparkPlan] {
+ private case class RasImplement(delegate: ImplementSingleNode) extends RasRule[SparkPlan] {
override def shift(node: SparkPlan): Iterable[SparkPlan] = {
val out = List(delegate.impl(node))
out
diff --git a/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/transform/ImplementSingleNode.scala b/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/transform/ImplementSingleNode.scala
index 453337681..22edfaa5d 100644
--- a/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/transform/ImplementSingleNode.scala
+++ b/gluten-core/src/main/scala/org/apache/gluten/extension/columnar/transform/ImplementSingleNode.scala
@@ -295,7 +295,7 @@ object ImplementOthers {
// Children will be preserved as they are as children of the output node.
//
// Do not look-up on children on the input node in this rule. Otherwise
- // it may break ACBO which would group all the possible input nodes to
+ // it may break RAS which would group all the possible input nodes to
// search for validate candidates.
class ReplaceSingleNode() extends LogLevelUtil with Logging {
diff --git a/gluten-core/src/main/scala/org/apache/gluten/planner/GlutenOptimization.scala b/gluten-core/src/main/scala/org/apache/gluten/planner/GlutenOptimization.scala
index 5205358fb..ea45e1632 100644
--- a/gluten-core/src/main/scala/org/apache/gluten/planner/GlutenOptimization.scala
+++ b/gluten-core/src/main/scala/org/apache/gluten/planner/GlutenOptimization.scala
@@ -16,18 +16,18 @@
*/
package org.apache.gluten.planner
-import org.apache.gluten.cbo.{CboExplain, Optimization}
-import org.apache.gluten.cbo.rule.CboRule
import org.apache.gluten.planner.cost.GlutenCostModel
import org.apache.gluten.planner.metadata.GlutenMetadataModel
import org.apache.gluten.planner.plan.GlutenPlanModel
import org.apache.gluten.planner.property.GlutenPropertyModel
import org.apache.gluten.planner.rule.GlutenRules
+import org.apache.gluten.ras.{Optimization, RasExplain}
+import org.apache.gluten.ras.rule.RasRule
import org.apache.spark.sql.execution.SparkPlan
object GlutenOptimization {
- private object GlutenExplain extends CboExplain[SparkPlan] {
+ private object GlutenExplain extends RasExplain[SparkPlan] {
override def describeNode(node: SparkPlan): String = node.nodeName
}
@@ -38,16 +38,16 @@ object GlutenOptimization {
GlutenMetadataModel(),
GlutenPropertyModel(),
GlutenExplain,
- CboRule.Factory.reuse(GlutenRules()))
+ RasRule.Factory.reuse(GlutenRules()))
}
- def apply(rules: Seq[CboRule[SparkPlan]]): Optimization[SparkPlan] = {
+ def apply(rules: Seq[RasRule[SparkPlan]]): Optimization[SparkPlan] = {
Optimization[SparkPlan](
GlutenPlanModel(),
GlutenCostModel(),
GlutenMetadataModel(),
GlutenPropertyModel(),
GlutenExplain,
- CboRule.Factory.reuse(rules))
+ RasRule.Factory.reuse(rules))
}
}
diff --git a/gluten-core/src/main/scala/org/apache/gluten/planner/cost/GlutenCost.scala b/gluten-core/src/main/scala/org/apache/gluten/planner/cost/GlutenCost.scala
index b3ac64caf..72c1cb8b4 100644
--- a/gluten-core/src/main/scala/org/apache/gluten/planner/cost/GlutenCost.scala
+++ b/gluten-core/src/main/scala/org/apache/gluten/planner/cost/GlutenCost.scala
@@ -16,6 +16,6 @@
*/
package org.apache.gluten.planner.cost
-import org.apache.gluten.cbo.Cost
+import org.apache.gluten.ras.Cost
case class GlutenCost(value: Long) extends Cost
diff --git a/gluten-core/src/main/scala/org/apache/gluten/planner/cost/GlutenCostModel.scala b/gluten-core/src/main/scala/org/apache/gluten/planner/cost/GlutenCostModel.scala
index 85ae85266..e1295480c 100644
--- a/gluten-core/src/main/scala/org/apache/gluten/planner/cost/GlutenCostModel.scala
+++ b/gluten-core/src/main/scala/org/apache/gluten/planner/cost/GlutenCostModel.scala
@@ -16,9 +16,9 @@
*/
package org.apache.gluten.planner.cost
-import org.apache.gluten.cbo.{Cost, CostModel}
import org.apache.gluten.extension.columnar.ColumnarTransitions
import org.apache.gluten.planner.plan.GlutenPlanModel.GroupLeafExec
+import org.apache.gluten.ras.{Cost, CostModel}
import org.apache.gluten.utils.PlanUtil
import org.apache.spark.sql.execution.{ColumnarToRowExec, RowToColumnarExec, SparkPlan}
diff --git a/gluten-core/src/main/scala/org/apache/gluten/planner/metadata/GlutenMetadata.scala b/gluten-core/src/main/scala/org/apache/gluten/planner/metadata/GlutenMetadata.scala
index b6136fc73..7eb1d4b57 100644
--- a/gluten-core/src/main/scala/org/apache/gluten/planner/metadata/GlutenMetadata.scala
+++ b/gluten-core/src/main/scala/org/apache/gluten/planner/metadata/GlutenMetadata.scala
@@ -16,7 +16,7 @@
*/
package org.apache.gluten.planner.metadata
-import org.apache.gluten.cbo.Metadata
+import org.apache.gluten.ras.Metadata
import org.apache.spark.sql.catalyst.expressions.Attribute
diff --git a/gluten-core/src/main/scala/org/apache/gluten/planner/metadata/GlutenMetadataModel.scala b/gluten-core/src/main/scala/org/apache/gluten/planner/metadata/GlutenMetadataModel.scala
index 71bb445d3..6d1baa79d 100644
--- a/gluten-core/src/main/scala/org/apache/gluten/planner/metadata/GlutenMetadataModel.scala
+++ b/gluten-core/src/main/scala/org/apache/gluten/planner/metadata/GlutenMetadataModel.scala
@@ -16,9 +16,9 @@
*/
package org.apache.gluten.planner.metadata
-import org.apache.gluten.cbo.{Metadata, MetadataModel}
import org.apache.gluten.planner.metadata.GlutenMetadata.Schema
import org.apache.gluten.planner.plan.GlutenPlanModel.GroupLeafExec
+import org.apache.gluten.ras.{Metadata, MetadataModel}
import org.apache.spark.internal.Logging
import org.apache.spark.sql.execution.SparkPlan
diff --git a/gluten-core/src/main/scala/org/apache/gluten/planner/plan/GlutenPlanModel.scala b/gluten-core/src/main/scala/org/apache/gluten/planner/plan/GlutenPlanModel.scala
index a1a31346d..79fa040a4 100644
--- a/gluten-core/src/main/scala/org/apache/gluten/planner/plan/GlutenPlanModel.scala
+++ b/gluten-core/src/main/scala/org/apache/gluten/planner/plan/GlutenPlanModel.scala
@@ -16,11 +16,11 @@
*/
package org.apache.gluten.planner.plan
-import org.apache.gluten.cbo.{Metadata, PlanModel}
-import org.apache.gluten.cbo.property.PropertySet
import org.apache.gluten.planner.metadata.GlutenMetadata
import org.apache.gluten.planner.property.GlutenProperties
import org.apache.gluten.planner.property.GlutenProperties.Conventions
+import org.apache.gluten.ras.{Metadata, PlanModel}
+import org.apache.gluten.ras.property.PropertySet
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.catalyst.InternalRow
diff --git a/gluten-core/src/main/scala/org/apache/gluten/planner/property/GlutenPropertyModel.scala b/gluten-core/src/main/scala/org/apache/gluten/planner/property/GlutenPropertyModel.scala
index 12cea2c5c..54f4e3b84 100644
--- a/gluten-core/src/main/scala/org/apache/gluten/planner/property/GlutenPropertyModel.scala
+++ b/gluten-core/src/main/scala/org/apache/gluten/planner/property/GlutenPropertyModel.scala
@@ -17,11 +17,11 @@
package org.apache.gluten.planner.property
import org.apache.gluten.backendsapi.BackendsApiManager
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.rule.{CboRule, Shape, Shapes}
import org.apache.gluten.extension.columnar.ColumnarTransitions
import org.apache.gluten.planner.plan.GlutenPlanModel.GroupLeafExec
import org.apache.gluten.planner.property.GlutenProperties.{Convention, CONVENTION_DEF, ConventionEnforcerRule}
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.rule.{RasRule, Shape, Shapes}
import org.apache.gluten.sql.shims.SparkShimLoader
import org.apache.gluten.utils.PlanUtil
@@ -55,7 +55,7 @@ object GlutenProperties {
}
}
- case class ConventionEnforcerRule(reqConv: Convention) extends CboRule[SparkPlan] {
+ case class ConventionEnforcerRule(reqConv: Convention) extends RasRule[SparkPlan] {
override def shift(node: SparkPlan): Iterable[SparkPlan] = {
val conv = CONVENTION_DEF.getProperty(node)
if (conv == reqConv) {
diff --git a/gluten-core/src/main/scala/org/apache/gluten/planner/rule/GlutenRules.scala b/gluten-core/src/main/scala/org/apache/gluten/planner/rule/GlutenRules.scala
index 7c7386d43..59250c563 100644
--- a/gluten-core/src/main/scala/org/apache/gluten/planner/rule/GlutenRules.scala
+++ b/gluten-core/src/main/scala/org/apache/gluten/planner/rule/GlutenRules.scala
@@ -16,12 +16,12 @@
*/
package org.apache.gluten.planner.rule
-import org.apache.gluten.cbo.rule.CboRule
+import org.apache.gluten.ras.rule.RasRule
import org.apache.spark.sql.execution.SparkPlan
object GlutenRules {
- def apply(): Seq[CboRule[SparkPlan]] = {
+ def apply(): Seq[RasRule[SparkPlan]] = {
List() // TODO
}
}
diff --git a/gluten-cbo/common/pom.xml b/gluten-ras/common/pom.xml
similarity index 75%
rename from gluten-cbo/common/pom.xml
rename to gluten-ras/common/pom.xml
index a5a023a86..963b350f7 100644
--- a/gluten-cbo/common/pom.xml
+++ b/gluten-ras/common/pom.xml
@@ -4,9 +4,9 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.gluten</groupId>
- <artifactId>gluten-cbo</artifactId>
+ <artifactId>gluten-ras</artifactId>
<version>1.2.0-SNAPSHOT</version>
</parent>
- <artifactId>gluten-cbo-common</artifactId>
- <name>Gluten Cbo Common</name>
+ <artifactId>gluten-ras-common</artifactId>
+ <name>Gluten Ras Common</name>
</project>
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CostModel.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/CostModel.scala
similarity index 96%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CostModel.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/CostModel.scala
index fc209f253..cc259cd01 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CostModel.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/CostModel.scala
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
trait Cost
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/MetadataModel.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/MetadataModel.scala
similarity index 97%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/MetadataModel.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/MetadataModel.scala
index 3bf749866..d2056746c 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/MetadataModel.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/MetadataModel.scala
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
/**
* Metadata defines the common traits among nodes in one single cluster. E.g. Schema, statistics.
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/PlanModel.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/PlanModel.scala
similarity index 93%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/PlanModel.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/PlanModel.scala
index 9388ee8b6..34924ccbf 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/PlanModel.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/PlanModel.scala
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.property.PropertySet
+import org.apache.gluten.ras.property.PropertySet
trait PlanModel[T <: AnyRef] {
// Trivial tree operations.
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/PropertyModel.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/PropertyModel.scala
similarity index 91%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/PropertyModel.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/PropertyModel.scala
index a89cb1286..e2ba99136 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/PropertyModel.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/PropertyModel.scala
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.rule.CboRule
+import org.apache.gluten.ras.rule.RasRule
// TODO Use class tags to restrict runtime user-defined class types.
@@ -31,7 +31,7 @@ trait PropertyDef[T <: AnyRef, P <: Property[T]] {
}
trait EnforcerRuleFactory[T <: AnyRef] {
- def newEnforcerRules(constraint: Property[T]): Seq[CboRule[T]]
+ def newEnforcerRules(constraint: Property[T]): Seq[RasRule[T]]
}
trait PropertyModel[T <: AnyRef] {
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/Cbo.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/Ras.scala
similarity index 76%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/Cbo.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/Ras.scala
index 372e390cf..6832d07c5 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/Cbo.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/Ras.scala
@@ -14,26 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.property.PropertySet
-import org.apache.gluten.cbo.rule.CboRule
+import org.apache.gluten.ras.property.PropertySet
+import org.apache.gluten.ras.rule.RasRule
import scala.collection.mutable
/**
- * Entrypoint of ACBO (Advanced CBO)'s search engine. See basic introduction of ACBO:
+ * Entrypoint of RAS (relational algebra selector)'s search engine. See basic introduction of RAS:
* https://github.com/apache/incubator-gluten/issues/5057.
*/
trait Optimization[T <: AnyRef] {
def newPlanner(
plan: T,
constraintSet: PropertySet[T],
- altConstraintSets: Seq[PropertySet[T]]): CboPlanner[T]
+ altConstraintSets: Seq[PropertySet[T]]): RasPlanner[T]
def propSetsOf(plan: T): PropertySet[T]
- def withNewConfig(confFunc: CboConfig => CboConfig): Optimization[T]
+ def withNewConfig(confFunc: RasConfig => RasConfig): Optimization[T]
}
object Optimization {
@@ -42,34 +42,34 @@ object Optimization {
costModel: CostModel[T],
metadataModel: MetadataModel[T],
propertyModel: PropertyModel[T],
- explain: CboExplain[T],
- ruleFactory: CboRule.Factory[T]): Optimization[T] = {
- Cbo(planModel, costModel, metadataModel, propertyModel, explain, ruleFactory)
+ explain: RasExplain[T],
+ ruleFactory: RasRule.Factory[T]): Optimization[T] = {
+ Ras(planModel, costModel, metadataModel, propertyModel, explain, ruleFactory)
}
implicit class OptimizationImplicits[T <: AnyRef](opt: Optimization[T]) {
- def newPlanner(plan: T): CboPlanner[T] = {
+ def newPlanner(plan: T): RasPlanner[T] = {
opt.newPlanner(plan, opt.propSetsOf(plan), List.empty)
}
- def newPlanner(plan: T, constraintSet: PropertySet[T]): CboPlanner[T] = {
+ def newPlanner(plan: T, constraintSet: PropertySet[T]): RasPlanner[T] = {
opt.newPlanner(plan, constraintSet, List.empty)
}
}
}
-class Cbo[T <: AnyRef] private (
- val config: CboConfig,
+class Ras[T <: AnyRef] private (
+ val config: RasConfig,
val planModel: PlanModel[T],
val costModel: CostModel[T],
val metadataModel: MetadataModel[T],
val propertyModel: PropertyModel[T],
- val explain: CboExplain[T],
- val ruleFactory: CboRule.Factory[T])
+ val explain: RasExplain[T],
+ val ruleFactory: RasRule.Factory[T])
extends Optimization[T] {
- import Cbo._
+ import Ras._
- override def withNewConfig(confFunc: CboConfig => CboConfig): Cbo[T] = {
- new Cbo(
+ override def withNewConfig(confFunc: RasConfig => RasConfig): Ras[T] = {
+ new Ras(
confFunc(config),
planModel,
costModel,
@@ -128,13 +128,13 @@ class Cbo[T <: AnyRef] private (
override def newPlanner(
plan: T,
constraintSet: PropertySet[T],
- altConstraintSets: Seq[PropertySet[T]]): CboPlanner[T] = {
- CboPlanner(this, altConstraintSets, constraintSet, plan)
+ altConstraintSets: Seq[PropertySet[T]]): RasPlanner[T] = {
+ RasPlanner(this, altConstraintSets, constraintSet, plan)
}
override def propSetsOf(plan: T): PropertySet[T] = propertySetFactory().get(plan)
- private[cbo] def withNewChildren(node: T, newChildren: Seq[T]): T = {
+ private[ras] def withNewChildren(node: T, newChildren: Seq[T]): T = {
val oldChildren = planModel.childrenOf(node)
assert(newChildren.size == oldChildren.size)
val out = planModel.withNewChildren(node, newChildren)
@@ -142,47 +142,47 @@ class Cbo[T <: AnyRef] private (
out
}
- private[cbo] def isGroupLeaf(node: T): Boolean = {
+ private[ras] def isGroupLeaf(node: T): Boolean = {
planModel.isGroupLeaf(node)
}
- private[cbo] def isLeaf(node: T): Boolean = {
+ private[ras] def isLeaf(node: T): Boolean = {
planModel.childrenOf(node).isEmpty
}
- private[cbo] def isCanonical(node: T): Boolean = {
+ private[ras] def isCanonical(node: T): Boolean = {
assert(!planModel.isGroupLeaf(node))
planModel.childrenOf(node).forall(child => planModel.isGroupLeaf(child))
}
- private[cbo] def getChildrenGroupIds(n: T): Seq[Int] = {
+ private[ras] def getChildrenGroupIds(n: T): Seq[Int] = {
assert(isCanonical(n))
planModel
.childrenOf(n)
.map(child => planModel.getGroupId(child))
}
- private[cbo] def propertySetFactory(): PropertySetFactory[T] = propSetFactory
+ private[ras] def propertySetFactory(): PropertySetFactory[T] = propSetFactory
- private[cbo] def dummyGroupLeaf(): T = {
+ private[ras] def dummyGroupLeaf(): T = {
dummyGroup
}
- private[cbo] def getInfCost(): Cost = infCost
+ private[ras] def getInfCost(): Cost = infCost
- private[cbo] def isInfCost(cost: Cost) = costModel.costComparator().equiv(cost, infCost)
+ private[ras] def isInfCost(cost: Cost) = costModel.costComparator().equiv(cost, infCost)
}
-object Cbo {
- private[cbo] def apply[T <: AnyRef](
+object Ras {
+ private[ras] def apply[T <: AnyRef](
planModel: PlanModel[T],
costModel: CostModel[T],
metadataModel: MetadataModel[T],
propertyModel: PropertyModel[T],
- explain: CboExplain[T],
- ruleFactory: CboRule.Factory[T]): Cbo[T] = {
- new Cbo[T](
- CboConfig(),
+ explain: RasExplain[T],
+ ruleFactory: RasRule.Factory[T]): Ras[T] = {
+ new Ras[T](
+ RasConfig(),
planModel,
costModel,
metadataModel,
@@ -197,11 +197,11 @@ object Cbo {
}
private object PropertySetFactory {
- def apply[T <: AnyRef](cbo: Cbo[T]): PropertySetFactory[T] = new PropertySetFactoryImpl[T](cbo)
+ def apply[T <: AnyRef](ras: Ras[T]): PropertySetFactory[T] = new PropertySetFactoryImpl[T](ras)
- private class PropertySetFactoryImpl[T <: AnyRef](val cbo: Cbo[T])
+ private class PropertySetFactoryImpl[T <: AnyRef](val ras: Ras[T])
extends PropertySetFactory[T] {
- private val propDefs: Seq[PropertyDef[T, _ <: Property[T]]] = cbo.propertyModel.propertyDefs
+ private val propDefs: Seq[PropertyDef[T, _ <: Property[T]]] = ras.propertyModel.propertyDefs
override def get(node: T): PropertySet[T] = {
val m: Map[PropertyDef[T, _ <: Property[T]], Property[T]] =
@@ -213,7 +213,7 @@ object Cbo {
constraintSet: PropertySet[T],
node: T): Seq[PropertySet[T]] = {
val builder: Seq[mutable.Map[PropertyDef[T, _ <: Property[T]], Property[T]]] =
- cbo.planModel
+ ras.planModel
.childrenOf(node)
.map(_ => mutable.Map[PropertyDef[T, _ <: Property[T]], Property[T]]())
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboCluster.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasCluster.scala
similarity index 61%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboCluster.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasCluster.scala
index 4a3d318cc..63b8b1e68 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboCluster.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasCluster.scala
@@ -14,44 +14,46 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.memo.MemoTable
-import org.apache.gluten.cbo.property.PropertySet
+import org.apache.gluten.ras.memo.MemoTable
+import org.apache.gluten.ras.property.PropertySet
import scala.collection.mutable
-trait CboClusterKey {
+trait RasClusterKey {
def metadata: Metadata
}
-object CboClusterKey {
- implicit class CboClusterKeyImplicits[T <: AnyRef](key: CboClusterKey) {
+object RasClusterKey {
+ implicit class RasClusterKeyImplicits[T <: AnyRef](key: RasClusterKey) {
def propSets(memoTable: MemoTable[T]): Set[PropertySet[T]] = {
memoTable.getClusterPropSets(key)
}
}
}
-trait CboCluster[T <: AnyRef] {
+trait RasCluster[T <: AnyRef] {
def nodes(): Iterable[CanonicalNode[T]]
}
-object CboCluster {
+object RasCluster {
// Node cluster.
- trait MutableCboCluster[T <: AnyRef] extends CboCluster[T] {
- def cbo(): Cbo[T]
+ trait MutableRasCluster[T <: AnyRef] extends RasCluster[T] {
+ def ras(): Ras[T]
def contains(t: CanonicalNode[T]): Boolean
def add(t: CanonicalNode[T]): Unit
}
- object MutableCboCluster {
- def apply[T <: AnyRef](cbo: Cbo[T], metadata: Metadata): MutableCboCluster[T] = {
- new RegularMutableCboCluster(cbo, metadata)
+ object MutableRasCluster {
+ def apply[T <: AnyRef](ras: Ras[T], metadata: Metadata): MutableRasCluster[T] = {
+ new RegularMutableRasCluster(ras, metadata)
}
- private class RegularMutableCboCluster[T <: AnyRef](val cbo: Cbo[T], metadata: Metadata)
- extends MutableCboCluster[T] {
+ private class RegularMutableRasCluster[T <: AnyRef](
+ override val ras: Ras[T],
+ metadata: Metadata)
+ extends MutableRasCluster[T] {
private val buffer: mutable.Set[CanonicalNode[T]] =
mutable.Set()
@@ -60,7 +62,7 @@ object CboCluster {
}
override def add(t: CanonicalNode[T]): Unit = {
- cbo.metadataModel.verify(metadata, cbo.metadataModel.metadataOf(t.self()))
+ ras.metadataModel.verify(metadata, ras.metadataModel.metadataOf(t.self()))
assert(!buffer.contains(t))
buffer += t
}
@@ -71,14 +73,14 @@ object CboCluster {
}
}
- case class ImmutableCboCluster[T <: AnyRef] private (
- cbo: Cbo[T],
+ case class ImmutableRasCluster[T <: AnyRef] private (
+ ras: Ras[T],
override val nodes: Set[CanonicalNode[T]])
- extends CboCluster[T]
+ extends RasCluster[T]
- object ImmutableCboCluster {
- def apply[T <: AnyRef](cbo: Cbo[T], cluster: CboCluster[T]): ImmutableCboCluster[T] = {
- ImmutableCboCluster(cbo, cluster.nodes().toSet)
+ object ImmutableRasCluster {
+ def apply[T <: AnyRef](ras: Ras[T], cluster: RasCluster[T]): ImmutableRasCluster[T] = {
+ ImmutableRasCluster(ras, cluster.nodes().toSet)
}
}
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboConfig.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasConfig.scala
similarity index 89%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboConfig.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasConfig.scala
index 25775ae45..10e1c1248 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboConfig.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasConfig.scala
@@ -14,15 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.CboConfig._
+import org.apache.gluten.ras.RasConfig._
-case class CboConfig(
+case class RasConfig(
plannerType: PlannerType = PlannerType.Dp
)
-object CboConfig {
+object RasConfig {
sealed trait PlannerType
object PlannerType {
case object Exhaustive extends PlannerType
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboExplain.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasExplain.scala
similarity index 93%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboExplain.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasExplain.scala
index 763ad1ddc..9bc58e613 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboExplain.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasExplain.scala
@@ -14,8 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-trait CboExplain[T <: AnyRef] {
+trait RasExplain[T <: AnyRef] {
def describeNode(node: T): String
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboGroup.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasGroup.scala
similarity index 66%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboGroup.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasGroup.scala
index 300798e58..b5e9c9891 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboGroup.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasGroup.scala
@@ -14,43 +14,43 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.memo.MemoStore
-import org.apache.gluten.cbo.property.PropertySet
+import org.apache.gluten.ras.memo.MemoStore
+import org.apache.gluten.ras.property.PropertySet
-trait CboGroup[T <: AnyRef] {
+trait RasGroup[T <: AnyRef] {
def id(): Int
- def clusterKey(): CboClusterKey
+ def clusterKey(): RasClusterKey
def propSet(): PropertySet[T]
def self(): T
def nodes(store: MemoStore[T]): Iterable[CanonicalNode[T]]
}
-object CboGroup {
+object RasGroup {
def apply[T <: AnyRef](
- cbo: Cbo[T],
- clusterKey: CboClusterKey,
+ ras: Ras[T],
+ clusterKey: RasClusterKey,
id: Int,
- propSet: PropertySet[T]): CboGroup[T] = {
- new CboGroupImpl[T](cbo, clusterKey, id, propSet)
+ propSet: PropertySet[T]): RasGroup[T] = {
+ new RasGroupImpl[T](ras, clusterKey, id, propSet)
}
- private class CboGroupImpl[T <: AnyRef](
- cbo: Cbo[T],
- clusterKey: CboClusterKey,
+ private class RasGroupImpl[T <: AnyRef](
+ ras: Ras[T],
+ clusterKey: RasClusterKey,
override val id: Int,
override val propSet: PropertySet[T])
- extends CboGroup[T] {
- private val groupLeaf: T = cbo.planModel.newGroupLeaf(id, clusterKey.metadata, propSet)
+ extends RasGroup[T] {
+ private val groupLeaf: T = ras.planModel.newGroupLeaf(id, clusterKey.metadata, propSet)
- override def clusterKey(): CboClusterKey = clusterKey
+ override def clusterKey(): RasClusterKey = clusterKey
override def self(): T = groupLeaf
override def nodes(store: MemoStore[T]): Iterable[CanonicalNode[T]] = {
store.getCluster(clusterKey).nodes().filter(n => n.propSet().satisfies(propSet))
}
override def toString(): String = {
- s"CboGroup(id=$id, clusterKey=$clusterKey, propSet=$propSet))"
+ s"RasGroup(id=$id, clusterKey=$clusterKey, propSet=$propSet))"
}
}
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboNode.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasNode.scala
similarity index 68%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboNode.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasNode.scala
index 90bfb5edb..5f18f96a7 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboNode.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasNode.scala
@@ -14,18 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.property.PropertySet
+import org.apache.gluten.ras.property.PropertySet
-trait CboNode[T <: AnyRef] {
- def cbo(): Cbo[T]
+trait RasNode[T <: AnyRef] {
+ def ras(): Ras[T]
def self(): T
def propSet(): PropertySet[T]
}
-object CboNode {
- implicit class CboNodeImplicits[T <: AnyRef](node: CboNode[T]) {
+object RasNode {
+ implicit class RasNodeImplicits[T <: AnyRef](node: RasNode[T]) {
def isCanonical: Boolean = {
node.isInstanceOf[CanonicalNode[T]]
}
@@ -44,64 +44,64 @@ object CboNode {
}
}
-trait CanonicalNode[T <: AnyRef] extends CboNode[T] {
+trait CanonicalNode[T <: AnyRef] extends RasNode[T] {
def childrenCount: Int
}
object CanonicalNode {
- def apply[T <: AnyRef](cbo: Cbo[T], canonical: T): CanonicalNode[T] = {
- assert(cbo.isCanonical(canonical))
- val propSet = cbo.propSetsOf(canonical)
- val children = cbo.planModel.childrenOf(canonical)
- CanonicalNodeImpl[T](cbo, canonical, propSet, children.size)
+ def apply[T <: AnyRef](ras: Ras[T], canonical: T): CanonicalNode[T] = {
+ assert(ras.isCanonical(canonical))
+ val propSet = ras.propSetsOf(canonical)
+ val children = ras.planModel.childrenOf(canonical)
+ CanonicalNodeImpl[T](ras, canonical, propSet, children.size)
}
- // We put CboNode's API methods that accept mutable input in implicit definition.
+ // We put RasNode's API methods that accept mutable input in implicit definition.
// Do not break this rule during further development.
implicit class CanonicalNodeImplicits[T <: AnyRef](node: CanonicalNode[T]) {
def isLeaf(): Boolean = {
node.childrenCount == 0
}
- def getChildrenGroups(allGroups: Int => CboGroup[T]): Seq[GroupNode[T]] = {
- val cbo = node.cbo()
- cbo.getChildrenGroupIds(node.self()).map(allGroups(_)).map(g => GroupNode(cbo, g))
+ def getChildrenGroups(allGroups: Int => RasGroup[T]): Seq[GroupNode[T]] = {
+ val ras = node.ras()
+ ras.getChildrenGroupIds(node.self()).map(allGroups(_)).map(g => GroupNode(ras, g))
}
def getChildrenGroupIds(): Seq[Int] = {
- val cbo = node.cbo()
- cbo.getChildrenGroupIds(node.self())
+ val ras = node.ras()
+ ras.getChildrenGroupIds(node.self())
}
}
private case class CanonicalNodeImpl[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
override val self: T,
override val propSet: PropertySet[T],
override val childrenCount: Int)
extends CanonicalNode[T]
}
-trait GroupNode[T <: AnyRef] extends CboNode[T] {
+trait GroupNode[T <: AnyRef] extends RasNode[T] {
def groupId(): Int
}
object GroupNode {
- def apply[T <: AnyRef](cbo: Cbo[T], group: CboGroup[T]): GroupNode[T] = {
- GroupNodeImpl[T](cbo, group.self(), group.propSet(), group.id())
+ def apply[T <: AnyRef](ras: Ras[T], group: RasGroup[T]): GroupNode[T] = {
+ GroupNodeImpl[T](ras, group.self(), group.propSet(), group.id())
}
private case class GroupNodeImpl[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
override val self: T,
override val propSet: PropertySet[T],
override val groupId: Int)
extends GroupNode[T] {}
- // We put CboNode's API methods that accept mutable input in implicit definition.
+ // We put RasNode's API methods that accept mutable input in implicit definition.
// Do not break this rule during further development.
implicit class GroupNodeImplicits[T <: AnyRef](gn: GroupNode[T]) {
- def group(allGroups: Int => CboGroup[T]): CboGroup[T] = {
+ def group(allGroups: Int => RasGroup[T]): RasGroup[T] = {
allGroups(gn.groupId())
}
}
@@ -121,16 +121,16 @@ object InGroupNode {
}
trait InClusterNode[T <: AnyRef] {
- def clusterKey: CboClusterKey
+ def clusterKey: RasClusterKey
def can: CanonicalNode[T]
}
object InClusterNode {
- def apply[T <: AnyRef](clusterId: CboClusterKey, node: CanonicalNode[T]): InClusterNode[T] = {
+ def apply[T <: AnyRef](clusterId: RasClusterKey, node: CanonicalNode[T]): InClusterNode[T] = {
InClusterNodeImpl(clusterId, node)
}
private case class InClusterNodeImpl[T <: AnyRef](
- clusterKey: CboClusterKey,
+ clusterKey: RasClusterKey,
can: CanonicalNode[T])
extends InClusterNode[T]
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboPlanner.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasPlanner.scala
similarity index 71%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboPlanner.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasPlanner.scala
index 04d7e3374..0665d3661 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/CboPlanner.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/RasPlanner.scala
@@ -14,34 +14,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.CboConfig.PlannerType
-import org.apache.gluten.cbo.dp.DpPlanner
-import org.apache.gluten.cbo.exaustive.ExhaustivePlanner
-import org.apache.gluten.cbo.memo.MemoState
-import org.apache.gluten.cbo.path.CboPath
-import org.apache.gluten.cbo.property.PropertySet
-import org.apache.gluten.cbo.vis.GraphvizVisualizer
+import org.apache.gluten.ras.RasConfig.PlannerType
+import org.apache.gluten.ras.dp.DpPlanner
+import org.apache.gluten.ras.exaustive.ExhaustivePlanner
+import org.apache.gluten.ras.memo.MemoState
+import org.apache.gluten.ras.path.RasPath
+import org.apache.gluten.ras.property.PropertySet
+import org.apache.gluten.ras.vis.GraphvizVisualizer
import scala.collection.mutable
-trait CboPlanner[T <: AnyRef] {
+trait RasPlanner[T <: AnyRef] {
def plan(): T
def newState(): PlannerState[T]
}
-object CboPlanner {
+object RasPlanner {
def apply[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
altConstraintSets: Seq[PropertySet[T]],
constraintSet: PropertySet[T],
- plan: T): CboPlanner[T] = {
- cbo.config.plannerType match {
+ plan: T): RasPlanner[T] = {
+ ras.config.plannerType match {
case PlannerType.Exhaustive =>
- ExhaustivePlanner(cbo, altConstraintSets, constraintSet, plan)
+ ExhaustivePlanner(ras, altConstraintSets, constraintSet, plan)
case PlannerType.Dp =>
- DpPlanner(cbo, altConstraintSets, constraintSet, plan)
+ DpPlanner(ras, altConstraintSets, constraintSet, plan)
}
}
}
@@ -57,14 +57,14 @@ trait Best[T <: AnyRef] {
object Best {
def apply[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
rootGroupId: Int,
bestPath: KnownCostPath[T],
winnerNodes: Seq[InGroupNode[T]],
costs: InGroupNode[T] => Option[Cost]): Best[T] = {
val bestNodes = mutable.Set[InGroupNode[T]]()
- def dfs(groupId: Int, cursor: CboPath.PathNode[T]): Unit = {
+ def dfs(groupId: Int, cursor: RasPath.PathNode[T]): Unit = {
val can = cursor.self().asCanonical()
bestNodes += InGroupNode(groupId, can)
cursor.zipChildrenWithGroupIds().foreach {
@@ -73,15 +73,15 @@ object Best {
}
}
- dfs(rootGroupId, bestPath.cboPath.node())
+ dfs(rootGroupId, bestPath.rasPath.node())
val winnerNodeSet = winnerNodes.toSet
- BestImpl(cbo, rootGroupId, bestPath, bestNodes.toSet, winnerNodeSet, costs)
+ BestImpl(ras, rootGroupId, bestPath, bestNodes.toSet, winnerNodeSet, costs)
}
private case class BestImpl[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
override val rootGroupId: Int,
override val path: KnownCostPath[T],
override val bestNodes: Set[InGroupNode[T]],
@@ -90,20 +90,20 @@ object Best {
extends Best[T]
trait KnownCostPath[T <: AnyRef] {
- def cboPath: CboPath[T]
+ def rasPath: RasPath[T]
def cost: Cost
}
object KnownCostPath {
- def apply[T <: AnyRef](cbo: Cbo[T], cboPath: CboPath[T]): KnownCostPath[T] = {
- KnownCostPathImpl(cboPath, cbo.costModel.costOf(cboPath.plan()))
+ def apply[T <: AnyRef](ras: Ras[T], rasPath: RasPath[T]): KnownCostPath[T] = {
+ KnownCostPathImpl(rasPath, ras.costModel.costOf(rasPath.plan()))
}
- def apply[T <: AnyRef](cboPath: CboPath[T], cost: Cost): KnownCostPath[T] = {
- KnownCostPathImpl(cboPath, cost)
+ def apply[T <: AnyRef](rasPath: RasPath[T], cost: Cost): KnownCostPath[T] = {
+ KnownCostPathImpl(rasPath, cost)
}
- private case class KnownCostPathImpl[T <: AnyRef](cboPath: CboPath[T], cost: Cost)
+ private case class KnownCostPathImpl[T <: AnyRef](rasPath: RasPath[T], cost: Cost)
extends KnownCostPath[T]
}
@@ -120,7 +120,7 @@ object Best {
}
trait PlannerState[T <: AnyRef] {
- def cbo(): Cbo[T]
+ def ras(): Ras[T]
def memoState(): MemoState[T]
def rootGroupId(): Int
def best(): Best[T]
@@ -128,11 +128,11 @@ trait PlannerState[T <: AnyRef] {
object PlannerState {
def apply[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
memoState: MemoState[T],
rootGroupId: Int,
best: Best[T]): PlannerState[T] = {
- PlannerStateImpl(cbo, memoState, rootGroupId, best)
+ PlannerStateImpl(ras, memoState, rootGroupId, best)
}
implicit class PlannerStateImplicits[T <: AnyRef](state: PlannerState[T]) {
@@ -141,12 +141,12 @@ object PlannerState {
}
private def formatGraphvizWithBest(): String = {
- GraphvizVisualizer(state.cbo(), state.memoState(), state.best()).format()
+ GraphvizVisualizer(state.ras(), state.memoState(), state.best()).format()
}
}
private case class PlannerStateImpl[T <: AnyRef] private (
- override val cbo: Cbo[T],
+ override val ras: Ras[T],
override val memoState: MemoState[T],
override val rootGroupId: Int,
override val best: Best[T])
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/best/BestFinder.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/best/BestFinder.scala
similarity index 75%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/best/BestFinder.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/best/BestFinder.scala
index bb8abf283..4ec7e09f5 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/best/BestFinder.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/best/BestFinder.scala
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.best
+package org.apache.gluten.ras.best
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.Best.KnownCostPath
-import org.apache.gluten.cbo.dp.DpGroupAlgo
-import org.apache.gluten.cbo.memo.MemoState
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.Best.KnownCostPath
+import org.apache.gluten.ras.dp.DpGroupAlgo
+import org.apache.gluten.ras.memo.MemoState
import scala.collection.mutable
@@ -28,15 +28,15 @@ trait BestFinder[T <: AnyRef] {
}
object BestFinder {
- def apply[T <: AnyRef](cbo: Cbo[T], memoState: MemoState[T]): BestFinder[T] = {
- unsafe(cbo, memoState, DpGroupAlgo.Adjustment.none())
+ def apply[T <: AnyRef](ras: Ras[T], memoState: MemoState[T]): BestFinder[T] = {
+ unsafe(ras, memoState, DpGroupAlgo.Adjustment.none())
}
def unsafe[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
memoState: MemoState[T],
adjustment: DpGroupAlgo.Adjustment[T]): BestFinder[T] = {
- new GroupBasedBestFinder[T](cbo, memoState, adjustment)
+ new GroupBasedBestFinder[T](ras, memoState, adjustment)
}
case class KnownCostGroup[T <: AnyRef](
@@ -48,12 +48,12 @@ object BestFinder {
case class KnownCostCluster[T <: AnyRef](groupToCost: Map[Int, KnownCostGroup[T]])
private[best] def newBest[T <: AnyRef](
- cbo: Cbo[T],
- allGroups: Seq[CboGroup[T]],
- group: CboGroup[T],
+ ras: Ras[T],
+ allGroups: Seq[RasGroup[T]],
+ group: RasGroup[T],
groupToCosts: Map[Int, KnownCostGroup[T]]): Best[T] = {
val bestPath = groupToCosts(group.id()).best()
- val bestRoot = bestPath.cboPath.node()
+ val bestRoot = bestPath.rasPath.node()
val winnerNodes = groupToCosts.map { case (id, g) => InGroupNode(id, g.bestNode) }.toSeq
val costsMap = mutable.Map[InGroupNode[T], Cost]()
groupToCosts.foreach {
@@ -63,6 +63,6 @@ object BestFinder {
costsMap += (InGroupNode(gid, n) -> c.cost)
}
}
- Best(cbo, group.id(), bestPath, winnerNodes, costsMap.get)
+ Best(ras, group.id(), bestPath, winnerNodes, costsMap.get)
}
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/best/GroupBasedBestFinder.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/best/GroupBasedBestFinder.scala
similarity index 73%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/best/GroupBasedBestFinder.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/best/GroupBasedBestFinder.scala
index a2bd60532..7d2d807ff 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/best/GroupBasedBestFinder.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/best/GroupBasedBestFinder.scala
@@ -14,18 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.best
+package org.apache.gluten.ras.best
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.Best.{BestNotFoundException, KnownCostPath}
-import org.apache.gluten.cbo.best.BestFinder.KnownCostGroup
-import org.apache.gluten.cbo.dp.{DpGroupAlgo, DpGroupAlgoDef}
-import org.apache.gluten.cbo.memo.MemoState
-import org.apache.gluten.cbo.path.{CboPath, PathKeySet}
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.Best.{BestNotFoundException, KnownCostPath}
+import org.apache.gluten.ras.best.BestFinder.KnownCostGroup
+import org.apache.gluten.ras.dp.{DpGroupAlgo, DpGroupAlgoDef}
+import org.apache.gluten.ras.memo.MemoState
+import org.apache.gluten.ras.path.{PathKeySet, RasPath}
// The best path's each sub-path is considered optimal in its own group.
private class GroupBasedBestFinder[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
memoState: MemoState[T],
adjustment: DpGroupAlgo.Adjustment[T])
extends BestFinder[T] {
@@ -41,11 +41,11 @@ private class GroupBasedBestFinder[T <: AnyRef](
s"Best path not found. Memo state (Graphviz): \n" +
s"${memoState.formatGraphvizWithoutBest(groupId)}")
}
- BestFinder.newBest(cbo, allGroups, group, groupToCosts)
+ BestFinder.newBest(ras, allGroups, group, groupToCosts)
}
- private def fillBests(group: CboGroup[T]): Map[Int, KnownCostGroup[T]] = {
- val algoDef = new AlgoDef(cbo, memoState)
+ private def fillBests(group: RasGroup[T]): Map[Int, KnownCostGroup[T]] = {
+ val algoDef = new AlgoDef(ras, memoState)
val solution = DpGroupAlgo.resolve(memoState, algoDef, adjustment, group)
val bests = allGroups.flatMap {
group =>
@@ -60,39 +60,39 @@ private class GroupBasedBestFinder[T <: AnyRef](
}
private object GroupBasedBestFinder {
- private[best] def algoDef[T <: AnyRef](cbo: Cbo[T], memoState: MemoState[T])
+ private[best] def algoDef[T <: AnyRef](ras: Ras[T], memoState: MemoState[T])
: DpGroupAlgoDef[T, Option[KnownCostPath[T]], Option[KnownCostGroup[T]]] = {
- new AlgoDef(cbo, memoState)
+ new AlgoDef(ras, memoState)
}
- private class AlgoDef[T <: AnyRef](cbo: Cbo[T], memoState: MemoState[T])
+ private class AlgoDef[T <: AnyRef](ras: Ras[T], memoState: MemoState[T])
extends DpGroupAlgoDef[T, Option[KnownCostPath[T]], Option[KnownCostGroup[T]]] {
private val allGroups = memoState.allGroups()
- private val costComparator = cbo.costModel.costComparator()
+ private val costComparator = ras.costModel.costComparator()
override def solveNode(
ign: InGroupNode[T],
- childrenGroupsOutput: CboGroup[T] => Option[KnownCostGroup[T]])
+ childrenGroupsOutput: RasGroup[T] => Option[KnownCostGroup[T]])
: Option[KnownCostPath[T]] = {
val can = ign.can
if (can.isLeaf()) {
- val path = CboPath.one(cbo, PathKeySet.trivial, allGroups, can)
- return Some(KnownCostPath(cbo, path))
+ val path = RasPath.one(ras, PathKeySet.trivial, allGroups, can)
+ return Some(KnownCostPath(ras, path))
}
val childrenGroups = can.getChildrenGroups(allGroups).map(gn => allGroups(gn.groupId()))
- val maybeBestChildrenPaths: Seq[Option[CboPath[T]]] = childrenGroups.map {
- childGroup => childrenGroupsOutput(childGroup).map(kcg => kcg.best().cboPath)
+ val maybeBestChildrenPaths: Seq[Option[RasPath[T]]] = childrenGroups.map {
+ childGroup => childrenGroupsOutput(childGroup).map(kcg => kcg.best().rasPath)
}
if (maybeBestChildrenPaths.exists(_.isEmpty)) {
// Node should only be solved when all children outputs exist.
return None
}
val bestChildrenPaths = maybeBestChildrenPaths.map(_.get)
- Some(KnownCostPath(cbo, path.CboPath(cbo, can, bestChildrenPaths).get))
+ Some(KnownCostPath(ras, path.RasPath(ras, can, bestChildrenPaths).get))
}
override def solveGroup(
- group: CboGroup[T],
+ group: RasGroup[T],
nodesOutput: InGroupNode[T] => Option[KnownCostPath[T]]): Option[KnownCostGroup[T]] = {
val nodes = group.nodes(memoState)
// Allow unsolved children nodes while solving group.
@@ -108,13 +108,13 @@ private object GroupBasedBestFinder {
.by((cp: KnownCostPath[T]) => cp.cost)(costComparator)
.min(left, right)
}
- Some(KnownCostGroup(flatNodesOutput, bestPath.cboPath.node().self().asCanonical()))
+ Some(KnownCostGroup(flatNodesOutput, bestPath.rasPath.node().self().asCanonical()))
}
override def solveNodeOnCycle(node: InGroupNode[T]): Option[KnownCostPath[T]] =
None
- override def solveGroupOnCycle(cluster: CboGroup[T]): Option[KnownCostGroup[T]] = {
+ override def solveGroupOnCycle(cluster: RasGroup[T]): Option[KnownCostGroup[T]] = {
None
}
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/dp/DpClusterAlgo.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/dp/DpClusterAlgo.scala
similarity index 74%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/dp/DpClusterAlgo.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/dp/DpClusterAlgo.scala
index 2403dadf0..95f453f47 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/dp/DpClusterAlgo.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/dp/DpClusterAlgo.scala
@@ -14,45 +14,45 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.dp
+package org.apache.gluten.ras.dp
-import org.apache.gluten.cbo.{CboClusterKey, InClusterNode}
-import org.apache.gluten.cbo.dp.DpZipperAlgo.Solution
-import org.apache.gluten.cbo.memo.MemoTable
+import org.apache.gluten.ras.{InClusterNode, RasClusterKey}
+import org.apache.gluten.ras.dp.DpZipperAlgo.Solution
+import org.apache.gluten.ras.memo.MemoTable
-// Dynamic programming algorithm to solve problem against a single CBO cluster that can be
+// Dynamic programming algorithm to solve problem against a single RAS cluster that can be
// broken down to sub problems for sub clusters.
//
// FIXME: Code is so similar with DpGroupAlgo.
trait DpClusterAlgoDef[T <: AnyRef, NodeOutput <: AnyRef, ClusterOutput <: AnyRef] {
def solveNode(
node: InClusterNode[T],
- childrenClustersOutput: CboClusterKey => ClusterOutput): NodeOutput
+ childrenClustersOutput: RasClusterKey => ClusterOutput): NodeOutput
def solveCluster(
- cluster: CboClusterKey,
+ cluster: RasClusterKey,
nodesOutput: InClusterNode[T] => NodeOutput): ClusterOutput
def solveNodeOnCycle(node: InClusterNode[T]): NodeOutput
- def solveClusterOnCycle(cluster: CboClusterKey): ClusterOutput
+ def solveClusterOnCycle(cluster: RasClusterKey): ClusterOutput
}
object DpClusterAlgo {
- trait Adjustment[T <: AnyRef] extends DpZipperAlgo.Adjustment[InClusterNode[T], CboClusterKey]
+ trait Adjustment[T <: AnyRef] extends DpZipperAlgo.Adjustment[InClusterNode[T], RasClusterKey]
object Adjustment {
private class None[T <: AnyRef] extends Adjustment[T] {
override def exploreChildX(
- panel: DpZipperAlgo.Adjustment.Panel[InClusterNode[T], CboClusterKey],
+ panel: DpZipperAlgo.Adjustment.Panel[InClusterNode[T], RasClusterKey],
x: InClusterNode[T]): Unit = {}
override def exploreParentY(
- panel: DpZipperAlgo.Adjustment.Panel[InClusterNode[T], CboClusterKey],
- y: CboClusterKey): Unit = {}
+ panel: DpZipperAlgo.Adjustment.Panel[InClusterNode[T], RasClusterKey],
+ y: RasClusterKey): Unit = {}
override def exploreChildY(
- panel: DpZipperAlgo.Adjustment.Panel[InClusterNode[T], CboClusterKey],
- y: CboClusterKey): Unit = {}
+ panel: DpZipperAlgo.Adjustment.Panel[InClusterNode[T], RasClusterKey],
+ y: RasClusterKey): Unit = {}
override def exploreParentX(
- panel: DpZipperAlgo.Adjustment.Panel[InClusterNode[T], CboClusterKey],
+ panel: DpZipperAlgo.Adjustment.Panel[InClusterNode[T], RasClusterKey],
x: InClusterNode[T]): Unit = {}
}
@@ -63,43 +63,43 @@ object DpClusterAlgo {
memoTable: MemoTable[T],
groupAlgoDef: DpClusterAlgoDef[T, NodeOutput, ClusterOutput],
adjustment: Adjustment[T],
- cluster: CboClusterKey)
- : Solution[InClusterNode[T], CboClusterKey, NodeOutput, ClusterOutput] = {
+ cluster: RasClusterKey)
+ : Solution[InClusterNode[T], RasClusterKey, NodeOutput, ClusterOutput] = {
DpZipperAlgo.resolve(new ZipperAlgoDefImpl(memoTable, groupAlgoDef), adjustment, cluster)
}
private class ZipperAlgoDefImpl[T <: AnyRef, NodeOutput <: AnyRef, ClusterOutput <: AnyRef](
memoTable: MemoTable[T],
clusterAlgoDef: DpClusterAlgoDef[T, NodeOutput, ClusterOutput])
- extends DpZipperAlgoDef[InClusterNode[T], CboClusterKey, NodeOutput, ClusterOutput] {
+ extends DpZipperAlgoDef[InClusterNode[T], RasClusterKey, NodeOutput, ClusterOutput] {
override def idOfX(x: InClusterNode[T]): Any = {
x
}
- override def idOfY(y: CboClusterKey): Any = {
+ override def idOfY(y: RasClusterKey): Any = {
y
}
- override def browseX(x: InClusterNode[T]): Iterable[CboClusterKey] = {
+ override def browseX(x: InClusterNode[T]): Iterable[RasClusterKey] = {
val allGroups = memoTable.allGroups()
x.can
.getChildrenGroups(allGroups)
.map(gn => allGroups(gn.groupId()).clusterKey())
}
- override def browseY(y: CboClusterKey): Iterable[InClusterNode[T]] = {
+ override def browseY(y: RasClusterKey): Iterable[InClusterNode[T]] = {
memoTable.getCluster(y).nodes().map(n => InClusterNode(y, n))
}
- override def solveX(x: InClusterNode[T], yOutput: CboClusterKey => ClusterOutput): NodeOutput =
+ override def solveX(x: InClusterNode[T], yOutput: RasClusterKey => ClusterOutput): NodeOutput =
clusterAlgoDef.solveNode(x, yOutput)
- override def solveY(y: CboClusterKey, xOutput: InClusterNode[T] => NodeOutput): ClusterOutput =
+ override def solveY(y: RasClusterKey, xOutput: InClusterNode[T] => NodeOutput): ClusterOutput =
clusterAlgoDef.solveCluster(y, xOutput)
override def solveXOnCycle(x: InClusterNode[T]): NodeOutput = clusterAlgoDef.solveNodeOnCycle(x)
- override def solveYOnCycle(y: CboClusterKey): ClusterOutput =
+ override def solveYOnCycle(y: RasClusterKey): ClusterOutput =
clusterAlgoDef.solveClusterOnCycle(y)
}
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/dp/DpGroupAlgo.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/dp/DpGroupAlgo.scala
similarity index 67%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/dp/DpGroupAlgo.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/dp/DpGroupAlgo.scala
index 7711fd675..6c1e998b6 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/dp/DpGroupAlgo.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/dp/DpGroupAlgo.scala
@@ -14,39 +14,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.dp
+package org.apache.gluten.ras.dp
-import org.apache.gluten.cbo.{CboGroup, InGroupNode}
-import org.apache.gluten.cbo.dp.DpZipperAlgo.Solution
-import org.apache.gluten.cbo.memo.MemoState
+import org.apache.gluten.ras.{InGroupNode, RasGroup}
+import org.apache.gluten.ras.dp.DpZipperAlgo.Solution
+import org.apache.gluten.ras.memo.MemoState
-// Dynamic programming algorithm to solve problem against a single CBO group that can be
+// Dynamic programming algorithm to solve problem against a single RAS group that can be
// broken down to sub problems for sub groups.
trait DpGroupAlgoDef[T <: AnyRef, NodeOutput <: AnyRef, GroupOutput <: AnyRef] {
- def solveNode(node: InGroupNode[T], childrenGroupsOutput: CboGroup[T] => GroupOutput): NodeOutput
- def solveGroup(group: CboGroup[T], nodesOutput: InGroupNode[T] => NodeOutput): GroupOutput
+ def solveNode(node: InGroupNode[T], childrenGroupsOutput: RasGroup[T] => GroupOutput): NodeOutput
+ def solveGroup(group: RasGroup[T], nodesOutput: InGroupNode[T] => NodeOutput): GroupOutput
def solveNodeOnCycle(node: InGroupNode[T]): NodeOutput
- def solveGroupOnCycle(cluster: CboGroup[T]): GroupOutput
+ def solveGroupOnCycle(cluster: RasGroup[T]): GroupOutput
}
object DpGroupAlgo {
- trait Adjustment[T <: AnyRef] extends DpZipperAlgo.Adjustment[InGroupNode[T], CboGroup[T]]
+ trait Adjustment[T <: AnyRef] extends DpZipperAlgo.Adjustment[InGroupNode[T], RasGroup[T]]
object Adjustment {
private class None[T <: AnyRef] extends Adjustment[T] {
override def exploreChildX(
- panel: DpZipperAlgo.Adjustment.Panel[InGroupNode[T], CboGroup[T]],
+ panel: DpZipperAlgo.Adjustment.Panel[InGroupNode[T], RasGroup[T]],
x: InGroupNode[T]): Unit = {}
override def exploreParentY(
- panel: DpZipperAlgo.Adjustment.Panel[InGroupNode[T], CboGroup[T]],
- y: CboGroup[T]): Unit = {}
+ panel: DpZipperAlgo.Adjustment.Panel[InGroupNode[T], RasGroup[T]],
+ y: RasGroup[T]): Unit = {}
override def exploreChildY(
- panel: DpZipperAlgo.Adjustment.Panel[InGroupNode[T], CboGroup[T]],
- y: CboGroup[T]): Unit = {}
+ panel: DpZipperAlgo.Adjustment.Panel[InGroupNode[T], RasGroup[T]],
+ y: RasGroup[T]): Unit = {}
override def exploreParentX(
- panel: DpZipperAlgo.Adjustment.Panel[InGroupNode[T], CboGroup[T]],
+ panel: DpZipperAlgo.Adjustment.Panel[InGroupNode[T], RasGroup[T]],
x: InGroupNode[T]): Unit = {}
}
@@ -57,39 +57,39 @@ object DpGroupAlgo {
memoState: MemoState[T],
groupAlgoDef: DpGroupAlgoDef[T, NodeOutput, GroupOutput],
adjustment: Adjustment[T],
- group: CboGroup[T]): Solution[InGroupNode[T], CboGroup[T], NodeOutput, GroupOutput] = {
+ group: RasGroup[T]): Solution[InGroupNode[T], RasGroup[T], NodeOutput, GroupOutput] = {
DpZipperAlgo.resolve(new ZipperAlgoDefImpl(memoState, groupAlgoDef), adjustment, group)
}
private class ZipperAlgoDefImpl[T <: AnyRef, NodeOutput <: AnyRef, GroupOutput <: AnyRef](
memoState: MemoState[T],
groupAlgoDef: DpGroupAlgoDef[T, NodeOutput, GroupOutput])
- extends DpZipperAlgoDef[InGroupNode[T], CboGroup[T], NodeOutput, GroupOutput] {
+ extends DpZipperAlgoDef[InGroupNode[T], RasGroup[T], NodeOutput, GroupOutput] {
override def idOfX(x: InGroupNode[T]): Any = {
x
}
- override def idOfY(y: CboGroup[T]): Any = {
+ override def idOfY(y: RasGroup[T]): Any = {
y.id()
}
- override def browseX(x: InGroupNode[T]): Iterable[CboGroup[T]] = {
+ override def browseX(x: InGroupNode[T]): Iterable[RasGroup[T]] = {
val allGroups = memoState.allGroups()
x.can.getChildrenGroups(allGroups).map(gn => allGroups(gn.groupId()))
}
- override def browseY(y: CboGroup[T]): Iterable[InGroupNode[T]] = {
+ override def browseY(y: RasGroup[T]): Iterable[InGroupNode[T]] = {
y.nodes(memoState).map(can => InGroupNode(y.id(), can))
}
- override def solveX(x: InGroupNode[T], yOutput: CboGroup[T] => GroupOutput): NodeOutput =
+ override def solveX(x: InGroupNode[T], yOutput: RasGroup[T] => GroupOutput): NodeOutput =
groupAlgoDef.solveNode(x, yOutput)
- override def solveY(y: CboGroup[T], xOutput: InGroupNode[T] => NodeOutput): GroupOutput =
+ override def solveY(y: RasGroup[T], xOutput: InGroupNode[T] => NodeOutput): GroupOutput =
groupAlgoDef.solveGroup(y, xOutput)
override def solveXOnCycle(x: InGroupNode[T]): NodeOutput = groupAlgoDef.solveNodeOnCycle(x)
- override def solveYOnCycle(y: CboGroup[T]): GroupOutput = groupAlgoDef.solveGroupOnCycle(y)
+ override def solveYOnCycle(y: RasGroup[T]): GroupOutput = groupAlgoDef.solveGroupOnCycle(y)
}
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/dp/DpPlanner.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/dp/DpPlanner.scala
similarity index 73%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/dp/DpPlanner.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/dp/DpPlanner.scala
index 827c185f4..391e7f196 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/dp/DpPlanner.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/dp/DpPlanner.scala
@@ -14,29 +14,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.dp
+package org.apache.gluten.ras.dp
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.Best.KnownCostPath
-import org.apache.gluten.cbo.best.BestFinder
-import org.apache.gluten.cbo.dp.DpZipperAlgo.Adjustment.Panel
-import org.apache.gluten.cbo.memo.{Memo, MemoTable}
-import org.apache.gluten.cbo.path.{CboPath, PathFinder}
-import org.apache.gluten.cbo.property.PropertySet
-import org.apache.gluten.cbo.rule.{EnforcerRuleSet, RuleApplier, Shape}
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.Best.KnownCostPath
+import org.apache.gluten.ras.best.BestFinder
+import org.apache.gluten.ras.dp.DpZipperAlgo.Adjustment.Panel
+import org.apache.gluten.ras.memo.{Memo, MemoTable}
+import org.apache.gluten.ras.path.{PathFinder, RasPath}
+import org.apache.gluten.ras.property.PropertySet
+import org.apache.gluten.ras.rule.{EnforcerRuleSet, RuleApplier, Shape}
// TODO: Branch and bound pruning.
private class DpPlanner[T <: AnyRef] private (
- cbo: Cbo[T],
+ ras: Ras[T],
altConstraintSets: Seq[PropertySet[T]],
constraintSet: PropertySet[T],
plan: T)
- extends CboPlanner[T] {
+ extends RasPlanner[T] {
import DpPlanner._
- private val memo = Memo.unsafe(cbo)
- private val rules = cbo.ruleFactory.create().map(rule => RuleApplier(cbo, memo, rule))
- private val enforcerRuleSet = EnforcerRuleSet[T](cbo, memo)
+ private val memo = Memo.unsafe(ras)
+ private val rules = ras.ruleFactory.create().map(rule => RuleApplier(ras, memo, rule))
+ private val enforcerRuleSet = EnforcerRuleSet[T](ras, memo)
private lazy val rootGroupId: Int = {
memo.memorize(plan, constraintSet).id()
@@ -51,31 +51,31 @@ private class DpPlanner[T <: AnyRef] private (
}
override def plan(): T = {
- best._2.cboPath.plan()
+ best._2.rasPath.plan()
}
override def newState(): PlannerState[T] = {
val foundBest = best._1
- PlannerState(cbo, memo.newState(), rootGroupId, foundBest)
+ PlannerState(ras, memo.newState(), rootGroupId, foundBest)
}
private def findBest(memoTable: MemoTable[T], groupId: Int): Best[T] = {
val cKey = memoTable.allGroups()(groupId).clusterKey()
val algoDef = new DpExploreAlgoDef[T]
- val adjustment = new ExploreAdjustment(cbo, memoTable, rules, enforcerRuleSet)
+ val adjustment = new ExploreAdjustment(ras, memoTable, rules, enforcerRuleSet)
DpClusterAlgo.resolve(memoTable, algoDef, adjustment, cKey)
- val finder = BestFinder(cbo, memoTable.newState())
+ val finder = BestFinder(ras, memoTable.newState())
finder.bestOf(groupId)
}
}
object DpPlanner {
def apply[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
altConstraintSets: Seq[PropertySet[T]],
constraintSet: PropertySet[T],
- plan: T): CboPlanner[T] = {
- new DpPlanner(cbo, altConstraintSets: Seq[PropertySet[T]], constraintSet, plan)
+ plan: T): RasPlanner[T] = {
+ new DpPlanner(ras, altConstraintSets: Seq[PropertySet[T]], constraintSet, plan)
}
// Visited flag.
@@ -85,16 +85,16 @@ object DpPlanner {
private class DpExploreAlgoDef[T <: AnyRef] extends DpClusterAlgoDef[T, SolvedFlag, SolvedFlag] {
override def solveNode(
node: InClusterNode[T],
- childrenClustersOutput: CboClusterKey => SolvedFlag): SolvedFlag = Solved
+ childrenClustersOutput: RasClusterKey => SolvedFlag): SolvedFlag = Solved
override def solveCluster(
- group: CboClusterKey,
+ group: RasClusterKey,
nodesOutput: InClusterNode[T] => SolvedFlag): SolvedFlag = Solved
override def solveNodeOnCycle(node: InClusterNode[T]): SolvedFlag = Solved
- override def solveClusterOnCycle(cluster: CboClusterKey): SolvedFlag = Solved
+ override def solveClusterOnCycle(cluster: RasClusterKey): SolvedFlag = Solved
}
private class ExploreAdjustment[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
memoTable: MemoTable[T],
rules: Seq[RuleApplier[T]],
enforcerRuleSet: EnforcerRuleSet[T])
@@ -103,18 +103,18 @@ object DpPlanner {
private val clusterLookup = cKey => memoTable.getCluster(cKey)
override def exploreChildX(
- panel: Panel[InClusterNode[T], CboClusterKey],
+ panel: Panel[InClusterNode[T], RasClusterKey],
x: InClusterNode[T]): Unit = {}
override def exploreChildY(
- panel: Panel[InClusterNode[T], CboClusterKey],
- y: CboClusterKey): Unit = {}
+ panel: Panel[InClusterNode[T], RasClusterKey],
+ y: RasClusterKey): Unit = {}
override def exploreParentX(
- panel: Panel[InClusterNode[T], CboClusterKey],
+ panel: Panel[InClusterNode[T], RasClusterKey],
x: InClusterNode[T]): Unit = {}
override def exploreParentY(
- panel: Panel[InClusterNode[T], CboClusterKey],
- cKey: CboClusterKey): Unit = {
+ panel: Panel[InClusterNode[T], RasClusterKey],
+ cKey: RasClusterKey): Unit = {
memoTable.doExhaustively {
applyEnforcerRules(panel, cKey)
applyRules(panel, cKey)
@@ -122,8 +122,8 @@ object DpPlanner {
}
private def applyRules(
- panel: Panel[InClusterNode[T], CboClusterKey],
- cKey: CboClusterKey): Unit = {
+ panel: Panel[InClusterNode[T], RasClusterKey],
+ cKey: RasClusterKey): Unit = {
if (rules.isEmpty) {
return
}
@@ -136,8 +136,8 @@ object DpPlanner {
}
private def applyEnforcerRules(
- panel: Panel[InClusterNode[T], CboClusterKey],
- cKey: CboClusterKey): Unit = {
+ panel: Panel[InClusterNode[T], RasClusterKey],
+ cKey: RasClusterKey): Unit = {
val cluster = clusterLookup(cKey)
cKey.propSets(memoTable).foreach {
constraintSet =>
@@ -154,11 +154,11 @@ object DpPlanner {
}
private def findPaths(canonical: CanonicalNode[T], shapes: Seq[Shape[T]])(
- onFound: CboPath[T] => Unit): Unit = {
+ onFound: RasPath[T] => Unit): Unit = {
val finder = shapes
.foldLeft(
PathFinder
- .builder(cbo, memoTable)) {
+ .builder(ras, memoTable)) {
case (builder, shape) =>
builder.output(shape.wizard())
}
@@ -167,10 +167,10 @@ object DpPlanner {
}
private def applyRule(
- panel: Panel[InClusterNode[T], CboClusterKey],
- thisClusterKey: CboClusterKey,
+ panel: Panel[InClusterNode[T], RasClusterKey],
+ thisClusterKey: RasClusterKey,
rule: RuleApplier[T],
- path: CboPath[T]): Unit = {
+ path: RasPath[T]): Unit = {
val probe = memoTable.probe()
rule.apply(path)
val diff = probe.toDiff()
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/dp/DpZipperAlgo.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/dp/DpZipperAlgo.scala
similarity index 99%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/dp/DpZipperAlgo.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/dp/DpZipperAlgo.scala
index e8ac2b6d1..821009982 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/dp/DpZipperAlgo.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/dp/DpZipperAlgo.scala
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.dp
+package org.apache.gluten.ras.dp
-import org.apache.gluten.cbo.util.CycleDetector
+import org.apache.gluten.ras.util.CycleDetector
import scala.collection.mutable
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/exaustive/ExhaustivePlanner.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/exaustive/ExhaustivePlanner.scala
similarity index 75%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/exaustive/ExhaustivePlanner.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/exaustive/ExhaustivePlanner.scala
index 47e0f062a..a9737eb02 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/exaustive/ExhaustivePlanner.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/exaustive/ExhaustivePlanner.scala
@@ -14,26 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.exaustive
+package org.apache.gluten.ras.exaustive
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.Best.KnownCostPath
-import org.apache.gluten.cbo.best.BestFinder
-import org.apache.gluten.cbo.exaustive.ExhaustivePlanner.ExhaustiveExplorer
-import org.apache.gluten.cbo.memo.{Memo, MemoState}
-import org.apache.gluten.cbo.path._
-import org.apache.gluten.cbo.property.PropertySet
-import org.apache.gluten.cbo.rule.{EnforcerRuleSet, RuleApplier, Shape}
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.Best.KnownCostPath
+import org.apache.gluten.ras.best.BestFinder
+import org.apache.gluten.ras.exaustive.ExhaustivePlanner.ExhaustiveExplorer
+import org.apache.gluten.ras.memo.{Memo, MemoState}
+import org.apache.gluten.ras.path._
+import org.apache.gluten.ras.property.PropertySet
+import org.apache.gluten.ras.rule.{EnforcerRuleSet, RuleApplier, Shape}
private class ExhaustivePlanner[T <: AnyRef] private (
- cbo: Cbo[T],
+ ras: Ras[T],
altConstraintSets: Seq[PropertySet[T]],
constraintSet: PropertySet[T],
plan: T)
- extends CboPlanner[T] {
- private val memo = Memo(cbo)
- private val rules = cbo.ruleFactory.create().map(rule => RuleApplier(cbo, memo, rule))
- private val enforcerRuleSet = EnforcerRuleSet[T](cbo, memo)
+ extends RasPlanner[T] {
+ private val memo = Memo(ras)
+ private val rules = ras.ruleFactory.create().map(rule => RuleApplier(ras, memo, rule))
+ private val enforcerRuleSet = EnforcerRuleSet[T](ras, memo)
private lazy val rootGroupId: Int = {
memo.memorize(plan, constraintSet).id()
@@ -49,39 +49,39 @@ private class ExhaustivePlanner[T <: AnyRef] private (
}
override def plan(): T = {
- best._2.cboPath.plan()
+ best._2.rasPath.plan()
}
override def newState(): PlannerState[T] = {
val foundBest = best._1
- PlannerState(cbo, memo.newState(), rootGroupId, foundBest)
+ PlannerState(ras, memo.newState(), rootGroupId, foundBest)
}
private def explore(): Unit = {
// TODO1: Prune paths within cost threshold
// ~~ TODO2: Use partial-canonical paths to reduce search space ~~
memo.doExhaustively {
- val explorer = new ExhaustiveExplorer(cbo, memo.newState(), rules, enforcerRuleSet)
+ val explorer = new ExhaustiveExplorer(ras, memo.newState(), rules, enforcerRuleSet)
explorer.explore()
}
}
private def findBest(memoState: MemoState[T], groupId: Int): Best[T] = {
- BestFinder(cbo, memoState).bestOf(groupId)
+ BestFinder(ras, memoState).bestOf(groupId)
}
}
object ExhaustivePlanner {
def apply[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
altConstraintSets: Seq[PropertySet[T]],
constraintSet: PropertySet[T],
- plan: T): CboPlanner[T] = {
- new ExhaustivePlanner(cbo, altConstraintSets, constraintSet, plan)
+ plan: T): RasPlanner[T] = {
+ new ExhaustivePlanner(ras, altConstraintSets, constraintSet, plan)
}
private class ExhaustiveExplorer[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
memoState: MemoState[T],
rules: Seq[RuleApplier[T]],
enforcerRuleSet: EnforcerRuleSet[T]) {
@@ -95,11 +95,11 @@ object ExhaustivePlanner {
}
private def findPaths(canonical: CanonicalNode[T], shapes: Seq[Shape[T]])(
- onFound: CboPath[T] => Unit): Unit = {
+ onFound: RasPath[T] => Unit): Unit = {
val finder = shapes
.foldLeft(
PathFinder
- .builder(cbo, memoState)) {
+ .builder(ras, memoState)) {
case (builder, shape) =>
builder.output(shape.wizard())
}
@@ -107,7 +107,7 @@ object ExhaustivePlanner {
finder.find(canonical).foreach(path => onFound(path))
}
- private def applyRule(rule: RuleApplier[T], path: CboPath[T]): Unit = {
+ private def applyRule(rule: RuleApplier[T], path: RasPath[T]): Unit = {
rule.apply(path)
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/memo/ForwardMemoTable.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/memo/ForwardMemoTable.scala
similarity index 77%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/memo/ForwardMemoTable.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/memo/ForwardMemoTable.scala
index cd6f4cfe7..945e653eb 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/memo/ForwardMemoTable.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/memo/ForwardMemoTable.scala
@@ -14,47 +14,47 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.memo
+package org.apache.gluten.ras.memo
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.CboCluster.MutableCboCluster
-import org.apache.gluten.cbo.memo.MemoTable.Probe
-import org.apache.gluten.cbo.property.PropertySet
-import org.apache.gluten.cbo.util.IndexDisjointSet
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.RasCluster.MutableRasCluster
+import org.apache.gluten.ras.memo.MemoTable.Probe
+import org.apache.gluten.ras.property.PropertySet
+import org.apache.gluten.ras.util.IndexDisjointSet
import scala.collection.mutable
-class ForwardMemoTable[T <: AnyRef] private (override val cbo: Cbo[T])
+class ForwardMemoTable[T <: AnyRef] private (override val ras: Ras[T])
extends MemoTable.Writable[T] {
import ForwardMemoTable._
- private val groupBuffer: mutable.ArrayBuffer[CboGroup[T]] = mutable.ArrayBuffer()
+ private val groupBuffer: mutable.ArrayBuffer[RasGroup[T]] = mutable.ArrayBuffer()
private val clusterKeyBuffer: mutable.ArrayBuffer[IntClusterKey] = mutable.ArrayBuffer()
- private val clusterBuffer: mutable.ArrayBuffer[MutableCboCluster[T]] = mutable.ArrayBuffer()
+ private val clusterBuffer: mutable.ArrayBuffer[MutableRasCluster[T]] = mutable.ArrayBuffer()
private val clusterDisjointSet: IndexDisjointSet = IndexDisjointSet()
- private val groupLookup: mutable.ArrayBuffer[mutable.Map[PropertySet[T], CboGroup[T]]] =
+ private val groupLookup: mutable.ArrayBuffer[mutable.Map[PropertySet[T], RasGroup[T]]] =
mutable.ArrayBuffer()
private val clusterMergeLog: mutable.ArrayBuffer[(Int, Int)] = mutable.ArrayBuffer()
private var memoWriteCount: Int = 0
- override def getCluster(key: CboClusterKey): MutableCboCluster[T] = {
+ override def getCluster(key: RasClusterKey): MutableRasCluster[T] = {
val ancestor = ancestorClusterIdOf(key)
clusterBuffer(ancestor)
}
- override def newCluster(metadata: Metadata): CboClusterKey = {
+ override def newCluster(metadata: Metadata): RasClusterKey = {
checkBufferSizes()
val key = IntClusterKey(clusterBuffer.size, metadata)
clusterKeyBuffer += key
- clusterBuffer += MutableCboCluster(cbo, metadata)
+ clusterBuffer += MutableRasCluster(ras, metadata)
clusterDisjointSet.grow()
groupLookup += mutable.Map()
key
}
- override def groupOf(key: CboClusterKey, propSet: PropertySet[T]): CboGroup[T] = {
+ override def groupOf(key: RasClusterKey, propSet: PropertySet[T]): RasGroup[T] = {
val ancestor = ancestorClusterIdOf(key)
val lookup = groupLookup(ancestor)
if (lookup.contains(propSet)) {
@@ -62,24 +62,24 @@ class ForwardMemoTable[T <: AnyRef] private (override val cbo: Cbo[T])
}
val gid = groupBuffer.size
val newGroup =
- CboGroup(cbo, IntClusterKey(ancestor, key.metadata), gid, propSet)
+ RasGroup(ras, IntClusterKey(ancestor, key.metadata), gid, propSet)
lookup += propSet -> newGroup
groupBuffer += newGroup
memoWriteCount += 1
newGroup
}
- override def getClusterPropSets(key: CboClusterKey): Set[PropertySet[T]] = {
+ override def getClusterPropSets(key: RasClusterKey): Set[PropertySet[T]] = {
val ancestor = ancestorClusterIdOf(key)
groupLookup(ancestor).keySet.toSet
}
- override def addToCluster(key: CboClusterKey, node: CanonicalNode[T]): Unit = {
+ override def addToCluster(key: RasClusterKey, node: CanonicalNode[T]): Unit = {
getCluster(key).add(node)
memoWriteCount += 1
}
- override def mergeClusters(one: CboClusterKey, other: CboClusterKey): Unit = {
+ override def mergeClusters(one: RasClusterKey, other: RasClusterKey): Unit = {
val oneAncestor = ancestorClusterIdOf(one)
val otherAncestor = ancestorClusterIdOf(other)
@@ -88,8 +88,8 @@ class ForwardMemoTable[T <: AnyRef] private (override val cbo: Cbo[T])
return
}
- case class Merge(from: CboClusterKey, to: CboClusterKey) {
- cbo.metadataModel.verify(from.metadata, to.metadata)
+ case class Merge(from: RasClusterKey, to: RasClusterKey) {
+ ras.metadataModel.verify(from.metadata, to.metadata)
}
val merge = if (oneAncestor > otherAncestor) {
@@ -128,13 +128,13 @@ class ForwardMemoTable[T <: AnyRef] private (override val cbo: Cbo[T])
memoWriteCount += 1
}
- override def getGroup(id: Int): CboGroup[T] = groupBuffer(id)
+ override def getGroup(id: Int): RasGroup[T] = groupBuffer(id)
- override def allClusters(): Seq[CboClusterKey] = clusterKeyBuffer
+ override def allClusters(): Seq[RasClusterKey] = clusterKeyBuffer
- override def allGroups(): Seq[CboGroup[T]] = groupBuffer
+ override def allGroups(): Seq[RasGroup[T]] = groupBuffer
- private def ancestorClusterIdOf(key: CboClusterKey): Int = {
+ private def ancestorClusterIdOf(key: RasClusterKey): Int = {
clusterDisjointSet.find(key.id())
}
@@ -150,9 +150,9 @@ class ForwardMemoTable[T <: AnyRef] private (override val cbo: Cbo[T])
}
object ForwardMemoTable {
- def apply[T <: AnyRef](cbo: Cbo[T]): MemoTable.Writable[T] = new ForwardMemoTable[T](cbo)
+ def apply[T <: AnyRef](ras: Ras[T]): MemoTable.Writable[T] = new ForwardMemoTable[T](ras)
- private case class IntClusterKey(id: Int, metadata: Metadata) extends CboClusterKey
+ private case class IntClusterKey(id: Int, metadata: Metadata) extends RasClusterKey
private class Probe[T <: AnyRef](table: ForwardMemoTable[T]) extends MemoTable.Probe[T] {
private val probedClusterCount: Int = table.clusterKeyBuffer.size
@@ -191,7 +191,7 @@ object ForwardMemoTable {
}
}
- implicit class CboClusterKeyImplicits(key: CboClusterKey) {
+ implicit class RasClusterKeyImplicits(key: RasClusterKey) {
def id(): Int = {
asIntKey().id
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/memo/Memo.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/memo/Memo.scala
similarity index 66%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/memo/Memo.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/memo/Memo.scala
index 620f2015b..a77293586 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/memo/Memo.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/memo/Memo.scala
@@ -14,16 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.memo
+package org.apache.gluten.ras.memo
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.CboCluster.ImmutableCboCluster
-import org.apache.gluten.cbo.property.PropertySet
-import org.apache.gluten.cbo.util.CanonicalNodeMap
-import org.apache.gluten.cbo.vis.GraphvizVisualizer
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.RasCluster.ImmutableRasCluster
+import org.apache.gluten.ras.property.PropertySet
+import org.apache.gluten.ras.util.CanonicalNodeMap
+import org.apache.gluten.ras.vis.GraphvizVisualizer
trait MemoLike[T <: AnyRef] {
- def memorize(node: T, constraintSet: PropertySet[T]): CboGroup[T]
+ def memorize(node: T, constraintSet: PropertySet[T]): RasGroup[T]
}
trait Closure[T <: AnyRef] {
@@ -40,24 +40,24 @@ trait UnsafeMemo[T <: AnyRef] extends Memo[T] {
}
object Memo {
- def apply[T <: AnyRef](cbo: Cbo[T]): Memo[T] = {
- new CboMemo[T](cbo)
+ def apply[T <: AnyRef](ras: Ras[T]): Memo[T] = {
+ new RasMemo[T](ras)
}
- def unsafe[T <: AnyRef](cbo: Cbo[T]): UnsafeMemo[T] = {
- new CboMemo[T](cbo)
+ def unsafe[T <: AnyRef](ras: Ras[T]): UnsafeMemo[T] = {
+ new RasMemo[T](ras)
}
- private class CboMemo[T <: AnyRef](val cbo: Cbo[T]) extends UnsafeMemo[T] {
- import CboMemo._
- private val memoTable: MemoTable.Writable[T] = MemoTable.create(cbo)
- private val cache: NodeToClusterMap[T] = new NodeToClusterMap(cbo)
+ private class RasMemo[T <: AnyRef](val ras: Ras[T]) extends UnsafeMemo[T] {
+ import RasMemo._
+ private val memoTable: MemoTable.Writable[T] = MemoTable.create(ras)
+ private val cache: NodeToClusterMap[T] = new NodeToClusterMap(ras)
- private def newCluster(metadata: Metadata): CboClusterKey = {
+ private def newCluster(metadata: Metadata): RasClusterKey = {
memoTable.newCluster(metadata)
}
- private def addToCluster(clusterKey: CboClusterKey, can: CanonicalNode[T]): Unit = {
+ private def addToCluster(clusterKey: RasClusterKey, can: CanonicalNode[T]): Unit = {
assert(!cache.contains(can))
cache.put(can, clusterKey)
memoTable.addToCluster(clusterKey, can)
@@ -67,11 +67,11 @@ object Memo {
private def canonizeUnsafe(node: T, constraintSet: PropertySet[T], depth: Int): T = {
assert(depth >= 1)
if (depth > 1) {
- return cbo.withNewChildren(
+ return ras.withNewChildren(
node,
- cbo.planModel
+ ras.planModel
.childrenOf(node)
- .zip(cbo.propertySetFactory().childrenConstraintSets(constraintSet, node))
+ .zip(ras.propertySetFactory().childrenConstraintSets(constraintSet, node))
.map {
case (child, constraintSet) =>
canonizeUnsafe(child, constraintSet, depth - 1)
@@ -79,25 +79,25 @@ object Memo {
)
}
assert(depth == 1)
- val childrenGroups: Seq[CboGroup[T]] = cbo.planModel
+ val childrenGroups: Seq[RasGroup[T]] = ras.planModel
.childrenOf(node)
- .zip(cbo.propertySetFactory().childrenConstraintSets(constraintSet, node))
+ .zip(ras.propertySetFactory().childrenConstraintSets(constraintSet, node))
.map {
case (child, childConstraintSet) =>
memorize(child, childConstraintSet)
}
val newNode =
- cbo.withNewChildren(node, childrenGroups.map(group => group.self()))
+ ras.withNewChildren(node, childrenGroups.map(group => group.self()))
newNode
}
private def canonize(node: T, constraintSet: PropertySet[T]): CanonicalNode[T] = {
- CanonicalNode(cbo, canonizeUnsafe(node, constraintSet, 1))
+ CanonicalNode(ras, canonizeUnsafe(node, constraintSet, 1))
}
- private def insert(n: T, constraintSet: PropertySet[T]): CboClusterKey = {
- if (cbo.planModel.isGroupLeaf(n)) {
- val plainGroup = memoTable.allGroups()(cbo.planModel.getGroupId(n))
+ private def insert(n: T, constraintSet: PropertySet[T]): RasClusterKey = {
+ if (ras.planModel.isGroupLeaf(n)) {
+ val plainGroup = memoTable.allGroups()(ras.planModel.getGroupId(n))
return plainGroup.clusterKey()
}
@@ -107,14 +107,14 @@ object Memo {
cache.get(node)
} else {
// Node not yet added to cluster.
- val meta = cbo.metadataModel.metadataOf(node.self())
+ val meta = ras.metadataModel.metadataOf(node.self())
val clusterKey = newCluster(meta)
addToCluster(clusterKey, node)
clusterKey
}
}
- override def memorize(node: T, constraintSet: PropertySet[T]): CboGroup[T] = {
+ override def memorize(node: T, constraintSet: PropertySet[T]): RasGroup[T] = {
val clusterKey = insert(node, constraintSet)
val prevGroupCount = memoTable.allGroups().size
val out = memoTable.groupOf(clusterKey, constraintSet)
@@ -140,8 +140,8 @@ object Memo {
}
}
- private object CboMemo {
- private class InCusterMemo[T <: AnyRef](parent: CboMemo[T], preparedCluster: CboClusterKey)
+ private object RasMemo {
+ private class InCusterMemo[T <: AnyRef](parent: RasMemo[T], preparedCluster: RasClusterKey)
extends MemoLike[T] {
private def insert(node: T, constraintSet: PropertySet[T]): Unit = {
@@ -163,65 +163,65 @@ object Memo {
parent.addToCluster(preparedCluster, can)
}
- override def memorize(node: T, constraintSet: PropertySet[T]): CboGroup[T] = {
+ override def memorize(node: T, constraintSet: PropertySet[T]): RasGroup[T] = {
insert(node, constraintSet)
parent.memoTable.groupOf(preparedCluster, constraintSet)
}
}
}
- private class NodeToClusterMap[T <: AnyRef](cbo: Cbo[T])
- extends CanonicalNodeMap[T, CboClusterKey](cbo)
+ private class NodeToClusterMap[T <: AnyRef](ras: Ras[T])
+ extends CanonicalNodeMap[T, RasClusterKey](ras)
}
trait MemoStore[T <: AnyRef] {
- def getCluster(key: CboClusterKey): CboCluster[T]
- def getGroup(id: Int): CboGroup[T]
+ def getCluster(key: RasClusterKey): RasCluster[T]
+ def getGroup(id: Int): RasGroup[T]
}
object MemoStore {
implicit class MemoStoreImplicits[T <: AnyRef](store: MemoStore[T]) {
- def asGroupSupplier(): Int => CboGroup[T] = {
+ def asGroupSupplier(): Int => RasGroup[T] = {
store.getGroup
}
}
}
trait MemoState[T <: AnyRef] extends MemoStore[T] {
- def cbo(): Cbo[T]
- def clusterLookup(): Map[CboClusterKey, CboCluster[T]]
- def allClusters(): Iterable[CboCluster[T]]
- def allGroups(): Seq[CboGroup[T]]
+ def ras(): Ras[T]
+ def clusterLookup(): Map[RasClusterKey, RasCluster[T]]
+ def allClusters(): Iterable[RasCluster[T]]
+ def allGroups(): Seq[RasGroup[T]]
}
object MemoState {
def apply[T <: AnyRef](
- cbo: Cbo[T],
- clusterLookup: Map[CboClusterKey, ImmutableCboCluster[T]],
- allGroups: Seq[CboGroup[T]]): MemoState[T] = {
- MemoStateImpl(cbo, clusterLookup, allGroups)
+ ras: Ras[T],
+ clusterLookup: Map[RasClusterKey, ImmutableRasCluster[T]],
+ allGroups: Seq[RasGroup[T]]): MemoState[T] = {
+ MemoStateImpl(ras, clusterLookup, allGroups)
}
private case class MemoStateImpl[T <: AnyRef](
- override val cbo: Cbo[T],
- override val clusterLookup: Map[CboClusterKey, ImmutableCboCluster[T]],
- override val allGroups: Seq[CboGroup[T]])
+ override val ras: Ras[T],
+ override val clusterLookup: Map[RasClusterKey, ImmutableRasCluster[T]],
+ override val allGroups: Seq[RasGroup[T]])
extends MemoState[T] {
private val allClustersCopy = clusterLookup.values
- override def getCluster(key: CboClusterKey): CboCluster[T] = clusterLookup(key)
- override def getGroup(id: Int): CboGroup[T] = allGroups(id)
- override def allClusters(): Iterable[CboCluster[T]] = allClustersCopy
+ override def getCluster(key: RasClusterKey): RasCluster[T] = clusterLookup(key)
+ override def getGroup(id: Int): RasGroup[T] = allGroups(id)
+ override def allClusters(): Iterable[RasCluster[T]] = allClustersCopy
}
implicit class MemoStateImplicits[T <: AnyRef](state: MemoState[T]) {
def formatGraphvizWithBest(best: Best[T]): String = {
- GraphvizVisualizer(state.cbo(), state, best).format()
+ GraphvizVisualizer(state.ras(), state, best).format()
}
def formatGraphvizWithoutBest(rootGroupId: Int): String = {
- GraphvizVisualizer(state.cbo(), state, rootGroupId).format()
+ GraphvizVisualizer(state.ras(), state, rootGroupId).format()
}
}
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/memo/MemoTable.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/memo/MemoTable.scala
similarity index 63%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/memo/MemoTable.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/memo/MemoTable.scala
index 127e313a7..b54bd8811 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/memo/MemoTable.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/memo/MemoTable.scala
@@ -14,24 +14,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.memo
+package org.apache.gluten.ras.memo
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.CboCluster.ImmutableCboCluster
-import org.apache.gluten.cbo.property.PropertySet
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.RasCluster.ImmutableRasCluster
+import org.apache.gluten.ras.property.PropertySet
sealed trait MemoTable[T <: AnyRef] extends MemoStore[T] {
import MemoTable._
- def cbo: Cbo[T]
+ def ras: Ras[T]
- override def getCluster(key: CboClusterKey): CboCluster[T]
- override def getGroup(id: Int): CboGroup[T]
+ override def getCluster(key: RasClusterKey): RasCluster[T]
+ override def getGroup(id: Int): RasGroup[T]
- def allClusters(): Seq[CboClusterKey]
- def allGroups(): Seq[CboGroup[T]]
+ def allClusters(): Seq[RasClusterKey]
+ def allGroups(): Seq[RasGroup[T]]
- def getClusterPropSets(key: CboClusterKey): Set[PropertySet[T]]
+ def getClusterPropSets(key: RasClusterKey): Set[PropertySet[T]]
def probe(): Probe[T]
@@ -39,14 +39,14 @@ sealed trait MemoTable[T <: AnyRef] extends MemoStore[T] {
}
object MemoTable {
- def create[T <: AnyRef](cbo: Cbo[T]): Writable[T] = ForwardMemoTable(cbo)
+ def create[T <: AnyRef](ras: Ras[T]): Writable[T] = ForwardMemoTable(ras)
trait Writable[T <: AnyRef] extends MemoTable[T] {
- def newCluster(metadata: Metadata): CboClusterKey
- def groupOf(key: CboClusterKey, propertySet: PropertySet[T]): CboGroup[T]
+ def newCluster(metadata: Metadata): RasClusterKey
+ def groupOf(key: RasClusterKey, propertySet: PropertySet[T]): RasGroup[T]
- def addToCluster(key: CboClusterKey, node: CanonicalNode[T]): Unit
- def mergeClusters(one: CboClusterKey, other: CboClusterKey): Unit
+ def addToCluster(key: RasClusterKey, node: CanonicalNode[T]): Unit
+ def mergeClusters(one: RasClusterKey, other: RasClusterKey): Unit
}
trait Probe[T <: AnyRef] {
@@ -56,13 +56,13 @@ object MemoTable {
object Probe {
trait Diff[T <: AnyRef] {
- def changedClusters(): Set[CboClusterKey]
+ def changedClusters(): Set[RasClusterKey]
}
object Diff {
- def apply[T <: AnyRef](changedClusters: Set[CboClusterKey]): Diff[T] = DiffImpl(
+ def apply[T <: AnyRef](changedClusters: Set[RasClusterKey]): Diff[T] = DiffImpl(
changedClusters)
- private case class DiffImpl[T <: AnyRef](override val changedClusters: Set[CboClusterKey])
+ private case class DiffImpl[T <: AnyRef](override val changedClusters: Set[RasClusterKey])
extends Diff[T]
}
}
@@ -71,9 +71,9 @@ object MemoTable {
def newState(): MemoState[T] = {
val immutableClusters = table
.allClusters()
- .map(key => key -> ImmutableCboCluster(table.cbo, table.getCluster(key)))
+ .map(key => key -> ImmutableRasCluster(table.ras, table.getCluster(key)))
.toMap
- MemoState(table.cbo, immutableClusters, table.allGroups())
+ MemoState(table.ras, immutableClusters, table.allGroups())
}
def doExhaustively(func: => Unit): Unit = {
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/OutputFilter.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/OutputFilter.scala
similarity index 94%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/OutputFilter.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/OutputFilter.scala
index 2937e9d8c..ed1c326f9 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/OutputFilter.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/OutputFilter.scala
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.path
+package org.apache.gluten.ras.path
-import org.apache.gluten.cbo.{CanonicalNode, GroupNode}
-import org.apache.gluten.cbo.path.FilterWizard.FilterAction
-import org.apache.gluten.cbo.path.OutputWizard.OutputAction
-import org.apache.gluten.cbo.util.CycleDetector
+import org.apache.gluten.ras.{CanonicalNode, GroupNode}
+import org.apache.gluten.ras.path.FilterWizard.FilterAction
+import org.apache.gluten.ras.path.OutputWizard.OutputAction
+import org.apache.gluten.ras.util.CycleDetector
trait FilterWizard[T <: AnyRef] {
import FilterWizard._
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/OutputWizard.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/OutputWizard.scala
similarity index 94%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/OutputWizard.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/OutputWizard.scala
index cc6310c50..0e40c36d8 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/OutputWizard.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/OutputWizard.scala
@@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.path
+package org.apache.gluten.ras.path
-import org.apache.gluten.cbo.{CanonicalNode, Cbo, CboGroup, GroupNode}
-import org.apache.gluten.cbo.path.OutputWizard.{OutputAction, PathDrain}
+import org.apache.gluten.ras.{CanonicalNode, GroupNode, Ras, RasGroup}
+import org.apache.gluten.ras.path.OutputWizard.{OutputAction, PathDrain}
import scala.collection.{mutable, Seq}
@@ -91,18 +91,18 @@ object OutputWizard {
}
def prepareForNode(
- cbo: Cbo[T],
- allGroups: Int => CboGroup[T],
+ ras: Ras[T],
+ allGroups: Int => RasGroup[T],
can: CanonicalNode[T]): NodePrepare[T] = {
- new NodePrepareImpl[T](cbo, wizard, allGroups, can)
+ new NodePrepareImpl[T](ras, wizard, allGroups, can)
}
def prepareForGroup(
- cbo: Cbo[T],
+ ras: Ras[T],
group: GroupNode[T],
offset: Int,
count: Int): GroupPrepare[T] = {
- new GroupPrepareImpl[T](cbo, wizard, group, offset, count)
+ new GroupPrepareImpl[T](ras, wizard, group, offset, count)
}
}
@@ -116,15 +116,15 @@ object OutputWizard {
}
sealed trait Terminate[T <: AnyRef] {
- def onContinue(extra: OutputWizard[T] => Iterable[CboPath[T]]): Iterable[CboPath[T]]
+ def onContinue(extra: OutputWizard[T] => Iterable[RasPath[T]]): Iterable[RasPath[T]]
}
private class DrainedTerminate[T <: AnyRef](
action: OutputAction[T],
- drained: Iterable[CboPath[T]])
+ drained: Iterable[RasPath[T]])
extends Terminate[T] {
override def onContinue(
- extra: OutputWizard[T] => Iterable[CboPath[T]]): Iterable[CboPath[T]] = {
+ extra: OutputWizard[T] => Iterable[RasPath[T]]): Iterable[RasPath[T]] = {
action match {
case OutputAction.Stop(_) =>
drained.view
@@ -135,9 +135,9 @@ object OutputWizard {
}
private class NodePrepareImpl[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
wizard: OutputWizard[T],
- allGroups: Int => CboGroup[T],
+ allGroups: Int => RasGroup[T],
can: CanonicalNode[T])
extends NodePrepare[T] {
override def visit(): Terminate[T] = {
@@ -145,14 +145,14 @@ object OutputWizard {
val drained = if (action.drain().isEmpty()) {
List.empty
} else {
- List(CboPath.one(cbo, PathKeySet(action.drain().keysUnsafe().toSet), allGroups, can))
+ List(RasPath.one(ras, PathKeySet(action.drain().keysUnsafe().toSet), allGroups, can))
}
new DrainedTerminate[T](action, drained)
}
}
private class GroupPrepareImpl[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
wizard: OutputWizard[T],
group: GroupNode[T],
offset: Int,
@@ -163,7 +163,7 @@ object OutputWizard {
val drained = if (action.drain().isEmpty()) {
List.empty
} else {
- List(CboPath.zero(cbo, PathKeySet(action.drain().keysUnsafe().toSet), group))
+ List(RasPath.zero(ras, PathKeySet(action.drain().keysUnsafe().toSet), group))
}
new DrainedTerminate[T](action, drained)
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/PathFinder.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/PathFinder.scala
similarity index 73%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/PathFinder.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/PathFinder.scala
index 2eeb6f659..c5949a9d7 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/PathFinder.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/PathFinder.scala
@@ -14,28 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.path
+package org.apache.gluten.ras.path
-import org.apache.gluten.cbo.{CanonicalNode, Cbo, GroupNode}
-import org.apache.gluten.cbo.memo.MemoStore
+import org.apache.gluten.ras.{CanonicalNode, GroupNode, Ras}
+import org.apache.gluten.ras.memo.MemoStore
import scala.collection.mutable
trait PathFinder[T <: AnyRef] {
- def find(base: CanonicalNode[T]): Iterable[CboPath[T]]
- def find(base: CboPath[T]): Iterable[CboPath[T]]
+ def find(base: CanonicalNode[T]): Iterable[RasPath[T]]
+ def find(base: RasPath[T]): Iterable[RasPath[T]]
}
object PathFinder {
- def apply[T <: AnyRef](cbo: Cbo[T], memoStore: MemoStore[T]): PathFinder[T] = {
- builder(cbo, memoStore).build()
+ def apply[T <: AnyRef](ras: Ras[T], memoStore: MemoStore[T]): PathFinder[T] = {
+ builder(ras, memoStore).build()
}
- def builder[T <: AnyRef](cbo: Cbo[T], memoStore: MemoStore[T]): Builder[T] = {
- Builder[T](cbo, memoStore)
+ def builder[T <: AnyRef](ras: Ras[T], memoStore: MemoStore[T]): Builder[T] = {
+ Builder[T](ras, memoStore)
}
- class Builder[T <: AnyRef] private (cbo: Cbo[T], memoStore: MemoStore[T]) {
+ class Builder[T <: AnyRef] private (ras: Ras[T], memoStore: MemoStore[T]) {
private val filterWizards = mutable.ListBuffer[FilterWizard[T]](FilterWizards.omitCycles())
private val outputWizards = mutable.ListBuffer[OutputWizard[T]]()
@@ -62,35 +62,35 @@ object PathFinder {
val wizard = filterWizards.foldLeft(allOutputs) {
(outputWizard, filterWizard) => outputWizard.filterBy(filterWizard)
}
- PathEnumerator(cbo, memoStore, wizard)
+ PathEnumerator(ras, memoStore, wizard)
}
}
private object Builder {
- def apply[T <: AnyRef](cbo: Cbo[T], memoStore: MemoStore[T]): Builder[T] = {
- new Builder(cbo, memoStore)
+ def apply[T <: AnyRef](ras: Ras[T], memoStore: MemoStore[T]): Builder[T] = {
+ new Builder(ras, memoStore)
}
}
// Using children's enumerated paths recursively to enumerate the paths of the current node.
// This works like from bottom up to assemble all possible paths.
private class PathEnumerator[T <: AnyRef] private (
- cbo: Cbo[T],
+ ras: Ras[T],
memoStore: MemoStore[T],
wizard: OutputWizard[T])
extends PathFinder[T] {
- override def find(canonical: CanonicalNode[T]): Iterable[CboPath[T]] = {
+ override def find(canonical: CanonicalNode[T]): Iterable[RasPath[T]] = {
val all =
- wizard.prepareForNode(cbo, memoStore.asGroupSupplier(), canonical).visit().onContinue {
+ wizard.prepareForNode(ras, memoStore.asGroupSupplier(), canonical).visit().onContinue {
newWizard => enumerateFromNode(canonical, newWizard)
}
all
}
- override def find(base: CboPath[T]): Iterable[CboPath[T]] = {
+ override def find(base: RasPath[T]): Iterable[RasPath[T]] = {
val can = base.node().self().asCanonical()
- val all = wizard.prepareForNode(cbo, memoStore.asGroupSupplier(), can).visit().onContinue {
+ val all = wizard.prepareForNode(ras, memoStore.asGroupSupplier(), can).visit().onContinue {
newWizard => diveFromNode(base.height(), base.node(), newWizard)
}
all
@@ -98,13 +98,13 @@ object PathFinder {
private def enumerateFromGroup(
group: GroupNode[T],
- wizard: OutputWizard[T]): Iterable[CboPath[T]] = {
+ wizard: OutputWizard[T]): Iterable[RasPath[T]] = {
group
.group(memoStore.asGroupSupplier())
.nodes(memoStore)
.flatMap(
can => {
- wizard.prepareForNode(cbo, memoStore.asGroupSupplier(), can).visit().onContinue {
+ wizard.prepareForNode(ras, memoStore.asGroupSupplier(), can).visit().onContinue {
newWizard => enumerateFromNode(can, newWizard)
}
})
@@ -112,28 +112,28 @@ object PathFinder {
private def enumerateFromNode(
canonical: CanonicalNode[T],
- wizard: OutputWizard[T]): Iterable[CboPath[T]] = {
+ wizard: OutputWizard[T]): Iterable[RasPath[T]] = {
val childrenGroups = canonical.getChildrenGroups(memoStore.asGroupSupplier())
if (childrenGroups.isEmpty) {
// It's a canonical leaf node.
return List.empty
}
// It's a canonical branch node.
- val expandedChildren: Seq[Iterable[CboPath[T]]] =
+ val expandedChildren: Seq[Iterable[RasPath[T]]] =
childrenGroups.zipWithIndex.map {
case (childGroup, index) =>
wizard
- .prepareForGroup(cbo, childGroup, index, childrenGroups.size)
+ .prepareForGroup(ras, childGroup, index, childrenGroups.size)
.advance()
.onContinue(newWizard => enumerateFromGroup(childGroup, newWizard))
}
- CboPath.cartesianProduct(cbo, canonical, expandedChildren)
+ RasPath.cartesianProduct(ras, canonical, expandedChildren)
}
private def diveFromGroup(
depth: Int,
gpn: GroupedPathNode[T],
- wizard: OutputWizard[T]): Iterable[CboPath[T]] = {
+ wizard: OutputWizard[T]): Iterable[RasPath[T]] = {
assert(depth >= 0)
if (depth == 0) {
assert(gpn.node.self().isGroup)
@@ -143,15 +143,15 @@ object PathFinder {
assert(gpn.node.self().isCanonical)
val canonical = gpn.node.self().asCanonical()
- wizard.prepareForNode(cbo, memoStore.asGroupSupplier(), canonical).visit().onContinue {
+ wizard.prepareForNode(ras, memoStore.asGroupSupplier(), canonical).visit().onContinue {
newWizard => diveFromNode(depth, gpn.node, newWizard)
}
}
private def diveFromNode(
depth: Int,
- node: CboPath.PathNode[T],
- wizard: OutputWizard[T]): Iterable[CboPath[T]] = {
+ node: RasPath.PathNode[T],
+ wizard: OutputWizard[T]): Iterable[RasPath[T]] = {
assert(depth >= 1)
assert(node.self().isCanonical)
val canonical = node.self().asCanonical()
@@ -162,13 +162,13 @@ object PathFinder {
}
val childrenGroups = canonical.getChildrenGroups(memoStore.asGroupSupplier())
- CboPath.cartesianProduct(
- cbo,
+ RasPath.cartesianProduct(
+ ras,
canonical,
children.zip(childrenGroups).zipWithIndex.map {
case ((child, childGroup), index) =>
wizard
- .prepareForGroup(cbo, childGroup, index, childrenGroups.size)
+ .prepareForGroup(ras, childGroup, index, childrenGroups.size)
.advance()
.onContinue {
newWizard => diveFromGroup(depth - 1, GroupedPathNode(childGroup, child), newWizard)
@@ -180,12 +180,12 @@ object PathFinder {
private object PathEnumerator {
def apply[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
memoStore: MemoStore[T],
wizard: OutputWizard[T]): PathEnumerator[T] = {
- new PathEnumerator(cbo, memoStore, wizard)
+ new PathEnumerator(ras, memoStore, wizard)
}
}
- private case class GroupedPathNode[T <: AnyRef](group: GroupNode[T], node: CboPath.PathNode[T])
+ private case class GroupedPathNode[T <: AnyRef](group: GroupNode[T], node: RasPath.PathNode[T])
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/PathKey.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/PathKey.scala
similarity index 98%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/PathKey.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/PathKey.scala
index 082431aea..2e82d7ce4 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/PathKey.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/PathKey.scala
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.path
+package org.apache.gluten.ras.path
import java.util.concurrent.atomic.AtomicLong
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/PathMask.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/PathMask.scala
similarity index 99%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/PathMask.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/PathMask.scala
index ebbedbee3..a8caded40 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/PathMask.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/PathMask.scala
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.path
+package org.apache.gluten.ras.path
import scala.collection.mutable
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/Pattern.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/Pattern.scala
similarity index 94%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/Pattern.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/Pattern.scala
index ad84441f3..b694279ec 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/Pattern.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/Pattern.scala
@@ -14,13 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.path
+package org.apache.gluten.ras.path
-import org.apache.gluten.cbo.CanonicalNode
-import org.apache.gluten.cbo.path.CboPath.PathNode
+import org.apache.gluten.ras.CanonicalNode
+import org.apache.gluten.ras.path.RasPath.PathNode
trait Pattern[T <: AnyRef] {
- def matches(path: CboPath[T], depth: Int): Boolean
+ def matches(path: RasPath[T], depth: Int): Boolean
def root(): Pattern.Node[T]
}
@@ -89,7 +89,7 @@ object Pattern {
}
private case class PatternImpl[T <: AnyRef](root: Node[T]) extends Pattern[T] {
- override def matches(path: CboPath[T], depth: Int): Boolean = {
+ override def matches(path: RasPath[T], depth: Int): Boolean = {
assert(depth >= 1)
assert(depth <= path.height())
def dfs(remainingDepth: Int, patternN: Node[T], n: PathNode[T]): Boolean = {
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/CboPath.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/RasPath.scala
similarity index 68%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/CboPath.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/RasPath.scala
index 36bce1eca..ca712cec4 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/path/CboPath.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/path/RasPath.scala
@@ -14,42 +14,42 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.path
+package org.apache.gluten.ras.path
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.memo.MemoStore
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.memo.MemoStore
-trait CboPath[T <: AnyRef] {
- def cbo(): Cbo[T]
+trait RasPath[T <: AnyRef] {
+ def ras(): Ras[T]
def keys(): PathKeySet
def height(): Int
- def node(): CboPath.PathNode[T]
+ def node(): RasPath.PathNode[T]
def plan(): T
}
-object CboPath {
+object RasPath {
val INF_DEPTH: Int = Int.MaxValue
trait PathNode[T <: AnyRef] {
- def self(): CboNode[T]
+ def self(): RasNode[T]
def children(): Seq[PathNode[T]]
}
object PathNode {
- def apply[T <: AnyRef](node: CboNode[T], children: Seq[PathNode[T]]): PathNode[T] = {
+ def apply[T <: AnyRef](node: RasNode[T], children: Seq[PathNode[T]]): PathNode[T] = {
PathNodeImpl(node, children)
}
}
- implicit class PathNodeImplicits[T <: AnyRef](pNode: CboPath.PathNode[T]) {
- def zipChildrenWithGroupIds(): Seq[(CboPath.PathNode[T], Int)] = {
+ implicit class PathNodeImplicits[T <: AnyRef](pNode: RasPath.PathNode[T]) {
+ def zipChildrenWithGroupIds(): Seq[(RasPath.PathNode[T], Int)] = {
pNode
.children()
.zip(pNode.self().asCanonical().getChildrenGroupIds())
}
def zipChildrenWithGroups(
- allGroups: Int => CboGroup[T]): Seq[(CboPath.PathNode[T], CboGroup[T])] = {
+ allGroups: Int => RasGroup[T]): Seq[(RasPath.PathNode[T], RasGroup[T])] = {
pNode
.children()
.zip(pNode.self().asCanonical().getChildrenGroups(allGroups).map(_.group(allGroups)))
@@ -57,19 +57,19 @@ object CboPath {
}
private def apply[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
keys: PathKeySet,
height: Int,
- node: CboPath.PathNode[T]): CboPath[T] = {
- CboPathImpl(cbo, keys, height, node)
+ node: RasPath.PathNode[T]): RasPath[T] = {
+ RasPathImpl(ras, keys, height, node)
}
// Returns none if children doesn't share at least one path key.
def apply[T <: AnyRef](
- cbo: Cbo[T],
- node: CboNode[T],
- children: Seq[CboPath[T]]): Option[CboPath[T]] = {
- assert(children.forall(_.cbo() eq cbo))
+ ras: Ras[T],
+ node: RasNode[T],
+ children: Seq[RasPath[T]]): Option[RasPath[T]] = {
+ assert(children.forall(_.ras() eq ras))
val newKeysUnsafe = children.map(_.keys().keys()).reduce[Set[PathKey]] {
case (one, other) =>
@@ -80,24 +80,24 @@ object CboPath {
}
val newKeys = PathKeySet(newKeysUnsafe)
Some(
- CboPath(
- cbo,
+ RasPath(
+ ras,
newKeys,
1 + children.map(_.height()).reduceOption(_ max _).getOrElse(0),
PathNode(node, children.map(_.node()))))
}
- def zero[T <: AnyRef](cbo: Cbo[T], keys: PathKeySet, group: GroupNode[T]): CboPath[T] = {
- CboPath(cbo, keys, 0, PathNode(group, List.empty))
+ def zero[T <: AnyRef](ras: Ras[T], keys: PathKeySet, group: GroupNode[T]): RasPath[T] = {
+ RasPath(ras, keys, 0, PathNode(group, List.empty))
}
def one[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
keys: PathKeySet,
- allGroups: Int => CboGroup[T],
- canonical: CanonicalNode[T]): CboPath[T] = {
- CboPath(
- cbo,
+ allGroups: Int => RasGroup[T],
+ canonical: CanonicalNode[T]): RasPath[T] = {
+ RasPath(
+ ras,
keys,
1,
PathNode(canonical, canonical.getChildrenGroups(allGroups).map(g => PathNode(g, List.empty))))
@@ -105,7 +105,7 @@ object CboPath {
// Aggregates paths that have same shape but different keys together.
// Currently not in use because of bad performance.
- def aggregate[T <: AnyRef](cbo: Cbo[T], paths: Iterable[CboPath[T]]): Iterable[CboPath[T]] = {
+ def aggregate[T <: AnyRef](ras: Ras[T], paths: Iterable[RasPath[T]]): Iterable[RasPath[T]] = {
// Scala has specialized optimization against small set of input of group-by.
// So it's better only to pass small inputs to this method if possible.
val grouped = paths.groupBy(_.node())
@@ -118,14 +118,14 @@ object CboPath {
case (one, other) =>
one.union(other)
}
- CboPath(cbo, PathKeySet(keys), height, node)
+ RasPath(ras, PathKeySet(keys), height, node)
}
}
def cartesianProduct[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
canonical: CanonicalNode[T],
- children: Seq[Iterable[CboPath[T]]]): Iterable[CboPath[T]] = {
+ children: Seq[Iterable[RasPath[T]]]): Iterable[RasPath[T]] = {
// Apply cartesian product across all children to get an enumeration
// of all possible choices of parent and children.
//
@@ -145,26 +145,26 @@ object CboPath {
// p0.6(p2.1, p5), p0.7(p2.2, p3), p0.8(p2.2, p4), p0.9(p2.2, p5)] (output)
//
// TODO: Make inner builder list mutable to reduce memory usage
- val choicesBuilder: Iterable[Seq[CboPath[T]]] = List(List.empty)
- val choices: Iterable[Seq[CboPath[T]]] = children
+ val choicesBuilder: Iterable[Seq[RasPath[T]]] = List(List.empty)
+ val choices: Iterable[Seq[RasPath[T]]] = children
.foldLeft(choicesBuilder) {
- (choicesBuilder: Iterable[Seq[CboPath[T]]], child: Iterable[CboPath[T]]) =>
+ (choicesBuilder: Iterable[Seq[RasPath[T]]], child: Iterable[RasPath[T]]) =>
for (left <- choicesBuilder; right <- child) yield left :+ right
}
- choices.flatMap { children: Seq[CboPath[T]] => CboPath(cbo, canonical, children) }
+ choices.flatMap { children: Seq[RasPath[T]] => RasPath(ras, canonical, children) }
}
- implicit class CboPathImplicits[T <: AnyRef](path: CboPath[T]) {
- def dive(memoStore: MemoStore[T], extraDepth: Int): Iterable[CboPath[T]] = {
+ implicit class RasPathImplicits[T <: AnyRef](path: RasPath[T]) {
+ def dive(memoStore: MemoStore[T], extraDepth: Int): Iterable[RasPath[T]] = {
val accumulatedDepth = extraDepth match {
- case CboPath.INF_DEPTH => CboPath.INF_DEPTH
+ case RasPath.INF_DEPTH => RasPath.INF_DEPTH
case _ =>
Math.addExact(path.height(), extraDepth)
}
val finder = PathFinder
- .builder(path.cbo(), memoStore)
+ .builder(path.ras(), memoStore)
.depth(accumulatedDepth)
.build()
finder.find(path)
@@ -172,20 +172,20 @@ object CboPath {
}
private case class PathNodeImpl[T <: AnyRef](
- override val self: CboNode[T],
+ override val self: RasNode[T],
override val children: Seq[PathNode[T]])
extends PathNode[T]
- private case class CboPathImpl[T <: AnyRef](
- override val cbo: Cbo[T],
+ private case class RasPathImpl[T <: AnyRef](
+ override val ras: Ras[T],
override val keys: PathKeySet,
override val height: Int,
- override val node: CboPath.PathNode[T])
- extends CboPath[T] {
+ override val node: RasPath.PathNode[T])
+ extends RasPath[T] {
assert(height >= 0)
private lazy val built: T = {
- def dfs(node: CboPath.PathNode[T]): T = {
- cbo.withNewChildren(node.self().self(), node.children().map(c => dfs(c)))
+ def dfs(node: RasPath.PathNode[T]): T = {
+ ras.withNewChildren(node.self().self(), node.children().map(c => dfs(c)))
}
dfs(node)
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/property/PropertySet.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/property/PropertySet.scala
similarity index 96%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/property/PropertySet.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/property/PropertySet.scala
index 8d7c297ea..13ee2da03 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/property/PropertySet.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/property/PropertySet.scala
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.property
+package org.apache.gluten.ras.property
-import org.apache.gluten.cbo.{Property, PropertyDef}
+import org.apache.gluten.ras.{Property, PropertyDef}
trait PropertySet[T <: AnyRef] {
def get[P <: Property[T]](property: PropertyDef[T, P]): P
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/rule/EnforcerRule.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/rule/EnforcerRule.scala
similarity index 78%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/rule/EnforcerRule.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/rule/EnforcerRule.scala
index 370469d57..c18936973 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/rule/EnforcerRule.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/rule/EnforcerRule.scala
@@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.rule
+package org.apache.gluten.ras.rule
-import org.apache.gluten.cbo.{Cbo, EnforcerRuleFactory, Property, PropertyDef}
-import org.apache.gluten.cbo.memo.Closure
-import org.apache.gluten.cbo.property.PropertySet
+import org.apache.gluten.ras.{EnforcerRuleFactory, Property, PropertyDef, Ras}
+import org.apache.gluten.ras.memo.Closure
+import org.apache.gluten.ras.property.PropertySet
import scala.collection.mutable
@@ -29,7 +29,7 @@ trait EnforcerRule[T <: AnyRef] {
}
object EnforcerRule {
- def apply[T <: AnyRef](rule: CboRule[T], constraint: Property[T]): EnforcerRule[T] = {
+ def apply[T <: AnyRef](rule: RasRule[T], constraint: Property[T]): EnforcerRule[T] = {
new EnforcerRuleImpl(rule, constraint)
}
@@ -38,7 +38,7 @@ object EnforcerRule {
}
private class EnforcerRuleImpl[T <: AnyRef](
- rule: CboRule[T],
+ rule: RasRule[T],
override val constraint: Property[T])
extends EnforcerRule[T] {
override def shift(node: T): Iterable[T] = rule.shift(node)
@@ -57,17 +57,17 @@ trait EnforcerRuleSet[T <: AnyRef] {
}
object EnforcerRuleSet {
- def apply[T <: AnyRef](cbo: Cbo[T], closure: Closure[T]): EnforcerRuleSet[T] = {
- new EnforcerRuleSetImpl(cbo, closure)
+ def apply[T <: AnyRef](ras: Ras[T], closure: Closure[T]): EnforcerRuleSet[T] = {
+ new EnforcerRuleSetImpl(ras, closure)
}
private def newEnforcerRuleFactory[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
propertyDef: PropertyDef[T, _ <: Property[T]]): EnforcerRuleFactory[T] = {
- cbo.propertyModel.newEnforcerRuleFactory(propertyDef)
+ ras.propertyModel.newEnforcerRuleFactory(propertyDef)
}
- private class EnforcerRuleSetImpl[T <: AnyRef](cbo: Cbo[T], closure: Closure[T])
+ private class EnforcerRuleSetImpl[T <: AnyRef](ras: Ras[T], closure: Closure[T])
extends EnforcerRuleSet[T] {
private val factoryBuffer =
mutable.Map[PropertyDef[T, _ <: Property[T]], EnforcerRuleFactory[T]]()
@@ -81,10 +81,10 @@ object EnforcerRuleSet {
val factory =
factoryBuffer.getOrElseUpdate(
constraintDef,
- newEnforcerRuleFactory(cbo, constraintDef))
- RuleApplier(cbo, closure, EnforcerRule.builtin(constraint)) +: factory
+ newEnforcerRuleFactory(ras, constraintDef))
+ RuleApplier(ras, closure, EnforcerRule.builtin(constraint)) +: factory
.newEnforcerRules(constraint)
- .map(rule => RuleApplier(cbo, closure, EnforcerRule(rule, constraint)))
+ .map(rule => RuleApplier(ras, closure, EnforcerRule(rule, constraint)))
}
)
}.toSeq
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/rule/CboRule.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/rule/RasRule.scala
similarity index 78%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/rule/CboRule.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/rule/RasRule.scala
index 1ddb783f1..0c3e7558e 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/rule/CboRule.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/rule/RasRule.scala
@@ -14,25 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.rule
+package org.apache.gluten.ras.rule
-trait CboRule[T <: AnyRef] {
+trait RasRule[T <: AnyRef] {
def shift(node: T): Iterable[T]
def shape(): Shape[T]
}
-object CboRule {
+object RasRule {
trait Factory[T <: AnyRef] {
- def create(): Seq[CboRule[T]]
+ def create(): Seq[RasRule[T]]
}
object Factory {
- def reuse[T <: AnyRef](rules: Seq[CboRule[T]]): Factory[T] = new SimpleReuse(rules)
+ def reuse[T <: AnyRef](rules: Seq[RasRule[T]]): Factory[T] = new SimpleReuse(rules)
def none[T <: AnyRef](): Factory[T] = new SimpleReuse[T](List.empty)
- private class SimpleReuse[T <: AnyRef](rules: Seq[CboRule[T]]) extends Factory[T] {
- override def create(): Seq[CboRule[T]] = rules
+ private class SimpleReuse[T <: AnyRef](rules: Seq[RasRule[T]]) extends Factory[T] {
+ override def create(): Seq[RasRule[T]] = rules
}
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/rule/RuleApplier.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/rule/RuleApplier.scala
similarity index 75%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/rule/RuleApplier.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/rule/RuleApplier.scala
index 64e214b3e..b99001e93 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/rule/RuleApplier.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/rule/RuleApplier.scala
@@ -14,37 +14,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.rule
+package org.apache.gluten.ras.rule
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.memo.Closure
-import org.apache.gluten.cbo.path.CboPath
-import org.apache.gluten.cbo.util.CanonicalNodeMap
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.memo.Closure
+import org.apache.gluten.ras.path.RasPath
+import org.apache.gluten.ras.util.CanonicalNodeMap
import scala.collection.mutable
trait RuleApplier[T <: AnyRef] {
- def apply(path: CboPath[T]): Unit
+ def apply(path: RasPath[T]): Unit
def shape(): Shape[T]
}
object RuleApplier {
- def apply[T <: AnyRef](cbo: Cbo[T], closure: Closure[T], rule: CboRule[T]): RuleApplier[T] = {
- new ShapeAwareRuleApplier[T](cbo, new RegularRuleApplier(cbo, closure, rule))
+ def apply[T <: AnyRef](ras: Ras[T], closure: Closure[T], rule: RasRule[T]): RuleApplier[T] = {
+ new ShapeAwareRuleApplier[T](ras, new RegularRuleApplier(ras, closure, rule))
}
def apply[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
closure: Closure[T],
rule: EnforcerRule[T]): RuleApplier[T] = {
- new ShapeAwareRuleApplier[T](cbo, new EnforcerRuleApplier[T](cbo, closure, rule))
+ new ShapeAwareRuleApplier[T](ras, new EnforcerRuleApplier[T](ras, closure, rule))
}
- private class RegularRuleApplier[T <: AnyRef](cbo: Cbo[T], closure: Closure[T], rule: CboRule[T])
+ private class RegularRuleApplier[T <: AnyRef](ras: Ras[T], closure: Closure[T], rule: RasRule[T])
extends RuleApplier[T] {
- private val cache = new CanonicalNodeMap[T, mutable.Set[T]](cbo)
+ private val cache = new CanonicalNodeMap[T, mutable.Set[T]](ras)
- override def apply(path: CboPath[T]): Unit = {
+ override def apply(path: RasPath[T]): Unit = {
val can = path.node().self().asCanonical()
val plan = path.plan()
val appliedPlans = cache.getOrElseUpdate(can, mutable.Set())
@@ -61,7 +61,7 @@ object RuleApplier {
equiv =>
closure
.openFor(can)
- .memorize(equiv, cbo.propertySetFactory().get(equiv))
+ .memorize(equiv, ras.propertySetFactory().get(equiv))
}
}
@@ -69,15 +69,15 @@ object RuleApplier {
}
private class EnforcerRuleApplier[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
closure: Closure[T],
rule: EnforcerRule[T])
extends RuleApplier[T] {
- private val cache = new CanonicalNodeMap[T, mutable.Set[T]](cbo)
+ private val cache = new CanonicalNodeMap[T, mutable.Set[T]](ras)
private val constraint = rule.constraint()
private val constraintDef = constraint.definition()
- override def apply(path: CboPath[T]): Unit = {
+ override def apply(path: RasPath[T]): Unit = {
val can = path.node().self().asCanonical()
if (can.propSet().get(constraintDef).satisfies(constraint)) {
return
@@ -92,7 +92,7 @@ object RuleApplier {
}
private def apply0(can: CanonicalNode[T], plan: T): Unit = {
- val propSet = cbo.propertySetFactory().get(plan)
+ val propSet = ras.propertySetFactory().get(plan)
val constraintSet = propSet.withProp(constraint)
val equivalents = rule.shift(plan)
equivalents.foreach {
@@ -106,11 +106,11 @@ object RuleApplier {
override def shape(): Shape[T] = rule.shape()
}
- private class ShapeAwareRuleApplier[T <: AnyRef](cbo: Cbo[T], rule: RuleApplier[T])
+ private class ShapeAwareRuleApplier[T <: AnyRef](ras: Ras[T], rule: RuleApplier[T])
extends RuleApplier[T] {
private val ruleShape = rule.shape()
- override def apply(path: CboPath[T]): Unit = {
+ override def apply(path: RasPath[T]): Unit = {
if (!ruleShape.identify(path)) {
return
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/rule/Shape.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/rule/Shape.scala
similarity index 84%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/rule/Shape.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/rule/Shape.scala
index c0077b3bd..400f0eeba 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/rule/Shape.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/rule/Shape.scala
@@ -14,16 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.rule
+package org.apache.gluten.ras.rule
-import org.apache.gluten.cbo.path.{CboPath, OutputWizard, OutputWizards}
+import org.apache.gluten.ras.path.{OutputWizard, OutputWizards, RasPath}
// Shape is an abstraction for all inputs the rule can accept.
// Shape can be specification on pattern, height, or mask
// to represent fuzzy, or precise structure of acceptable inputs.
trait Shape[T <: AnyRef] {
def wizard(): OutputWizard[T]
- def identify(path: CboPath[T]): Boolean
+ def identify(path: RasPath[T]): Boolean
}
object Shape {}
@@ -39,11 +39,11 @@ object Shapes {
private class FixedHeight[T <: AnyRef](height: Int) extends Shape[T] {
override def wizard(): OutputWizard[T] = OutputWizards.withMaxDepth(height)
- override def identify(path: CboPath[T]): Boolean = path.height() == height
+ override def identify(path: RasPath[T]): Boolean = path.height() == height
}
private class None[T <: AnyRef]() extends Shape[T] {
override def wizard(): OutputWizard[T] = OutputWizards.none()
- override def identify(path: CboPath[T]): Boolean = false
+ override def identify(path: RasPath[T]): Boolean = false
}
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/util/CycleDetector.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/util/CycleDetector.scala
similarity index 98%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/util/CycleDetector.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/util/CycleDetector.scala
index 429c1bc59..0f8cf116b 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/util/CycleDetector.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/util/CycleDetector.scala
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.util
+package org.apache.gluten.ras.util
trait CycleDetector[T <: Any] {
def append(obj: T): CycleDetector[T]
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/util/IndexDisjointSet.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/util/IndexDisjointSet.scala
similarity index 98%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/util/IndexDisjointSet.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/util/IndexDisjointSet.scala
index 387a0ff39..d9155df8c 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/util/IndexDisjointSet.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/util/IndexDisjointSet.scala
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.util
+package org.apache.gluten.ras.util
import scala.collection.mutable
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/util/NodeMap.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/util/NodeMap.scala
similarity index 81%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/util/NodeMap.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/util/NodeMap.scala
index 1b9e1d816..887e00bdc 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/util/NodeMap.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/util/NodeMap.scala
@@ -14,19 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.util
+package org.apache.gluten.ras.util
-import org.apache.gluten.cbo.{CanonicalNode, Cbo}
+import org.apache.gluten.ras.{CanonicalNode, Ras}
import scala.collection.mutable
// Arbitrary node key.
-class NodeKey[T <: AnyRef](cbo: Cbo[T], val node: T) {
- override def hashCode(): Int = cbo.planModel.hashCode(node)
+class NodeKey[T <: AnyRef](ras: Ras[T], val node: T) {
+ override def hashCode(): Int = ras.planModel.hashCode(node)
override def equals(obj: Any): Boolean = {
obj match {
- case other: NodeKey[T] => cbo.planModel.equals(node, other.node)
+ case other: NodeKey[T] => ras.planModel.equals(node, other.node)
case _ => false
}
}
@@ -35,7 +35,7 @@ class NodeKey[T <: AnyRef](cbo: Cbo[T], val node: T) {
}
// Canonical node map.
-class CanonicalNodeMap[T <: AnyRef, V](cbo: Cbo[T]) {
+class CanonicalNodeMap[T <: AnyRef, V](ras: Ras[T]) {
private val map: mutable.Map[NodeKey[T], V] = mutable.Map()
def contains(node: CanonicalNode[T]): Boolean = {
@@ -55,6 +55,6 @@ class CanonicalNodeMap[T <: AnyRef, V](cbo: Cbo[T]) {
}
private def keyOf(node: CanonicalNode[T]): NodeKey[T] = {
- new NodeKey(cbo, node.self())
+ new NodeKey(ras, node.self())
}
}
diff --git a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/vis/GraphvizVisualizer.scala b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/vis/GraphvizVisualizer.scala
similarity index 82%
rename from gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/vis/GraphvizVisualizer.scala
rename to gluten-ras/common/src/main/scala/org/apache/gluten/ras/vis/GraphvizVisualizer.scala
index 940c98610..600a61edc 100644
--- a/gluten-cbo/common/src/main/scala/org/apache/gluten/cbo/vis/GraphvizVisualizer.scala
+++ b/gluten-ras/common/src/main/scala/org/apache/gluten/ras/vis/GraphvizVisualizer.scala
@@ -14,17 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.vis
+package org.apache.gluten.ras.vis
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.best.BestFinder
-import org.apache.gluten.cbo.memo.MemoState
-import org.apache.gluten.cbo.path._
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.best.BestFinder
+import org.apache.gluten.ras.memo.MemoState
+import org.apache.gluten.ras.path._
import scala.collection.mutable
// Visualize the planning procedure using dot language.
-class GraphvizVisualizer[T <: AnyRef](cbo: Cbo[T], memoState: MemoState[T], best: Best[T]) {
+class GraphvizVisualizer[T <: AnyRef](ras: Ras[T], memoState: MemoState[T], best: Best[T]) {
private val allGroups = memoState.allGroups()
private val allClusters = memoState.clusterLookup()
@@ -42,18 +42,18 @@ class GraphvizVisualizer[T <: AnyRef](cbo: Cbo[T], memoState: MemoState[T], best
buf.append(" compound=true;\n")
object IsBestNode {
- def unapply(nodeAndGroupToTest: (CanonicalNode[T], CboGroup[T])): Boolean = {
+ def unapply(nodeAndGroupToTest: (CanonicalNode[T], RasGroup[T])): Boolean = {
bestNodes.contains(InGroupNode(nodeAndGroupToTest._2.id(), nodeAndGroupToTest._1))
}
}
object IsWinnerNode {
- def unapply(nodeAndGroupToTest: (CanonicalNode[T], CboGroup[T])): Boolean = {
+ def unapply(nodeAndGroupToTest: (CanonicalNode[T], RasGroup[T])): Boolean = {
winnerNodes.contains(InGroupNode(nodeAndGroupToTest._2.id(), nodeAndGroupToTest._1))
}
}
- val clusterToGroups: mutable.Map[CboClusterKey, mutable.Set[Int]] = mutable.Map()
+ val clusterToGroups: mutable.Map[RasClusterKey, mutable.Set[Int]] = mutable.Map()
allGroups.foreach {
group => clusterToGroups.getOrElseUpdate(group.clusterKey(), mutable.Set()).add(group.id())
@@ -109,7 +109,7 @@ class GraphvizVisualizer[T <: AnyRef](cbo: Cbo[T], memoState: MemoState[T], best
}
}
- def drawBest(bestNode: CboPath.PathNode[T], bestGroup: CboGroup[T]): Unit = {
+ def drawBest(bestNode: RasPath.PathNode[T], bestGroup: RasGroup[T]): Unit = {
val canonical = bestNode.self().asCanonical()
bestNode
.zipChildrenWithGroups(allGroups)
@@ -128,7 +128,7 @@ class GraphvizVisualizer[T <: AnyRef](cbo: Cbo[T], memoState: MemoState[T], best
// Since there might be cases that best path was not found for some reason and
// user needs the graph for debug purpose, we loose the restriction on best path
// here by filtering out the illegal ones.
- val rootNode = bestPath.cboPath.node()
+ val rootNode = bestPath.rasPath.node()
if (rootNode.self().isCanonical) {
drawBest(rootNode, rootGroup)
}
@@ -137,44 +137,44 @@ class GraphvizVisualizer[T <: AnyRef](cbo: Cbo[T], memoState: MemoState[T], best
buf.toString()
}
- private def describeCluster(cluster: CboClusterKey): String = {
+ private def describeCluster(cluster: RasClusterKey): String = {
s"[Cluster $cluster]"
}
- private def describeGroup(group: CboGroup[T]): String = {
+ private def describeGroup(group: RasGroup[T]): String = {
s"[Group ${group.id()}]"
}
- private def describeGroupVerbose(group: CboGroup[T]): String = {
+ private def describeGroupVerbose(group: RasGroup[T]): String = {
s"[Group ${group.id()}: ${group.propSet().getMap.values.toIndexedSeq}]"
}
private def describeNode(
costs: InGroupNode[T] => Option[Cost],
- group: CboGroup[T],
+ group: RasGroup[T],
node: CanonicalNode[T]): String = {
s"${describeGroup(group)}[Cost ${costs(InGroupNode(group.id(), node))
.map {
- case c if cbo.isInfCost(c) => "<INF>"
+ case c if ras.isInfCost(c) => "<INF>"
case other => other
}
- .getOrElse("N/A")}]${cbo.explain.describeNode(node.self())}"
+ .getOrElse("N/A")}]${ras.explain.describeNode(node.self())}"
}
}
object GraphvizVisualizer {
- private class FakeBestFinder[T <: AnyRef](cbo: Cbo[T], allGroups: Int => CboGroup[T])
+ private class FakeBestFinder[T <: AnyRef](ras: Ras[T], allGroups: Int => RasGroup[T])
extends BestFinder[T] {
import FakeBestFinder._
override def bestOf(groupId: Int): Best[T] = {
- new FakeBest(cbo, allGroups, groupId)
+ new FakeBest(ras, allGroups, groupId)
}
}
private object FakeBestFinder {
private class FakeBest[T <: AnyRef](
- cbo: Cbo[T],
- allGroups: Int => CboGroup[T],
+ ras: Ras[T],
+ allGroups: Int => RasGroup[T],
rootGroupId: Int)
extends Best[T] {
override def rootGroupId(): Int = {
@@ -190,25 +190,25 @@ object GraphvizVisualizer {
override def path(): Best.KnownCostPath[T] = {
Best.KnownCostPath(
- CboPath.zero(cbo, PathKeySet.trivial, GroupNode(cbo, allGroups(rootGroupId))),
- cbo.getInfCost())
+ RasPath.zero(ras, PathKeySet.trivial, GroupNode(ras, allGroups(rootGroupId))),
+ ras.getInfCost())
}
}
}
def apply[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
memoState: MemoState[T],
rootGroupId: Int): GraphvizVisualizer[T] = {
- val fakeBestFinder = new FakeBestFinder[T](cbo, memoState.allGroups())
+ val fakeBestFinder = new FakeBestFinder[T](ras, memoState.allGroups())
val fakeBest = fakeBestFinder.bestOf(rootGroupId)
- new GraphvizVisualizer(cbo, memoState, fakeBest)
+ new GraphvizVisualizer(ras, memoState, fakeBest)
}
def apply[T <: AnyRef](
- cbo: Cbo[T],
+ ras: Ras[T],
memoState: MemoState[T],
best: Best[T]): GraphvizVisualizer[T] = {
- new GraphvizVisualizer(cbo, memoState, best)
+ new GraphvizVisualizer(ras, memoState, best)
}
}
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboMetadataSuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/MetadataSuite.scala
similarity index 83%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboMetadataSuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/MetadataSuite.scala
index ce5d20b93..50c37ca9d 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboMetadataSuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/MetadataSuite.scala
@@ -14,44 +14,44 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.CboConfig.PlannerType
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.rule.{CboRule, Shape, Shapes}
+import org.apache.gluten.ras.RasConfig.PlannerType
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.rule.{RasRule, Shape, Shapes}
import org.scalatest.funsuite.AnyFunSuite
-class ExhaustiveCboMetadataSuite extends CboMetadataSuite {
- override protected def conf: CboConfig = CboConfig(plannerType = PlannerType.Exhaustive)
+class ExhaustiveMetadataSuite extends MetadataSuite {
+ override protected def conf: RasConfig = RasConfig(plannerType = PlannerType.Exhaustive)
}
-class DpCboMetadataSuite extends CboMetadataSuite {
- override protected def conf: CboConfig = CboConfig(plannerType = PlannerType.Dp)
+class DpMetadataSuite extends MetadataSuite {
+ override protected def conf: RasConfig = RasConfig(plannerType = PlannerType.Dp)
}
-abstract class CboMetadataSuite extends AnyFunSuite {
- import CboMetadataSuite._
- protected def conf: CboConfig
+abstract class MetadataSuite extends AnyFunSuite {
+ import MetadataSuite._
+ protected def conf: RasConfig
test("Dry run") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
RowCountMetadataModel,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
- val planner = cbo.newPlanner(KnownRowCountUnary(0.5, KnownRowCountLeaf(2000)))
+ val planner = ras.newPlanner(KnownRowCountUnary(0.5, KnownRowCountLeaf(2000)))
val out = planner.plan()
assert(out == KnownRowCountUnary(0.5, KnownRowCountLeaf(2000)))
}
test("Trivial planning") {
- object CombineUnaryNodes extends CboRule[TestNode] {
+ object CombineUnaryNodes extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case KnownRowCountUnary(0.25d, KnownRowCountUnary(2.0d, child)) =>
assert(child.isInstanceOf[Group])
@@ -64,24 +64,24 @@ abstract class CboMetadataSuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
RowCountMetadataModel,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(CombineUnaryNodes)))
+ RasRule.Factory.reuse(List(CombineUnaryNodes)))
.withNewConfig(_ => conf)
val planner =
- cbo.newPlanner(KnownRowCountUnary(0.25d, KnownRowCountUnary(2.0d, KnownRowCountLeaf(2000))))
+ ras.newPlanner(KnownRowCountUnary(0.25d, KnownRowCountUnary(2.0d, KnownRowCountLeaf(2000))))
val out = planner.plan()
assert(out == KnownRowCountUnary(0.5d, KnownRowCountLeaf(2000)))
}
test("Cluster merge") {
- object CombineUnaryNodes extends CboRule[TestNode] {
+ object CombineUnaryNodes extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case KnownRowCountUnary(0.25d, KnownRowCountUnary(2.0d, child)) =>
assert(child.isInstanceOf[Group])
@@ -94,20 +94,20 @@ abstract class CboMetadataSuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
RowCountMetadataModel,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(CombineUnaryNodes)))
+ RasRule.Factory.reuse(List(CombineUnaryNodes)))
.withNewConfig(_ => conf)
val in = KnownRowCountBinary(
KnownRowCountUnary(0.5d, KnownRowCountLeaf(2000)),
KnownRowCountUnary(0.25d, KnownRowCountUnary(2.0d, KnownRowCountLeaf(2000))))
- val planner = cbo.newPlanner(in)
+ val planner = ras.newPlanner(in)
val out = planner.plan()
assert(
out == KnownRowCountBinary(
@@ -116,7 +116,7 @@ abstract class CboMetadataSuite extends AnyFunSuite {
}
}
-object CboMetadataSuite {
+object MetadataSuite {
private object RowCountMetadataModel extends MetadataModel[TestNode] {
override def metadataOf(node: TestNode): Metadata = node match {
case n: KnownRowCountNode =>
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboOperationSuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/OperationSuite.scala
similarity index 88%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboOperationSuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/OperationSuite.scala
index 4f53e067a..acd96442c 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboOperationSuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/OperationSuite.scala
@@ -14,23 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.path.CboPath
-import org.apache.gluten.cbo.property.PropertySet
-import org.apache.gluten.cbo.rule.{CboRule, Shape, Shapes}
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.path.RasPath
+import org.apache.gluten.ras.property.PropertySet
+import org.apache.gluten.ras.rule.{RasRule, Shape, Shapes}
import org.scalatest.funsuite.AnyFunSuite
-class CboOperationSuite extends AnyFunSuite {
- import CboOperationSuite._
+class OperationSuite extends AnyFunSuite {
+ import OperationSuite._
test(s"Rule invocation count - depth 2, 1") {
val l2l2 = new LeafToLeaf2()
val u2u2 = new UnaryToUnary2()
- object Unary2Unary2ToUnary3 extends CboRule[TestNode] {
+ object Unary2Unary2ToUnary3 extends RasRule[TestNode] {
var invocationCount: Int = 0
var effectiveInvocationCount: Int = 0
override def shift(node: TestNode): Iterable[TestNode] = {
@@ -46,16 +46,16 @@ class CboOperationSuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(l2l2, u2u2, Unary2Unary2ToUnary3)))
+ RasRule.Factory.reuse(List(l2l2, u2u2, Unary2Unary2ToUnary3)))
val plan = Unary(50, Unary2(50, Unary2(50, Unary2(50, Leaf(30)))))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(Unary2Unary2ToUnary3.invocationCount == 14)
@@ -68,16 +68,16 @@ class CboOperationSuite extends AnyFunSuite {
val u2u2 = new UnaryToUnary2()
val u2u22u3 = new Unary2Unary2ToUnary3()
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(l2l2, u2u2, u2u22u3)))
+ RasRule.Factory.reuse(List(l2l2, u2u2, u2u22u3)))
val plan = Unary(50, Unary2(50, Unary2(50, Unary2(50, Leaf(30)))))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(l2l2.invocationCount == 10)
@@ -95,23 +95,23 @@ class CboOperationSuite extends AnyFunSuite {
val planModel = new PlanModelWithStats(PlanModelImpl)
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(l2l2, u2u2)))
+ RasRule.Factory.reuse(List(l2l2, u2u2)))
val plan = Unary(50, Leaf(30))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(optimized == Unary2(49, Leaf2(29)))
planModel.assertPlanOpsLte((200, 50, 50, 50))
val state = planner.newState()
- val allPaths = state.memoState().collectAllPaths(CboPath.INF_DEPTH).toSeq
+ val allPaths = state.memoState().collectAllPaths(RasPath.INF_DEPTH).toSeq
val distinctPathCount = allPaths.distinct.size
val pathCount = allPaths.size
assert(distinctPathCount == pathCount)
@@ -125,23 +125,23 @@ class CboOperationSuite extends AnyFunSuite {
val planModel = new PlanModelWithStats(PlanModelImpl)
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(l2l2, u2u2, u2u22u3)))
+ RasRule.Factory.reuse(List(l2l2, u2u2, u2u22u3)))
val plan = Unary(50, Unary2(50, Unary2(50, Unary2(50, Leaf(30)))))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(optimized == Unary3(98, Unary3(99, Leaf2(29))))
planModel.assertPlanOpsLte((800, 300, 300, 200))
val state = planner.newState()
- val allPaths = state.memoState().collectAllPaths(CboPath.INF_DEPTH).toSeq
+ val allPaths = state.memoState().collectAllPaths(RasPath.INF_DEPTH).toSeq
val distinctPathCount = allPaths.distinct.size
val pathCount = allPaths.size
assert(distinctPathCount == pathCount)
@@ -149,7 +149,7 @@ class CboOperationSuite extends AnyFunSuite {
}
test("Plan manipulation count - depth 5") {
- val rule = new CboRule[TestNode] {
+ val rule = new RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case Unary(c1, Unary(c2, Unary(c3, Unary(c4, Unary(c5, child))))) =>
List(Unary2(c1, Unary2(c2, Unary2(c3 - 6, Unary2(c4, Unary2(c5, child))))))
@@ -161,14 +161,14 @@ class CboOperationSuite extends AnyFunSuite {
val planModel = new PlanModelWithStats(PlanModelImpl)
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(new UnaryToUnary2(), new LeafToLeaf2(), rule)))
+ RasRule.Factory.reuse(List(new UnaryToUnary2(), new LeafToLeaf2(), rule)))
val plan = Unary(
50,
Unary(
@@ -176,7 +176,7 @@ class CboOperationSuite extends AnyFunSuite {
Unary(
50,
Unary(50, Unary(50, Unary(50, Unary(50, Unary(50, Unary(50, Unary(50, Leaf(30)))))))))))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(
optimized == Unary2(
@@ -192,7 +192,7 @@ class CboOperationSuite extends AnyFunSuite {
planModel.assertPlanOpsLte((20000, 10000, 3000, 3000))
val state = planner.newState()
- val allPaths = state.memoState().collectAllPaths(CboPath.INF_DEPTH).toSeq
+ val allPaths = state.memoState().collectAllPaths(RasPath.INF_DEPTH).toSeq
val distinctPathCount = allPaths.distinct.size
val pathCount = allPaths.size
assert(distinctPathCount == pathCount)
@@ -202,14 +202,14 @@ class CboOperationSuite extends AnyFunSuite {
test("Cost evaluation count - base") {
val costModel = new CostModelWithStats(CostModelImpl)
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
costModel,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(new UnaryToUnary2, new Unary2ToUnary3)))
+ RasRule.Factory.reuse(List(new UnaryToUnary2, new Unary2ToUnary3)))
val plan = Unary(
50,
Unary(
@@ -217,7 +217,7 @@ class CboOperationSuite extends AnyFunSuite {
Unary(
50,
Unary(50, Unary(50, Unary(50, Unary(50, Unary(50, Unary(50, Unary(50, Leaf(30)))))))))))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(
optimized == Unary3(
@@ -264,14 +264,14 @@ class CboOperationSuite extends AnyFunSuite {
val costModel = new CostModelWithStats(costModelPruned)
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
costModel,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(new UnaryToUnary2, new Unary2ToUnary3)))
+ RasRule.Factory.reuse(List(new UnaryToUnary2, new Unary2ToUnary3)))
val plan = Unary(
50,
Unary(
@@ -279,7 +279,7 @@ class CboOperationSuite extends AnyFunSuite {
Unary(
50,
Unary(50, Unary(50, Unary(50, Unary(50, Unary(50, Unary(50, Unary(50, Leaf(30)))))))))))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(
optimized == Unary3(
@@ -296,7 +296,7 @@ class CboOperationSuite extends AnyFunSuite {
}
}
-object CboOperationSuite {
+object OperationSuite {
case class Unary(override val selfCost: Long, override val child: TestNode) extends UnaryLike {
override def withNewChildren(child: TestNode): UnaryLike = copy(child = child)
@@ -318,7 +318,7 @@ object CboOperationSuite {
override def makeCopy(): LeafLike = copy()
}
- class LeafToLeaf2 extends CboRule[TestNode] {
+ class LeafToLeaf2 extends RasRule[TestNode] {
var invocationCount: Int = 0
var effectiveInvocationCount: Int = 0
@@ -335,7 +335,7 @@ object CboOperationSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- class UnaryToUnary2 extends CboRule[TestNode] {
+ class UnaryToUnary2 extends RasRule[TestNode] {
var invocationCount: Int = 0
var effectiveInvocationCount: Int = 0
@@ -352,7 +352,7 @@ object CboOperationSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- class Unary2ToUnary3 extends CboRule[TestNode] {
+ class Unary2ToUnary3 extends RasRule[TestNode] {
var invocationCount: Int = 0
var effectiveInvocationCount: Int = 0
@@ -369,7 +369,7 @@ object CboOperationSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- class Unary2Unary2ToUnary3 extends CboRule[TestNode] {
+ class Unary2Unary2ToUnary3 extends RasRule[TestNode] {
var invocationCount: Int = 0
var effectiveInvocationCount: Int = 0
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboPropertySuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/PropertySuite.scala
similarity index 86%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboPropertySuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/PropertySuite.scala
index d9e4adc6b..8a68bbba8 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboPropertySuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/PropertySuite.scala
@@ -14,28 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.Best.BestNotFoundException
-import org.apache.gluten.cbo.CboConfig.PlannerType
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.property.PropertySet
-import org.apache.gluten.cbo.rule.{CboRule, Shape, Shapes}
+import org.apache.gluten.ras.Best.BestNotFoundException
+import org.apache.gluten.ras.RasConfig.PlannerType
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.property.PropertySet
+import org.apache.gluten.ras.rule.{RasRule, Shape, Shapes}
import org.scalatest.funsuite.AnyFunSuite
-class ExhaustivePlannerPropertySuite extends CboPropertySuite {
- override protected def conf: CboConfig = CboConfig(plannerType = PlannerType.Exhaustive)
+class ExhaustivePlannerPropertySuite extends PropertySuite {
+ override protected def conf: RasConfig = RasConfig(plannerType = PlannerType.Exhaustive)
}
-class DpPlannerPropertySuite extends CboPropertySuite {
- override protected def conf: CboConfig = CboConfig(plannerType = PlannerType.Dp)
+class DpPlannerPropertySuite extends PropertySuite {
+ override protected def conf: RasConfig = RasConfig(plannerType = PlannerType.Dp)
}
-abstract class CboPropertySuite extends AnyFunSuite {
- import CboPropertySuite._
+abstract class PropertySuite extends AnyFunSuite {
+ import PropertySuite._
- protected def conf: CboConfig
+ protected def conf: RasConfig
test(s"Get property") {
val leaf = PLeaf(10, DummyProperty(0))
@@ -56,53 +56,53 @@ abstract class CboPropertySuite extends AnyFunSuite {
}
test(s"Cannot enforce property") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
NodeTypePropertyModelWithOutEnforcerRules,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
val plan = TypedUnary(TypeA, 10, TypedLeaf(TypeA, 10))
- val planner = cbo.newPlanner(plan, PropertySet(Seq(TypeB)))
+ val planner = ras.newPlanner(plan, PropertySet(Seq(TypeB)))
assertThrows[BestNotFoundException] {
planner.plan()
}
}
test(s"Property enforcement - A to B") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
NodeTypePropertyModel,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
val plan =
TypedBinary(TypeA, 5, TypedUnary(TypeA, 10, TypedLeaf(TypeA, 10)), TypedLeaf(TypeA, 10))
- val planner = cbo.newPlanner(plan, PropertySet(Seq(TypeB)))
+ val planner = ras.newPlanner(plan, PropertySet(Seq(TypeB)))
val out = planner.plan()
assert(out == TypeEnforcer(TypeB, 1, plan))
}
test(s"Property convert - (A, B)") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
NodeTypePropertyModel,
ExplainImpl,
- CboRule.Factory.reuse(List(ReplaceByTypeARule, ReplaceByTypeBRule)))
+ RasRule.Factory.reuse(List(ReplaceByTypeARule, ReplaceByTypeBRule)))
.withNewConfig(_ => conf)
val plan =
TypedBinary(TypeA, 5, TypedUnary(TypeA, 10, TypedLeaf(TypeA, 10)), TypedLeaf(TypeA, 10))
- val planner = cbo.newPlanner(plan, PropertySet(Seq(TypeB)))
+ val planner = ras.newPlanner(plan, PropertySet(Seq(TypeB)))
val out = planner.plan()
assert(
out == TypedBinary(
@@ -113,7 +113,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
}
ignore(s"Memo cache hit - (A, B)") {
- object ReplaceLeafAByLeafBRule extends CboRule[TestNode] {
+ object ReplaceLeafAByLeafBRule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case TypedLeaf(TypeA, cost) => List(TypedLeaf(TypeB, cost - 1))
@@ -124,7 +124,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- object HitCacheOp extends CboRule[TestNode] {
+ object HitCacheOp extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case PassNodeType(10, TypedLeaf(TypeA, 10)) =>
@@ -135,7 +135,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- object FinalOp extends CboRule[TestNode] {
+ object FinalOp extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
@@ -147,19 +147,19 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(3)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
NodeTypePropertyModelWithOutEnforcerRules,
ExplainImpl,
- CboRule.Factory.reuse(List(ReplaceLeafAByLeafBRule, HitCacheOp, FinalOp))
+ RasRule.Factory.reuse(List(ReplaceLeafAByLeafBRule, HitCacheOp, FinalOp))
)
.withNewConfig(_ => conf)
val plan = PassNodeType(10, TypedLeaf(TypeA, 10))
- val planner = cbo.newPlanner(plan, PropertySet(Seq(TypeA)))
+ val planner = ras.newPlanner(plan, PropertySet(Seq(TypeA)))
val out = planner.plan()
assert(out == TypedLeaf(TypeA, 1))
@@ -171,7 +171,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
test(s"Property propagation - (A, B)") {
// The propagation is expected to be done by built-in enforcer rule.
- object ReplaceLeafAByLeafBRule extends CboRule[TestNode] {
+ object ReplaceLeafAByLeafBRule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case TypedLeaf(TypeA, cost) => List(TypedLeaf(TypeB, cost - 1))
@@ -182,7 +182,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- object ReplaceUnaryBByUnaryARule extends CboRule[TestNode] {
+ object ReplaceUnaryBByUnaryARule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case TypedUnary(TypeB, cost, child) => List(TypedUnary(TypeA, cost - 2, child))
@@ -193,27 +193,27 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
NodeTypePropertyModelWithOutEnforcerRules,
ExplainImpl,
- CboRule.Factory.reuse(List(ReplaceLeafAByLeafBRule, ReplaceUnaryBByUnaryARule))
+ RasRule.Factory.reuse(List(ReplaceLeafAByLeafBRule, ReplaceUnaryBByUnaryARule))
)
.withNewConfig(_ => conf)
val sub =
PassNodeType(5, TypedLeaf(TypeA, 10))
val plan = TypedUnary(TypeB, 10, sub)
- val planner = cbo.newPlanner(plan, PropertySet(Seq(TypeAny)))
+ val planner = ras.newPlanner(plan, PropertySet(Seq(TypeAny)))
val out = planner.plan()
assert(out == TypedUnary(TypeA, 8, PassNodeType(5, TypedLeaf(TypeA, 10))))
}
test(s"Property convert - (A, B), alternative conventions") {
- object ConvertEnforcerAndTypeAToTypeB extends CboRule[TestNode] {
+ object ConvertEnforcerAndTypeAToTypeB extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case TypeEnforcer(TypeB, _, TypedBinary(TypeA, 5, left, right)) =>
List(TypedBinary(TypeB, 0, left, right))
@@ -222,18 +222,18 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
NodeTypePropertyModel,
ExplainImpl,
- CboRule.Factory.reuse(List(ConvertEnforcerAndTypeAToTypeB)))
+ RasRule.Factory.reuse(List(ConvertEnforcerAndTypeAToTypeB)))
.withNewConfig(_ => conf)
val plan =
TypedBinary(TypeA, 5, TypedUnary(TypeA, 10, TypedLeaf(TypeA, 10)), TypedLeaf(TypeA, 10))
- val planner = cbo.newPlanner(
+ val planner = ras.newPlanner(
plan,
PropertySet(Seq(TypeAny)),
List(PropertySet(Seq(TypeB)), PropertySet(Seq(TypeC))))
@@ -248,7 +248,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
}
test(s"Property convert - (A, B), Unary only has TypeA") {
- object ReplaceNonUnaryByTypeBRule extends CboRule[TestNode] {
+ object ReplaceNonUnaryByTypeBRule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case TypedLeaf(_, cost) => List(TypedLeaf(TypeB, cost))
@@ -260,19 +260,19 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
NodeTypePropertyModel,
ExplainImpl,
- CboRule.Factory.reuse(List(ReplaceByTypeARule, ReplaceNonUnaryByTypeBRule))
+ RasRule.Factory.reuse(List(ReplaceByTypeARule, ReplaceNonUnaryByTypeBRule))
)
.withNewConfig(_ => conf)
val plan =
TypedBinary(TypeA, 5, TypedUnary(TypeA, 10, TypedLeaf(TypeA, 10)), TypedLeaf(TypeA, 10))
- val planner = cbo.newPlanner(plan, PropertySet(Seq(TypeB)))
+ val planner = ras.newPlanner(plan, PropertySet(Seq(TypeB)))
val out = planner.plan()
assert(
out == TypeEnforcer(
@@ -290,7 +290,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
}
test(s"Property convert - (A, B, C), TypeC has lowest cost") {
- object ReduceTypeBCost extends CboRule[TestNode] {
+ object ReduceTypeBCost extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case TypedLeaf(TypeB, _) => List(TypedLeaf(TypeB, 5))
@@ -303,7 +303,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- object ConvertUnaryTypeBToTypeC extends CboRule[TestNode] {
+ object ConvertUnaryTypeBToTypeC extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case TypedUnary(TypeB, _, child) => List(TypedUnary(TypeC, 0, child))
case other => List.empty
@@ -312,19 +312,19 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
NodeTypePropertyModel,
ExplainImpl,
- CboRule.Factory.reuse(List(ReduceTypeBCost, ConvertUnaryTypeBToTypeC)))
+ RasRule.Factory.reuse(List(ReduceTypeBCost, ConvertUnaryTypeBToTypeC)))
.withNewConfig(_ => conf)
val plan =
TypedUnary(TypeB, 10, TypedLeaf(TypeA, 20))
- val planner = cbo.newPlanner(plan, PropertySet(Seq(TypeB)))
+ val planner = ras.newPlanner(plan, PropertySet(Seq(TypeB)))
val out = planner.plan()
assert(
out == TypeEnforcer(
@@ -337,7 +337,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
s"Property convert - (A, B, C), TypeC has lowest cost, binary root," +
s" right enforcer added after left is explored, disordered group creation") {
- object RightOp extends CboRule[TestNode] {
+ object RightOp extends RasRule[TestNode] {
// Let the right child tree add group A to the leaf.
override def shift(node: TestNode): Iterable[TestNode] = node match {
case TypedUnary(TypeA, 15, TypedLeaf(TypeA, 20)) =>
@@ -352,7 +352,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- object LeftOp extends CboRule[TestNode] {
+ object LeftOp extends RasRule[TestNode] {
// The the left child tree should be aware of the enforcer and continue exploration.
override def shift(node: TestNode): Iterable[TestNode] = node match {
case TypedUnary(TypeA, 10, TypedLeaf(TypeA, 100)) =>
@@ -364,21 +364,21 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
NodeTypePropertyModel,
ExplainImpl,
- CboRule.Factory.reuse(List(LeftOp, RightOp))
+ RasRule.Factory.reuse(List(LeftOp, RightOp))
)
.withNewConfig(_ => conf)
val left = TypedUnary(TypeA, 10, TypedLeaf(TypeA, 20))
val right = TypeEnforcer(TypeA, 1, TypedUnary(TypeA, 15, TypedLeaf(TypeA, 20)))
val plan = TypedBinary(TypeA, 10, left, right)
- val planner = cbo.newPlanner(plan, PropertySet(Seq(TypeA)))
+ val planner = ras.newPlanner(plan, PropertySet(Seq(TypeA)))
val out = planner.plan()
assert(
out == TypedBinary(
@@ -391,7 +391,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
test(
s"Property convert - (A, B, C), TypeC has lowest cost, binary root," +
s" right enforcer added after left is explored, merge") {
- object ConvertTypeBEnforcerAndLeafToTypeC extends CboRule[TestNode] {
+ object ConvertTypeBEnforcerAndLeafToTypeC extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case TypeEnforcer(TypeB, _, _ @TypedLeaf(_, _)) =>
List(TypedLeaf(TypeC, 0))
@@ -401,7 +401,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- object ConvertTypeATypeCToTypeC extends CboRule[TestNode] {
+ object ConvertTypeATypeCToTypeC extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case TypedUnary(TypeA, _, TypeEnforcer(TypeA, _, _ @TypedLeaf(TypeC, _))) =>
List(TypedLeaf(TypeC, 0))
@@ -411,14 +411,14 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(3)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
NodeTypePropertyModel,
ExplainImpl,
- CboRule.Factory.reuse(List(ConvertTypeBEnforcerAndLeafToTypeC, ConvertTypeATypeCToTypeC))
+ RasRule.Factory.reuse(List(ConvertTypeBEnforcerAndLeafToTypeC, ConvertTypeATypeCToTypeC))
)
.withNewConfig(_ => conf)
@@ -427,7 +427,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
val right =
TypedUnary(TypeB, 15, TypedUnary(TypeB, 15, TypedLeaf(TypeA, 20)))
val plan = TypedBinary(TypeB, 10, left, right)
- val planner = cbo.newPlanner(plan, PropertySet(Seq(TypeB)))
+ val planner = ras.newPlanner(plan, PropertySet(Seq(TypeB)))
val out = planner.plan()
assert(
out == TypedBinary(
@@ -439,7 +439,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
test(s"Property convert - (A, B), Unary only has TypeA, TypeB has lowest cost") {
// TODO: Apply enforce rules on low-cost nodes to propagate it to other groups.
- object ReduceTypeBCost extends CboRule[TestNode] {
+ object ReduceTypeBCost extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case TypedLeaf(TypeB, _) => List(TypedLeaf(TypeB, 0))
@@ -452,7 +452,7 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- object ReplaceNonUnaryByTypeBRule extends CboRule[TestNode] {
+ object ReplaceNonUnaryByTypeBRule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case TypedLeaf(_, cost) => List(TypedLeaf(TypeB, cost))
@@ -464,19 +464,19 @@ abstract class CboPropertySuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
NodeTypePropertyModel,
ExplainImpl,
- CboRule.Factory.reuse(List(ReplaceNonUnaryByTypeBRule, ReduceTypeBCost))
+ RasRule.Factory.reuse(List(ReplaceNonUnaryByTypeBRule, ReduceTypeBCost))
)
.withNewConfig(_ => conf)
val plan =
TypedBinary(TypeA, 5, TypedUnary(TypeA, 10, TypedLeaf(TypeA, 10)), TypedLeaf(TypeA, 10))
- val planner = cbo.newPlanner(plan, PropertySet(Seq(TypeB)))
+ val planner = ras.newPlanner(plan, PropertySet(Seq(TypeB)))
val out = planner.plan()
assert(
out == TypedBinary(
@@ -487,9 +487,9 @@ abstract class CboPropertySuite extends AnyFunSuite {
}
}
-object CboPropertySuite {
+object PropertySuite {
- case class NoopEnforcerRule[T <: AnyRef]() extends CboRule[T] {
+ case class NoopEnforcerRule[T <: AnyRef]() extends RasRule[T] {
override def shift(node: T): Iterable[T] = List.empty
override def shape(): Shape[T] = Shapes.none()
}
@@ -613,7 +613,7 @@ object CboPropertySuite {
override def withNewChildren(children: Seq[TestNode]): TestNode = copy(selfCost, children.head)
}
- case class NodeTypeEnforcerRule(reqType: NodeType) extends CboRule[TestNode] {
+ case class NodeTypeEnforcerRule(reqType: NodeType) extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case typed: TypedNode if typed.nodeType.satisfies(reqType) => List(typed)
@@ -625,7 +625,7 @@ object CboPropertySuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- object ReplaceByTypeARule extends CboRule[TestNode] {
+ object ReplaceByTypeARule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case TypedLeaf(_, cost) => List(TypedLeaf(TypeA, cost))
@@ -638,7 +638,7 @@ object CboPropertySuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- object ReplaceByTypeBRule extends CboRule[TestNode] {
+ object ReplaceByTypeBRule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case TypedLeaf(_, cost) => List(TypedLeaf(TypeB, cost))
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboSuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/RasSuite.scala
similarity index 76%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboSuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/RasSuite.scala
index a981d9942..abb8bdecd 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboSuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/RasSuite.scala
@@ -14,123 +14,123 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.CboConfig.PlannerType
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.memo.Memo
-import org.apache.gluten.cbo.rule.{CboRule, Shape, Shapes}
+import org.apache.gluten.ras.RasConfig.PlannerType
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.memo.Memo
+import org.apache.gluten.ras.rule.{RasRule, Shape, Shapes}
import org.scalatest.funsuite.AnyFunSuite
-class ExhaustivePlannerCboSuite extends CboSuite {
- override protected def conf: CboConfig = CboConfig(plannerType = PlannerType.Exhaustive)
+class ExhaustivePlannerRasSuite extends RasSuite {
+ override protected def conf: RasConfig = RasConfig(plannerType = PlannerType.Exhaustive)
}
-class DpPlannerCboSuite extends CboSuite {
- override protected def conf: CboConfig = CboConfig(plannerType = PlannerType.Dp)
+class DpPlannerRasSuite extends RasSuite {
+ override protected def conf: RasConfig = RasConfig(plannerType = PlannerType.Dp)
}
-abstract class CboSuite extends AnyFunSuite {
- import CboSuite._
+abstract class RasSuite extends AnyFunSuite {
+ import RasSuite._
- protected def conf: CboConfig
+ protected def conf: RasConfig
test("Group memo - re-memorize") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
- val memo = Memo(cbo)
- val group1 = memo.memorize(cbo, Unary(50, Unary(50, Leaf(30))))
- val group2 = memo.memorize(cbo, Unary(50, Unary(50, Leaf(30))))
+ val memo = Memo(ras)
+ val group1 = memo.memorize(ras, Unary(50, Unary(50, Leaf(30))))
+ val group2 = memo.memorize(ras, Unary(50, Unary(50, Leaf(30))))
assert(group2 eq group1)
}
test("Group memo - define equivalence") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
- val memo = Memo(cbo)
- val group = memo.memorize(cbo, Unary(50, Unary(50, Leaf(30))))
+ val memo = Memo(ras)
+ val group = memo.memorize(ras, Unary(50, Unary(50, Leaf(30))))
val state = memo.newState()
assert(group.nodes(state).size == 1)
val can = group.nodes(state).head.asCanonical()
- memo.openFor(can).memorize(cbo, Unary(30, Leaf(90)))
+ memo.openFor(can).memorize(ras, Unary(30, Leaf(90)))
assert(memo.newState().allGroups().size == 4)
}
test("Group memo - define equivalence: binary with similar children, 1") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
- val memo = Memo(cbo)
- val group = memo.memorize(cbo, Binary(50, Leaf(30), Leaf(40)))
+ val memo = Memo(ras)
+ val group = memo.memorize(ras, Binary(50, Leaf(30), Leaf(40)))
val state = memo.newState()
assert(group.nodes(state).size == 1)
- val leaf40Group = memo.memorize(cbo, Leaf(40))
+ val leaf40Group = memo.memorize(ras, Leaf(40))
assert(leaf40Group.nodes(state).size == 1)
val can = leaf40Group.nodes(state).head.asCanonical()
- memo.openFor(can).memorize(cbo, Leaf(30))
+ memo.openFor(can).memorize(ras, Leaf(30))
assert(memo.newState().allGroups().size == 3)
}
test("Group memo - define equivalence: binary with similar children, 2") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
- val memo = Memo(cbo)
- val group = memo.memorize(cbo, Binary(50, Unary(20, Leaf(30)), Unary(20, Leaf(40))))
+ val memo = Memo(ras)
+ val group = memo.memorize(ras, Binary(50, Unary(20, Leaf(30)), Unary(20, Leaf(40))))
val state = memo.newState()
assert(group.nodes(state).size == 1)
- val leaf40Group = memo.memorize(cbo, Leaf(40))
+ val leaf40Group = memo.memorize(ras, Leaf(40))
assert(leaf40Group.nodes(state).size == 1)
val can = leaf40Group.nodes(state).head.asCanonical()
- memo.openFor(can).memorize(cbo, Leaf(30))
+ memo.openFor(can).memorize(ras, Leaf(30))
assert(memo.newState().allGroups().size == 5)
}
test("Group memo - partial canonical") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
- val memo = Memo(cbo)
- val group1 = memo.memorize(cbo, Unary(50, Unary(50, Leaf(30))))
- val group2 = memo.memorize(cbo, Unary(50, Group(1)))
+ val memo = Memo(ras)
+ val group1 = memo.memorize(ras, Unary(50, Unary(50, Leaf(30))))
+ val group2 = memo.memorize(ras, Unary(50, Group(1)))
assert(group2 eq group1)
}
test(s"Unary node") {
- object DivideUnaryCost extends CboRule[TestNode] {
+ object DivideUnaryCost extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case Unary(cost, child) =>
if (cost >= 35) {
@@ -145,7 +145,7 @@ abstract class CboSuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- object DecreaseUnaryCost extends CboRule[TestNode] {
+ object DecreaseUnaryCost extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case Unary(cost, child) =>
if (cost >= 80) {
@@ -159,24 +159,24 @@ abstract class CboSuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(DivideUnaryCost, DecreaseUnaryCost)))
+ RasRule.Factory.reuse(List(DivideUnaryCost, DecreaseUnaryCost)))
.withNewConfig(_ => conf)
val plan = Unary(90, Leaf(70))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(optimized == Unary(23, Unary(23, Leaf(70))))
}
test(s"Unary node insertion") {
- object InsertUnary2 extends CboRule[TestNode] {
+ object InsertUnary2 extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case Unary(cost1, Unary(cost2, child)) =>
List(Unary(cost1 - 11, Unary2(10, Unary(cost2, child))))
@@ -186,25 +186,25 @@ abstract class CboSuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(InsertUnary2)))
+ RasRule.Factory.reuse(List(InsertUnary2)))
.withNewConfig(_ => conf)
val plan = Unary(90, Unary(90, Leaf(70)))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(optimized == Unary(79, Unary2(10, Unary(90, Leaf(70)))))
}
test(s"Binary node") {
- object DivideBinaryCost extends CboRule[TestNode] {
+ object DivideBinaryCost extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case Binary(cost, left, right) =>
if (cost >= 35) {
@@ -219,25 +219,25 @@ abstract class CboSuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(DivideBinaryCost)))
+ RasRule.Factory.reuse(List(DivideBinaryCost)))
.withNewConfig(_ => conf)
val plan = Binary(90, Leaf(70), Leaf(70))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(optimized == Binary(90, Leaf(70), Leaf(70)))
}
test(s"Symmetric rule") {
- object SymmetricRule extends CboRule[TestNode] {
+ object SymmetricRule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case Unary(cost, child) => List(Unary2(cost, child))
case Unary2(cost, child) => List(Unary(cost, child))
@@ -247,18 +247,18 @@ abstract class CboSuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(SymmetricRule)))
+ RasRule.Factory.reuse(List(SymmetricRule)))
.withNewConfig(_ => conf)
val plan = Unary(90, Leaf(70))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
val state = planner.newState()
@@ -268,7 +268,7 @@ abstract class CboSuite extends AnyFunSuite {
}
test(s"Binary swap") {
- object BinarySwap extends CboRule[TestNode] {
+ object BinarySwap extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case Binary(cost, left, right) if cost >= 1 =>
List(Binary((cost - 1).max(0), right, left))
@@ -278,25 +278,25 @@ abstract class CboSuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(BinarySwap)))
+ RasRule.Factory.reuse(List(BinarySwap)))
.withNewConfig(_ => conf)
val plan = Binary(90, Leaf(50), Leaf(70))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(optimized == Binary(0, Leaf(50), Leaf(70)))
}
test(s"Binary swap equivalent leaves") {
- object BinarySwap extends CboRule[TestNode] {
+ object BinarySwap extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case Binary(cost, left, right) if cost >= 1 =>
List(Binary((cost - 1).max(0), right, left))
@@ -306,25 +306,25 @@ abstract class CboSuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(BinarySwap)))
+ RasRule.Factory.reuse(List(BinarySwap)))
.withNewConfig(_ => conf)
val plan = Binary(70, Binary(90, Leaf(50), Leaf(50)), Leaf(50))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(optimized == Binary(0, Binary(0, Leaf(50), Leaf(50)), Leaf(50)))
}
test(s"Avoid unused groups") {
- object Unary2Unary3 extends CboRule[TestNode] {
+ object Unary2Unary3 extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case Unary2(cost, child) if cost >= 1 => List(Unary3(cost - 1, child))
case Unary3(cost, child) if cost >= 1 => List(Unary2(cost + 1, child))
@@ -334,18 +334,18 @@ abstract class CboSuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(Unary2Unary3)))
+ RasRule.Factory.reuse(List(Unary2Unary3)))
.withNewConfig(_ => conf)
val plan = Unary(50, Unary2(50, Leaf(30)))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
val state = planner.newState()
@@ -356,18 +356,18 @@ abstract class CboSuite extends AnyFunSuite {
test(s"Rule application depth - depth 1") {
val l2l2 = new LeafToLeaf2()
val u2u2 = new UnaryToUnary2()
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(l2l2, u2u2)))
+ RasRule.Factory.reuse(List(l2l2, u2u2)))
.withNewConfig(_ => conf)
val plan = Unary(50, Unary2(50, Unary2(50, Unary2(50, Leaf(30)))))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(optimized == Unary2(49, Unary2(50, Unary2(50, Unary2(50, Leaf2(29))))))
@@ -377,7 +377,7 @@ abstract class CboSuite extends AnyFunSuite {
val l2l2 = new LeafToLeaf2()
val u2u2 = new UnaryToUnary2()
- object Unary2Unary2ToUnary3 extends CboRule[TestNode] {
+ object Unary2Unary2ToUnary3 extends RasRule[TestNode] {
var invocationCount: Int = 0
var effectiveInvocationCount: Int = 0
override def shift(node: TestNode): Iterable[TestNode] = {
@@ -393,18 +393,18 @@ abstract class CboSuite extends AnyFunSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(l2l2, u2u2, Unary2Unary2ToUnary3)))
+ RasRule.Factory.reuse(List(l2l2, u2u2, Unary2Unary2ToUnary3)))
.withNewConfig(_ => conf)
val plan = Unary(50, Unary2(50, Unary2(50, Unary2(50, Leaf(30)))))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val optimized = planner.plan()
assert(Unary2Unary2ToUnary3.invocationCount == 14)
@@ -413,7 +413,7 @@ abstract class CboSuite extends AnyFunSuite {
}
}
-object CboSuite {
+object RasSuite {
case class Binary(
override val selfCost: Long,
@@ -444,7 +444,7 @@ object CboSuite {
override def makeCopy(): LeafLike = copy()
}
- class LeafToLeaf2 extends CboRule[TestNode] {
+ class LeafToLeaf2 extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
@@ -457,7 +457,7 @@ object CboSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- class UnaryToUnary2 extends CboRule[TestNode] {
+ class UnaryToUnary2 extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case Unary(cost, child) =>
@@ -469,7 +469,7 @@ object CboSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- class Unary2ToUnary3 extends CboRule[TestNode] {
+ class Unary2ToUnary3 extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
node match {
case Unary2(cost, child) =>
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboSuiteBase.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/RasSuiteBase.scala
similarity index 88%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboSuiteBase.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/RasSuiteBase.scala
index 12276daa8..5432a6c78 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/CboSuiteBase.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/RasSuiteBase.scala
@@ -14,13 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo
+package org.apache.gluten.ras
-import org.apache.gluten.cbo.memo.{MemoLike, MemoState}
-import org.apache.gluten.cbo.path.{CboPath, PathFinder}
-import org.apache.gluten.cbo.property.PropertySet
+import org.apache.gluten.ras.memo.{MemoLike, MemoState}
+import org.apache.gluten.ras.path.{PathFinder, RasPath}
+import org.apache.gluten.ras.property.PropertySet
-object CboSuiteBase {
+object RasSuiteBase {
trait TestNode {
def selfCost(): Long
def children(): Seq[TestNode]
@@ -127,7 +127,7 @@ object CboSuiteBase {
}
}
- object ExplainImpl extends CboExplain[TestNode] {
+ object ExplainImpl extends RasExplain[TestNode] {
override def describeNode(node: TestNode): String = node match {
case n => n.toString
}
@@ -153,7 +153,7 @@ object CboSuiteBase {
: EnforcerRuleFactory[TestNode] = (_: Property[TestNode]) => List.empty
}
- implicit class GraphvizPrinter[T <: AnyRef](val planner: CboPlanner[T]) {
+ implicit class GraphvizPrinter[T <: AnyRef](val planner: RasPlanner[T]) {
def printGraphviz(): Unit = {
// scalastyle:off println
println(planner.newState().formatGraphviz())
@@ -162,8 +162,8 @@ object CboSuiteBase {
}
implicit class MemoLikeImplicits[T <: AnyRef](val memo: MemoLike[T]) {
- def memorize(cbo: Cbo[T], node: T): CboGroup[T] = {
- memo.memorize(node, cbo.propSetsOf(node))
+ def memorize(ras: Ras[T], node: T): RasGroup[T] = {
+ memo.memorize(node, ras.propSetsOf(node))
}
}
@@ -172,12 +172,12 @@ object CboSuiteBase {
state.allGroups().size
}
- def collectAllPaths(depth: Int): Iterable[CboPath[T]] = {
+ def collectAllPaths(depth: Int): Iterable[RasPath[T]] = {
val allClusters = state.allClusters()
val allGroups = state.allGroups()
val highestFinder = PathFinder
- .builder(state.cbo(), state)
+ .builder(state.ras(), state)
.depth(depth)
.build()
@@ -188,7 +188,7 @@ object CboSuiteBase {
val highest = highestFinder.find(node).maxBy(c => c.height())
val finder = (1 to highest.height())
.foldLeft(PathFinder
- .builder(state.cbo(), state)) {
+ .builder(state.ras(), state)) {
case (builder, d) =>
builder.depth(d)
}
@@ -199,14 +199,14 @@ object CboSuiteBase {
}
implicit class TestNodeImplicits(val node: TestNode) {
- def asCanonical(cbo: Cbo[TestNode]): CanonicalNode[TestNode] = {
- CanonicalNode(cbo, node)
+ def asCanonical(ras: Ras[TestNode]): CanonicalNode[TestNode] = {
+ CanonicalNode(ras, node)
}
}
- implicit class TestNodeGroupImplicits(val group: CboGroup[TestNode]) {
- def asGroup(cbo: Cbo[TestNode]): GroupNode[TestNode] = {
- GroupNode(cbo, group)
+ implicit class TestNodeGroupImplicits(val group: RasGroup[TestNode]) {
+ def asGroup(ras: Ras[TestNode]): GroupNode[TestNode] = {
+ GroupNode(ras, group)
}
}
}
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/mock/MockMemoState.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/mock/MockMemoState.scala
similarity index 65%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/mock/MockMemoState.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/mock/MockMemoState.scala
index ef902c1bb..e4c8cb30b 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/mock/MockMemoState.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/mock/MockMemoState.scala
@@ -14,48 +14,48 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.mock
+package org.apache.gluten.ras.mock
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.memo.{MemoState, MemoStore}
-import org.apache.gluten.cbo.property.PropertySet
-import org.apache.gluten.cbo.vis.GraphvizVisualizer
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.memo.{MemoState, MemoStore}
+import org.apache.gluten.ras.property.PropertySet
+import org.apache.gluten.ras.vis.GraphvizVisualizer
import scala.collection.mutable
case class MockMemoState[T <: AnyRef] private (
- override val cbo: Cbo[T],
- override val clusterLookup: Map[CboClusterKey, CboCluster[T]],
- override val allGroups: Seq[CboGroup[T]])
+ override val ras: Ras[T],
+ override val clusterLookup: Map[RasClusterKey, RasCluster[T]],
+ override val allGroups: Seq[RasGroup[T]])
extends MemoState[T] {
- def printGraphviz(group: CboGroup[T]): Unit = {
- val graph = GraphvizVisualizer(cbo, this, group.id())
+ def printGraphviz(group: RasGroup[T]): Unit = {
+ val graph = GraphvizVisualizer(ras, this, group.id())
// scalastyle:off println
println(graph.format())
// scalastyle:on println
}
def printGraphviz(best: Best[T]): Unit = {
- val graph = vis.GraphvizVisualizer(cbo, this, best)
+ val graph = vis.GraphvizVisualizer(ras, this, best)
// scalastyle:off println
println(graph.format())
// scalastyle:on println
}
- override def allClusters(): Iterable[CboCluster[T]] = clusterLookup.values
+ override def allClusters(): Iterable[RasCluster[T]] = clusterLookup.values
- override def getCluster(key: CboClusterKey): CboCluster[T] = clusterLookup(key)
+ override def getCluster(key: RasClusterKey): RasCluster[T] = clusterLookup(key)
- override def getGroup(id: Int): CboGroup[T] = allGroups(id)
+ override def getGroup(id: Int): RasGroup[T] = allGroups(id)
}
object MockMemoState {
- class Builder[T <: AnyRef] private (cbo: Cbo[T]) {
+ class Builder[T <: AnyRef] private (ras: Ras[T]) {
private var propSet: PropertySet[T] = PropertySet[T](List.empty)
- private val clusterBuffer = mutable.Map[CboClusterKey, MockMutableCluster[T]]()
+ private val clusterBuffer = mutable.Map[RasClusterKey, MockMutableCluster[T]]()
private val groupFactory: MockMutableGroup.Factory[T] =
- MockMutableGroup.Factory.create[T](cbo, propSet)
+ MockMutableGroup.Factory.create[T](ras, propSet)
def withPropertySet(propSet: PropertySet[T]): Builder[T] = {
this.propSet = propSet
@@ -65,28 +65,28 @@ object MockMemoState {
def newCluster(): MockMutableCluster[T] = {
val id = clusterBuffer.size
val key = MockMutableCluster.DummyIntClusterKey(id)
- val cluster = MockMutableCluster[T](cbo, key, groupFactory)
+ val cluster = MockMutableCluster[T](ras, key, groupFactory)
clusterBuffer += (key -> cluster)
cluster
}
def build(): MockMemoState[T] = {
- MockMemoState[T](cbo, clusterBuffer.toMap, groupFactory.allGroups())
+ MockMemoState[T](ras, clusterBuffer.toMap, groupFactory.allGroups())
}
}
object Builder {
- def apply[T <: AnyRef](cbo: Cbo[T]): Builder[T] = {
- new Builder[T](cbo)
+ def apply[T <: AnyRef](ras: Ras[T]): Builder[T] = {
+ new Builder[T](ras)
}
}
// TODO add groups with different property sets
class MockMutableCluster[T <: AnyRef] private (
- cbo: Cbo[T],
- key: CboClusterKey,
+ ras: Ras[T],
+ key: RasClusterKey,
groupFactory: MockMutableGroup.Factory[T])
- extends CboCluster[T] {
+ extends RasCluster[T] {
private val nodeBuffer = mutable.ArrayBuffer[CanonicalNode[T]]()
def newGroup(): MockMutableGroup[T] = {
@@ -102,23 +102,23 @@ object MockMemoState {
object MockMutableCluster {
def apply[T <: AnyRef](
- cbo: Cbo[T],
- key: CboClusterKey,
+ ras: Ras[T],
+ key: RasClusterKey,
groupFactory: MockMutableGroup.Factory[T]): MockMutableCluster[T] = {
- new MockMutableCluster[T](cbo, key, groupFactory)
+ new MockMutableCluster[T](ras, key, groupFactory)
}
- case class DummyIntClusterKey(id: Int) extends CboClusterKey {
+ case class DummyIntClusterKey(id: Int) extends RasClusterKey {
override def metadata: Metadata = MetadataModelImpl.DummyMetadata
}
}
class MockMutableGroup[T <: AnyRef] private (
override val id: Int,
- override val clusterKey: CboClusterKey,
+ override val clusterKey: RasClusterKey,
override val propSet: PropertySet[T],
override val self: T)
- extends CboGroup[T] {
+ extends RasGroup[T] {
private val nodes: mutable.ArrayBuffer[CanonicalNode[T]] = mutable.ArrayBuffer()
def add(node: CanonicalNode[T]): Unit = {
@@ -133,17 +133,17 @@ object MockMemoState {
}
object MockMutableGroup {
- class Factory[T <: AnyRef] private (cbo: Cbo[T], propSet: PropertySet[T]) {
+ class Factory[T <: AnyRef] private (ras: Ras[T], propSet: PropertySet[T]) {
private val groupBuffer = mutable.ArrayBuffer[MockMutableGroup[T]]()
- def newGroup(clusterKey: CboClusterKey): MockMutableGroup[T] = {
+ def newGroup(clusterKey: RasClusterKey): MockMutableGroup[T] = {
val id = groupBuffer.size
val group =
new MockMutableGroup[T](
id,
clusterKey,
propSet,
- cbo.planModel.newGroupLeaf(id, clusterKey.metadata, propSet))
+ ras.planModel.newGroupLeaf(id, clusterKey.metadata, propSet))
groupBuffer += group
group
}
@@ -152,8 +152,8 @@ object MockMemoState {
}
object Factory {
- def create[T <: AnyRef](cbo: Cbo[T], propSet: PropertySet[T]): Factory[T] = {
- new Factory[T](cbo, propSet)
+ def create[T <: AnyRef](ras: Ras[T], propSet: PropertySet[T]): Factory[T] = {
+ new Factory[T](ras, propSet)
}
}
}
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/mock/MockCboPath.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/mock/MockRasPath.scala
similarity index 67%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/mock/MockCboPath.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/mock/MockRasPath.scala
index 1c3026658..eac3d5f70 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/mock/MockCboPath.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/mock/MockRasPath.scala
@@ -14,31 +14,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.mock
+package org.apache.gluten.ras.mock
-import org.apache.gluten.cbo.{CanonicalNode, Cbo}
-import org.apache.gluten.cbo.memo.Memo
-import org.apache.gluten.cbo.path.{CboPath, PathKeySet}
+import org.apache.gluten.ras.{CanonicalNode, Ras}
+import org.apache.gluten.ras.memo.Memo
+import org.apache.gluten.ras.path.{PathKeySet, RasPath}
-object MockCboPath {
- def mock[T <: AnyRef](cbo: Cbo[T], node: T): CboPath[T] = {
- mock(cbo, node, PathKeySet.trivial)
+object MockRasPath {
+ def mock[T <: AnyRef](ras: Ras[T], node: T): RasPath[T] = {
+ mock(ras, node, PathKeySet.trivial)
}
- def mock[T <: AnyRef](cbo: Cbo[T], node: T, keys: PathKeySet): CboPath[T] = {
- val memo = Memo(cbo)
- val g = memo.memorize(node, cbo.propSetsOf(node))
+ def mock[T <: AnyRef](ras: Ras[T], node: T, keys: PathKeySet): RasPath[T] = {
+ val memo = Memo(ras)
+ val g = memo.memorize(node, ras.propSetsOf(node))
val state = memo.newState()
val groupSupplier = state.asGroupSupplier()
assert(g.nodes(state).size == 1)
val can = g.nodes(state).head
- def dfs(n: CanonicalNode[T]): CboPath[T] = {
+ def dfs(n: CanonicalNode[T]): RasPath[T] = {
if (n.isLeaf()) {
- return CboPath.one(cbo, keys, groupSupplier, n)
+ return RasPath.one(ras, keys, groupSupplier, n)
}
- CboPath(
- cbo,
+ RasPath(
+ ras,
n,
n.getChildrenGroups(groupSupplier).map(_.group(groupSupplier)).map {
cg =>
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/path/PathFinderSuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/path/PathFinderSuite.scala
similarity index 77%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/path/PathFinderSuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/path/PathFinderSuite.scala
index 4684cc24a..0c8880c29 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/path/PathFinderSuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/path/PathFinderSuite.scala
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.path
+package org.apache.gluten.ras.path
-import org.apache.gluten.cbo.{CanonicalNode, Cbo}
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.mock.MockMemoState
-import org.apache.gluten.cbo.rule.CboRule
+import org.apache.gluten.ras.{CanonicalNode, Ras}
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.mock.MockMemoState
+import org.apache.gluten.ras.rule.RasRule
import org.scalatest.funsuite.AnyFunSuite
@@ -27,16 +27,16 @@ class PathFinderSuite extends AnyFunSuite {
import PathFinderSuite._
test("Base") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val mock = MockMemoState.Builder(cbo)
+ val mock = MockMemoState.Builder(ras)
val cluster = mock.newCluster()
val groupA = cluster.newGroup()
val groupB = cluster.newGroup()
@@ -49,12 +49,12 @@ class PathFinderSuite extends AnyFunSuite {
val n4 = "n4"
val n5 = "n5"
val n6 = "n6"
- val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(cbo)
- val node2 = Unary(n2, groupD.self).asCanonical(cbo)
- val node3 = Unary(n3, groupE.self).asCanonical(cbo)
- val node4 = Leaf(n4, 1).asCanonical(cbo)
- val node5 = Leaf(n5, 1).asCanonical(cbo)
- val node6 = Leaf(n6, 1).asCanonical(cbo)
+ val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(ras)
+ val node2 = Unary(n2, groupD.self).asCanonical(ras)
+ val node3 = Unary(n3, groupE.self).asCanonical(ras)
+ val node4 = Leaf(n4, 1).asCanonical(ras)
+ val node5 = Leaf(n5, 1).asCanonical(ras)
+ val node6 = Leaf(n6, 1).asCanonical(ras)
groupA.add(node1)
groupB.add(node2)
@@ -64,14 +64,14 @@ class PathFinderSuite extends AnyFunSuite {
val state = mock.build()
- def find(can: CanonicalNode[TestNode], depth: Int): Iterable[CboPath[TestNode]] = {
- val finder = PathFinder.builder(cbo, state).depth(depth).build()
+ def find(can: CanonicalNode[TestNode], depth: Int): Iterable[RasPath[TestNode]] = {
+ val finder = PathFinder.builder(ras, state).depth(depth).build()
finder.find(can)
}
val height1 = find(node1, 1).map(_.plan()).toSeq
val height2 = find(node1, 2).map(_.plan()).toSeq
- val heightInf = find(node1, CboPath.INF_DEPTH).map(_.plan()).toSeq
+ val heightInf = find(node1, RasPath.INF_DEPTH).map(_.plan()).toSeq
assert(height1 == List(Binary(n1, Group(1), Group(2))))
assert(height2 == List(Binary(n1, Unary(n2, Group(3)), Unary(n3, Group(4)))))
@@ -82,16 +82,16 @@ class PathFinderSuite extends AnyFunSuite {
}
test("Find - multiple depths") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val mock = MockMemoState.Builder(cbo)
+ val mock = MockMemoState.Builder(ras)
val cluster = mock.newCluster()
val groupA = cluster.newGroup()
val groupB = cluster.newGroup()
@@ -105,12 +105,12 @@ class PathFinderSuite extends AnyFunSuite {
val n4 = "n4"
val n5 = "n5"
val n6 = "n6"
- val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(cbo)
- val node2 = Unary(n2, groupD.self).asCanonical(cbo)
- val node3 = Unary(n3, groupE.self).asCanonical(cbo)
- val node4 = Leaf(n4, 1).asCanonical(cbo)
- val node5 = Leaf(n5, 1).asCanonical(cbo)
- val node6 = Leaf(n6, 1).asCanonical(cbo)
+ val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(ras)
+ val node2 = Unary(n2, groupD.self).asCanonical(ras)
+ val node3 = Unary(n3, groupE.self).asCanonical(ras)
+ val node4 = Leaf(n4, 1).asCanonical(ras)
+ val node5 = Leaf(n5, 1).asCanonical(ras)
+ val node6 = Leaf(n6, 1).asCanonical(ras)
groupA.add(node1)
groupB.add(node2)
@@ -121,7 +121,7 @@ class PathFinderSuite extends AnyFunSuite {
val state = mock.build()
val finder1 = PathFinder
- .builder(cbo, state)
+ .builder(ras, state)
.depth(1)
.depth(3)
.build()
@@ -133,9 +133,9 @@ class PathFinderSuite extends AnyFunSuite {
Binary(n1, Unary(n2, Leaf(n4, 1)), Unary(n3, Leaf(n6, 1)))))
val finder2 = PathFinder
- .builder(cbo, state)
+ .builder(ras, state)
.depth(2)
- .depth(CboPath.INF_DEPTH)
+ .depth(RasPath.INF_DEPTH)
.build()
assert(
@@ -146,11 +146,11 @@ class PathFinderSuite extends AnyFunSuite {
))
val finder3 = PathFinder
- .builder(cbo, state)
+ .builder(ras, state)
.depth(2)
.depth(2)
- .depth(CboPath.INF_DEPTH)
- .depth(CboPath.INF_DEPTH)
+ .depth(RasPath.INF_DEPTH)
+ .depth(RasPath.INF_DEPTH)
.build()
assert(
@@ -162,16 +162,16 @@ class PathFinderSuite extends AnyFunSuite {
}
test("Dive - basic") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val mock = MockMemoState.Builder(cbo)
+ val mock = MockMemoState.Builder(ras)
val cluster = mock.newCluster()
val groupA = cluster.newGroup()
val groupB = cluster.newGroup()
@@ -185,12 +185,12 @@ class PathFinderSuite extends AnyFunSuite {
val n4 = "n4"
val n5 = "n5"
val n6 = "n6"
- val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(cbo)
- val node2 = Unary(n2, groupD.self).asCanonical(cbo)
- val node3 = Unary(n3, groupE.self).asCanonical(cbo)
- val node4 = Leaf(n4, 1).asCanonical(cbo)
- val node5 = Leaf(n5, 1).asCanonical(cbo)
- val node6 = Leaf(n6, 1).asCanonical(cbo)
+ val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(ras)
+ val node2 = Unary(n2, groupD.self).asCanonical(ras)
+ val node3 = Unary(n3, groupE.self).asCanonical(ras)
+ val node4 = Leaf(n4, 1).asCanonical(ras)
+ val node5 = Leaf(n5, 1).asCanonical(ras)
+ val node6 = Leaf(n6, 1).asCanonical(ras)
groupA.add(node1)
groupB.add(node2)
@@ -200,7 +200,7 @@ class PathFinderSuite extends AnyFunSuite {
val state = mock.build()
- val path = CboPath.one(cbo, PathKeySet.trivial, state.allGroups, node1)
+ val path = RasPath.one(ras, PathKeySet.trivial, state.allGroups, node1)
assert(path.plan() == Binary(n1, Group(1), Group(2)))
assert(
@@ -215,22 +215,22 @@ class PathFinderSuite extends AnyFunSuite {
Binary(n1, Unary(n2, Leaf(n4, 1)), Unary(n3, Leaf(n5, 1))),
Binary(n1, Unary(n2, Leaf(n4, 1)), Unary(n3, Leaf(n6, 1)))))
assert(
- path.dive(state, CboPath.INF_DEPTH).map(_.plan()) == List(
+ path.dive(state, RasPath.INF_DEPTH).map(_.plan()) == List(
Binary(n1, Unary(n2, Leaf(n4, 1)), Unary(n3, Leaf(n5, 1))),
Binary(n1, Unary(n2, Leaf(n4, 1)), Unary(n3, Leaf(n6, 1)))))
}
test("Find/Dive - binary with different children heights") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val mock = MockMemoState.Builder(cbo)
+ val mock = MockMemoState.Builder(ras)
val cluster = mock.newCluster()
val groupA = cluster.newGroup()
val groupB = cluster.newGroup()
@@ -243,11 +243,11 @@ class PathFinderSuite extends AnyFunSuite {
val n3 = "n3"
val n4 = "n4"
val n5 = "n5"
- val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(cbo)
- val node2 = Binary(n2, groupD.self, groupE.self).asCanonical(cbo)
- val node3 = Leaf(n3, 1).asCanonical(cbo)
- val node4 = Leaf(n4, 1).asCanonical(cbo)
- val node5 = Leaf(n5, 1).asCanonical(cbo)
+ val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(ras)
+ val node2 = Binary(n2, groupD.self, groupE.self).asCanonical(ras)
+ val node3 = Leaf(n3, 1).asCanonical(ras)
+ val node4 = Leaf(n4, 1).asCanonical(ras)
+ val node5 = Leaf(n5, 1).asCanonical(ras)
groupA.add(node1)
groupB.add(node2)
@@ -257,15 +257,15 @@ class PathFinderSuite extends AnyFunSuite {
val state = mock.build()
- def find(can: CanonicalNode[TestNode], depth: Int): Iterable[CboPath[TestNode]] = {
- PathFinder.builder(cbo, state).depth(depth).build().find(can)
+ def find(can: CanonicalNode[TestNode], depth: Int): Iterable[RasPath[TestNode]] = {
+ PathFinder.builder(ras, state).depth(depth).build().find(can)
}
val height1 = find(node1, 1).map(_.plan()).toSeq
val height2 = find(node1, 2).map(_.plan()).toSeq
val height3 = find(node1, 3).map(_.plan()).toSeq
val height4 = find(node1, 4).map(_.plan()).toSeq
- val heightInf = find(node1, CboPath.INF_DEPTH).map(_.plan()).toSeq
+ val heightInf = find(node1, RasPath.INF_DEPTH).map(_.plan()).toSeq
assert(height1 == List(Binary(n1, Group(1), Group(2))))
assert(height2 == List(Binary(n1, Binary(n2, Group(3), Group(4)), Leaf(n3, 1))))
@@ -273,7 +273,7 @@ class PathFinderSuite extends AnyFunSuite {
assert(height4 == List(Binary(n1, Binary(n2, Leaf(n4, 1), Leaf(n5, 1)), Leaf(n3, 1))))
assert(heightInf == List(Binary(n1, Binary(n2, Leaf(n4, 1), Leaf(n5, 1)), Leaf(n3, 1))))
- val path = CboPath.one(cbo, PathKeySet.trivial, state.allGroups, node1)
+ val path = RasPath.one(ras, PathKeySet.trivial, state.allGroups, node1)
assert(path.plan() == Binary(n1, Group(1), Group(2)))
assert(
@@ -286,7 +286,7 @@ class PathFinderSuite extends AnyFunSuite {
path.dive(state, 3).map(_.plan()) == List(
Binary(n1, Binary(n2, Leaf(n4, 1), Leaf(n5, 1)), Leaf(n3, 1))))
assert(
- path.dive(state, CboPath.INF_DEPTH).map(_.plan()) == List(
+ path.dive(state, RasPath.INF_DEPTH).map(_.plan()) == List(
Binary(n1, Binary(n2, Leaf(n4, 1), Leaf(n5, 1)), Leaf(n3, 1))))
}
}
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/path/PathMaskSuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/path/PathMaskSuite.scala
similarity index 95%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/path/PathMaskSuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/path/PathMaskSuite.scala
index 647b8e3d2..125f9f33c 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/path/PathMaskSuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/path/PathMaskSuite.scala
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.path
+package org.apache.gluten.ras.path
import org.scalatest.funsuite.AnyFunSuite
@@ -26,7 +26,7 @@ class PathMaskSuite extends AnyFunSuite {
assert(in.fold(1) == PathMask(List(3, -1, -1, -1)))
assert(in.fold(2) == PathMask(List(3, -1, 2, -1, -1, 0)))
assert(in.fold(3) == PathMask(List(3, -1, 2, 0, 0, 0)))
- assert(in.fold(CboPath.INF_DEPTH) == PathMask(List(3, -1, 2, 0, 0, 0)))
+ assert(in.fold(RasPath.INF_DEPTH) == PathMask(List(3, -1, 2, 0, 0, 0)))
}
test("Mask operation - fold 2") {
@@ -35,7 +35,7 @@ class PathMaskSuite extends AnyFunSuite {
assert(in.fold(1) == PathMask(List(3, -1, -1, -1)))
assert(in.fold(2) == PathMask(List(3, 2, -1, -1, 0, 1, -1)))
assert(in.fold(3) == PathMask(List(3, 2, 0, -1, 0, 1, 0)))
- assert(in.fold(CboPath.INF_DEPTH) == PathMask(List(3, 2, 0, -1, 0, 1, 0)))
+ assert(in.fold(RasPath.INF_DEPTH) == PathMask(List(3, 2, 0, -1, 0, 1, 0)))
}
test("Mask operation - sub-mask") {
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/path/CboPathSuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/path/RasPathSuite.scala
similarity index 77%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/path/CboPathSuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/path/RasPathSuite.scala
index 501b2b2fa..e092ea4f2 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/path/CboPathSuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/path/RasPathSuite.scala
@@ -14,39 +14,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.path
+package org.apache.gluten.ras.path
-import org.apache.gluten.cbo.Cbo
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.mock.MockCboPath
-import org.apache.gluten.cbo.rule.CboRule
+import org.apache.gluten.ras.Ras
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.mock.MockRasPath
+import org.apache.gluten.ras.rule.RasRule
import org.scalatest.funsuite.AnyFunSuite
-class CboPathSuite extends AnyFunSuite {
- import CboPathSuite._
+class RasPathSuite extends AnyFunSuite {
+ import RasPathSuite._
test("Path aggregate - empty") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List.empty))
- assert(CboPath.aggregate(cbo, List.empty) == List.empty)
+ RasRule.Factory.reuse(List.empty))
+ assert(RasPath.aggregate(ras, List.empty) == List.empty)
}
test("Path aggregate") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List.empty))
+ RasRule.Factory.reuse(List.empty))
val n1 = "n1"
val n2 = "n2"
@@ -54,33 +54,33 @@ class CboPathSuite extends AnyFunSuite {
val n4 = "n4"
val n5 = "n5"
val n6 = "n6"
- val path1 = MockCboPath.mock(
- cbo,
+ val path1 = MockRasPath.mock(
+ ras,
Unary(n5, Leaf(n6, 1)),
PathKeySet(Set(DummyPathKey(1), DummyPathKey(3)))
)
- val path2 = MockCboPath.mock(
- cbo,
+ val path2 = MockRasPath.mock(
+ ras,
Unary(n1, Unary(n2, Leaf(n3, 1))),
PathKeySet(Set(DummyPathKey(1)))
)
- val path3 = MockCboPath.mock(
- cbo,
+ val path3 = MockRasPath.mock(
+ ras,
Unary(n1, Unary(n2, Leaf(n3, 1))),
PathKeySet(Set(DummyPathKey(1), DummyPathKey(2)))
)
- val path4 = MockCboPath.mock(
- cbo,
+ val path4 = MockRasPath.mock(
+ ras,
Unary(n1, Unary(n2, Leaf(n3, 1))),
PathKeySet(Set(DummyPathKey(4)))
)
- val path5 = MockCboPath.mock(
- cbo,
+ val path5 = MockRasPath.mock(
+ ras,
Unary(n5, Leaf(n6, 1)),
PathKeySet(Set(DummyPathKey(4)))
)
- val out = CboPath
- .aggregate(cbo, List(path1, path2, path3, path4, path5))
+ val out = RasPath
+ .aggregate(ras, List(path1, path2, path3, path4, path5))
.toSeq
.sortBy(_.height())
assert(out.size == 2)
@@ -94,7 +94,7 @@ class CboPathSuite extends AnyFunSuite {
}
}
-object CboPathSuite {
+object RasPathSuite {
case class Leaf(name: String, override val selfCost: Long) extends LeafLike {
override def makeCopy(): LeafLike = this
}
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/path/WizardSuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/path/WizardSuite.scala
similarity index 82%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/path/WizardSuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/path/WizardSuite.scala
index bab612efb..c7505ef74 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/path/WizardSuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/path/WizardSuite.scala
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.path
+package org.apache.gluten.ras.path
-import org.apache.gluten.cbo.Cbo
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.mock.MockMemoState
-import org.apache.gluten.cbo.rule.CboRule
+import org.apache.gluten.ras.Ras
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.mock.MockMemoState
+import org.apache.gluten.ras.rule.RasRule
import org.scalatest.funsuite.AnyFunSuite
@@ -27,41 +27,41 @@ class WizardSuite extends AnyFunSuite {
import WizardSuite._
test("None") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val mock = MockMemoState.Builder(cbo)
+ val mock = MockMemoState.Builder(ras)
val cluster = mock.newCluster()
val groupA = cluster.newGroup()
val n1 = "n1"
- val node1 = Leaf(n1, 1).asCanonical(cbo)
+ val node1 = Leaf(n1, 1).asCanonical(ras)
groupA.add(node1)
val state = mock.build()
- val finder = PathFinder.builder(cbo, state).output(OutputWizards.none()).build()
+ val finder = PathFinder.builder(ras, state).output(OutputWizards.none()).build()
assert(finder.find(node1).map(_.plan()).toSeq == List.empty)
}
test("Prune by maximum depth") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val mock = MockMemoState.Builder(cbo)
+ val mock = MockMemoState.Builder(ras)
val cluster = mock.newCluster()
val groupA = cluster.newGroup()
val groupB = cluster.newGroup()
@@ -75,12 +75,12 @@ class WizardSuite extends AnyFunSuite {
val n4 = "n4"
val n5 = "n5"
val n6 = "n6"
- val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(cbo)
- val node2 = Unary(n2, groupD.self).asCanonical(cbo)
- val node3 = Unary(n3, groupE.self).asCanonical(cbo)
- val node4 = Leaf(n4, 1).asCanonical(cbo)
- val node5 = Leaf(n5, 1).asCanonical(cbo)
- val node6 = Leaf(n6, 1).asCanonical(cbo)
+ val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(ras)
+ val node2 = Unary(n2, groupD.self).asCanonical(ras)
+ val node3 = Unary(n3, groupE.self).asCanonical(ras)
+ val node4 = Leaf(n4, 1).asCanonical(ras)
+ val node5 = Leaf(n5, 1).asCanonical(ras)
+ val node6 = Leaf(n6, 1).asCanonical(ras)
groupA.add(node1)
groupB.add(node2)
@@ -91,7 +91,7 @@ class WizardSuite extends AnyFunSuite {
val state = mock.build()
def findWithMaxDepths(maxDepths: Seq[Int]): Seq[TestNode] = {
- val builder = PathFinder.builder(cbo, state)
+ val builder = PathFinder.builder(ras, state)
val finder = maxDepths
.foldLeft(builder) {
case (builder, d) =>
@@ -112,7 +112,7 @@ class WizardSuite extends AnyFunSuite {
Binary(n1, Unary(n2, Leaf(n4, 1)), Unary(n3, Leaf(n5, 1))),
Binary(n1, Unary(n2, Leaf(n4, 1)), Unary(n3, Leaf(n6, 1)))))
assert(
- findWithMaxDepths(List(CboPath.INF_DEPTH)) == List(
+ findWithMaxDepths(List(RasPath.INF_DEPTH)) == List(
Binary(n1, Unary(n2, Leaf(n4, 1)), Unary(n3, Leaf(n5, 1))),
Binary(n1, Unary(n2, Leaf(n4, 1)), Unary(n3, Leaf(n6, 1)))))
@@ -121,7 +121,7 @@ class WizardSuite extends AnyFunSuite {
Binary(n1, Group(1), Group(2)),
Binary(n1, Unary(n2, Group(3)), Unary(n3, Group(4)))))
assert(
- findWithMaxDepths(List(2, CboPath.INF_DEPTH)) == List(
+ findWithMaxDepths(List(2, RasPath.INF_DEPTH)) == List(
Binary(n1, Unary(n2, Group(3)), Unary(n3, Group(4))),
Binary(n1, Unary(n2, Leaf(n4, 1)), Unary(n3, Leaf(n5, 1))),
Binary(n1, Unary(n2, Leaf(n4, 1)), Unary(n3, Leaf(n6, 1)))
@@ -129,16 +129,16 @@ class WizardSuite extends AnyFunSuite {
}
test("Prune by pattern") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val mock = MockMemoState.Builder(cbo)
+ val mock = MockMemoState.Builder(ras)
val cluster = mock.newCluster()
val groupA = cluster.newGroup()
val groupB = cluster.newGroup()
@@ -152,12 +152,12 @@ class WizardSuite extends AnyFunSuite {
val n4 = "n4"
val n5 = "n5"
val n6 = "n6"
- val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(cbo)
- val node2 = Unary(n2, groupD.self).asCanonical(cbo)
- val node3 = Unary(n3, groupE.self).asCanonical(cbo)
- val node4 = Leaf(n4, 1).asCanonical(cbo)
- val node5 = Leaf(n5, 1).asCanonical(cbo)
- val node6 = Leaf(n6, 1).asCanonical(cbo)
+ val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(ras)
+ val node2 = Unary(n2, groupD.self).asCanonical(ras)
+ val node3 = Unary(n3, groupE.self).asCanonical(ras)
+ val node4 = Leaf(n4, 1).asCanonical(ras)
+ val node5 = Leaf(n5, 1).asCanonical(ras)
+ val node6 = Leaf(n6, 1).asCanonical(ras)
groupA.add(node1)
groupB.add(node2)
@@ -168,7 +168,7 @@ class WizardSuite extends AnyFunSuite {
val state = mock.build()
def findWithPatterns(patterns: Seq[Pattern[TestNode]]): Seq[TestNode] = {
- val builder = PathFinder.builder(cbo, state)
+ val builder = PathFinder.builder(ras, state)
val finder = patterns
.foldLeft(builder) {
case (builder, pattern) =>
@@ -220,16 +220,16 @@ class WizardSuite extends AnyFunSuite {
}
test("Prune by mask") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val mock = MockMemoState.Builder(cbo)
+ val mock = MockMemoState.Builder(ras)
val cluster = mock.newCluster()
val groupA = cluster.newGroup()
val groupB = cluster.newGroup()
@@ -243,12 +243,12 @@ class WizardSuite extends AnyFunSuite {
val n4 = "n4"
val n5 = "n5"
val n6 = "n6"
- val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(cbo)
- val node2 = Unary(n2, groupD.self).asCanonical(cbo)
- val node3 = Unary(n3, groupE.self).asCanonical(cbo)
- val node4 = Leaf(n4, 1).asCanonical(cbo)
- val node5 = Leaf(n5, 1).asCanonical(cbo)
- val node6 = Leaf(n6, 1).asCanonical(cbo)
+ val node1 = Binary(n1, groupB.self, groupC.self).asCanonical(ras)
+ val node2 = Unary(n2, groupD.self).asCanonical(ras)
+ val node3 = Unary(n3, groupE.self).asCanonical(ras)
+ val node4 = Leaf(n4, 1).asCanonical(ras)
+ val node5 = Leaf(n5, 1).asCanonical(ras)
+ val node6 = Leaf(n6, 1).asCanonical(ras)
groupA.add(node1)
groupB.add(node2)
@@ -260,7 +260,7 @@ class WizardSuite extends AnyFunSuite {
def findWithMask(mask: Seq[Int]): Seq[TestNode] = {
PathFinder
- .builder(cbo, state)
+ .builder(ras, state)
.output(OutputWizards.withMask(PathMask(mask)))
.build()
.find(node1)
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/rule/PatternSuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/rule/PatternSuite.scala
similarity index 85%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/rule/PatternSuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/rule/PatternSuite.scala
index ca4359219..263b1869a 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/rule/PatternSuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/rule/PatternSuite.scala
@@ -14,62 +14,62 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.rule
+package org.apache.gluten.ras.rule
-import org.apache.gluten.cbo.Cbo
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.mock.MockCboPath
-import org.apache.gluten.cbo.path.{CboPath, Pattern}
+import org.apache.gluten.ras.Ras
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.mock.MockRasPath
+import org.apache.gluten.ras.path.{Pattern, RasPath}
import org.scalatest.funsuite.AnyFunSuite
class PatternSuite extends AnyFunSuite {
import PatternSuite._
test("Match any") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
val pattern = Pattern.ignore[TestNode].build()
- val path = MockCboPath.mock(cbo, Leaf("n1", 1))
+ val path = MockRasPath.mock(ras, Leaf("n1", 1))
assert(path.height() == 1)
assert(pattern.matches(path, 1))
}
test("Match ignore") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
val pattern = Pattern.ignore[TestNode].build()
- val path = MockCboPath.mock(cbo, Leaf("n1", 1))
+ val path = MockRasPath.mock(ras, Leaf("n1", 1))
assert(path.height() == 1)
assert(pattern.matches(path, 1))
}
test("Match unary") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val path = MockCboPath.mock(cbo, Unary("n1", Leaf("n2", 1)))
+ val path = MockRasPath.mock(ras, Unary("n1", Leaf("n2", 1)))
assert(path.height() == 2)
val pattern1 = Pattern.node[TestNode](n => n.isInstanceOf[Unary], Pattern.ignore).build()
@@ -83,17 +83,17 @@ class PatternSuite extends AnyFunSuite {
}
test("Match binary") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val path = MockCboPath.mock(
- cbo,
+ val path = MockRasPath.mock(
+ ras,
Binary("n7", Unary("n1", Unary("n2", Leaf("n3", 1))), Unary("n5", Leaf("n6", 1))))
assert(path.height() == 4)
@@ -116,17 +116,17 @@ class PatternSuite extends AnyFunSuite {
}
test("Matches above a certain depth") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val path = MockCboPath.mock(
- cbo,
+ val path = MockRasPath.mock(
+ ras,
Binary("n7", Unary("n1", Unary("n2", Leaf("n3", 1))), Unary("n5", Leaf("n6", 1))))
assert(path.height() == 4)
@@ -199,7 +199,7 @@ object PatternSuite {
}
implicit class PatternImplicits[T <: AnyRef](pattern: Pattern[T]) {
- def matchesAll(paths: Seq[CboPath[T]], depth: Int): Boolean = {
+ def matchesAll(paths: Seq[RasPath[T]], depth: Int): Boolean = {
paths.forall(pattern.matches(_, depth))
}
}
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/specific/CyclicSearchSpaceSuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/specific/CyclicSearchSpaceSuite.scala
similarity index 71%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/specific/CyclicSearchSpaceSuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/specific/CyclicSearchSpaceSuite.scala
index 57169e9aa..d27292fb5 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/specific/CyclicSearchSpaceSuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/specific/CyclicSearchSpaceSuite.scala
@@ -14,46 +14,46 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.specific
+package org.apache.gluten.ras.specific
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.best.BestFinder
-import org.apache.gluten.cbo.memo.MemoState
-import org.apache.gluten.cbo.mock.MockMemoState
-import org.apache.gluten.cbo.path.{CboPath, PathFinder}
-import org.apache.gluten.cbo.rule.CboRule
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.best.BestFinder
+import org.apache.gluten.ras.memo.MemoState
+import org.apache.gluten.ras.mock.MockMemoState
+import org.apache.gluten.ras.path.{PathFinder, RasPath}
+import org.apache.gluten.ras.rule.RasRule
import org.scalatest.funsuite.AnyFunSuite
class GroupBastBestFinderCyclicSearchSpaceSuite extends CyclicSearchSpaceSuite {
override protected def newBestFinder[T <: AnyRef](
- cbo: Cbo[T],
- memoState: MemoState[T]): BestFinder[T] = BestFinder(cbo, memoState)
+ ras: Ras[T],
+ memoState: MemoState[T]): BestFinder[T] = BestFinder(ras, memoState)
}
abstract class CyclicSearchSpaceSuite extends AnyFunSuite {
import CyclicSearchSpaceSuite._
- protected def newBestFinder[T <: AnyRef](cbo: Cbo[T], memoState: MemoState[T]): BestFinder[T]
+ protected def newBestFinder[T <: AnyRef](ras: Ras[T], memoState: MemoState[T]): BestFinder[T]
test("Cyclic - find paths, simple self cycle") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val mock = MockMemoState.Builder(cbo)
+ val mock = MockMemoState.Builder(ras)
val cluster = mock.newCluster()
val groupA = cluster.newGroup()
- val node1 = Unary("node1", groupA.self).asCanonical(cbo)
- val node2 = Leaf("node2", 1).asCanonical(cbo)
+ val node1 = Unary("node1", groupA.self).asCanonical(ras)
+ val node2 = Leaf("node2", 1).asCanonical(ras)
groupA.add(List(node1, node2))
@@ -61,57 +61,57 @@ abstract class CyclicSearchSpaceSuite extends AnyFunSuite {
val mockState = mock.build()
- def find(can: CanonicalNode[TestNode], depth: Int): Iterable[CboPath[TestNode]] = {
- PathFinder.builder(cbo, mockState).depth(depth).build().find(can)
+ def find(can: CanonicalNode[TestNode], depth: Int): Iterable[RasPath[TestNode]] = {
+ PathFinder.builder(ras, mockState).depth(depth).build().find(can)
}
assert(find(node1, 1).map(p => p.plan()) == List(Unary("node1", Group(0))))
assert(find(node1, 2).map(p => p.plan()) == List(Unary("node1", Leaf("node2", 1))))
assert(find(node1, 3).map(p => p.plan()) == List(Unary("node1", Leaf("node2", 1))))
assert(
- find(node1, CboPath.INF_DEPTH).map(p => p.plan()) == List(Unary("node1", Leaf("node2", 1))))
+ find(node1, RasPath.INF_DEPTH).map(p => p.plan()) == List(Unary("node1", Leaf("node2", 1))))
}
test("Cyclic - find best, simple self cycle") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val mock = MockMemoState.Builder(cbo)
+ val mock = MockMemoState.Builder(ras)
val cluster = mock.newCluster()
val groupA = cluster.newGroup()
- val node1 = Unary("node1", groupA.self).asCanonical(cbo)
- val node2 = Leaf("node2", 1).asCanonical(cbo)
+ val node1 = Unary("node1", groupA.self).asCanonical(ras)
+ val node2 = Leaf("node2", 1).asCanonical(ras)
groupA.add(List(node1, node2))
cluster.addNodes(List(node1, node2))
val mockState = mock.build()
- val bestFinder = newBestFinder(cbo, mockState)
+ val bestFinder = newBestFinder(ras, mockState)
val best = bestFinder.bestOf(groupA.id).path()
- assert(best.cboPath.plan() == Leaf("node2", 1))
+ assert(best.rasPath.plan() == Leaf("node2", 1))
assert(best.cost == LongCost(1))
}
test("Cyclic - find best, case 1") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val mock = MockMemoState.Builder(cbo)
+ val mock = MockMemoState.Builder(ras)
val cluster = mock.newCluster()
val groupA = cluster.newGroup()
@@ -123,17 +123,17 @@ abstract class CyclicSearchSpaceSuite extends AnyFunSuite {
val groupG = cluster.newGroup()
val groupH = cluster.newGroup()
- val node1 = Binary("node1", groupB.self, groupC.self).asCanonical(cbo)
- val node2 = Unary("node2", groupF.self).asCanonical(cbo)
- val node3 = Binary("node3", groupD.self, groupF.self).asCanonical(cbo)
- val node4 = Binary("node4", groupG.self, groupH.self).asCanonical(cbo)
- val node5 = Unary("node5", groupC.self).asCanonical(cbo)
- val node6 = Unary("node6", groupE.self).asCanonical(cbo)
- val node7 = Leaf("node7", 1).asCanonical(cbo)
- val node8 = Leaf("node8", 1).asCanonical(cbo)
- val node9 = Leaf("node9", 1).asCanonical(cbo)
+ val node1 = Binary("node1", groupB.self, groupC.self).asCanonical(ras)
+ val node2 = Unary("node2", groupF.self).asCanonical(ras)
+ val node3 = Binary("node3", groupD.self, groupF.self).asCanonical(ras)
+ val node4 = Binary("node4", groupG.self, groupH.self).asCanonical(ras)
+ val node5 = Unary("node5", groupC.self).asCanonical(ras)
+ val node6 = Unary("node6", groupE.self).asCanonical(ras)
+ val node7 = Leaf("node7", 1).asCanonical(ras)
+ val node8 = Leaf("node8", 1).asCanonical(ras)
+ val node9 = Leaf("node9", 1).asCanonical(ras)
// The best path should avoid including this node to most extent.
- val node10 = Leaf("node10", 100).asCanonical(cbo)
+ val node10 = Leaf("node10", 100).asCanonical(ras)
groupA.add(node1)
groupB.add(node2)
@@ -148,9 +148,9 @@ abstract class CyclicSearchSpaceSuite extends AnyFunSuite {
val mockState = mock.build()
- val bestFinder = newBestFinder(cbo, mockState)
+ val bestFinder = newBestFinder(ras, mockState)
- def assertBestOf(group: CboGroup[TestNode])(assertion: Best[TestNode] => Unit): Unit = {
+ def assertBestOf(group: RasGroup[TestNode])(assertion: Best[TestNode] => Unit): Unit = {
val best = bestFinder.bestOf(group.id())
assertion(best)
}
@@ -166,16 +166,16 @@ abstract class CyclicSearchSpaceSuite extends AnyFunSuite {
}
test("Cyclic - find best, case 2") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
- val mock = MockMemoState.Builder(cbo)
+ val mock = MockMemoState.Builder(ras)
val cluster = mock.newCluster()
val groupA = cluster.newGroup()
@@ -183,12 +183,12 @@ abstract class CyclicSearchSpaceSuite extends AnyFunSuite {
val groupC = cluster.newGroup()
val groupD = cluster.newGroup()
- val node1 = Unary("node1", groupB.self).asCanonical(cbo)
- val node2 = Unary("node2", groupC.self).asCanonical(cbo)
- val node3 = Unary("node3", groupC.self).asCanonical(cbo)
- val node4 = Unary("node4", groupD.self).asCanonical(cbo)
- val node5 = Unary("node5", groupB.self).asCanonical(cbo)
- val node6 = Leaf("node6", 1).asCanonical(cbo)
+ val node1 = Unary("node1", groupB.self).asCanonical(ras)
+ val node2 = Unary("node2", groupC.self).asCanonical(ras)
+ val node3 = Unary("node3", groupC.self).asCanonical(ras)
+ val node4 = Unary("node4", groupD.self).asCanonical(ras)
+ val node5 = Unary("node5", groupB.self).asCanonical(ras)
+ val node6 = Leaf("node6", 1).asCanonical(ras)
groupA.add(node1)
groupA.add(node2)
@@ -201,7 +201,7 @@ abstract class CyclicSearchSpaceSuite extends AnyFunSuite {
val mockState = mock.build()
- val bestFinder = newBestFinder(cbo, mockState)
+ val bestFinder = newBestFinder(ras, mockState)
val best = bestFinder.bestOf(groupA.id)
assert(best.costs()(InGroupNode(groupA.id, node1)).contains(LongCost(3)))
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/specific/DistributedSuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/specific/DistributedSuite.scala
similarity index 91%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/specific/DistributedSuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/specific/DistributedSuite.scala
index ad4928608..cab3d1818 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/specific/DistributedSuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/specific/DistributedSuite.scala
@@ -14,78 +14,78 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.specific
+package org.apache.gluten.ras.specific
-import org.apache.gluten.cbo._
-import org.apache.gluten.cbo.CboConfig.PlannerType
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.property.PropertySet
-import org.apache.gluten.cbo.rule.{CboRule, Shape, Shapes}
+import org.apache.gluten.ras._
+import org.apache.gluten.ras.RasConfig.PlannerType
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.property.PropertySet
+import org.apache.gluten.ras.rule.{RasRule, Shape, Shapes}
import org.scalatest.funsuite.AnyFunSuite
class ExhaustivePlannerDistributedSuite extends DistributedSuite {
- override protected def conf: CboConfig = CboConfig(plannerType = PlannerType.Exhaustive)
+ override protected def conf: RasConfig = RasConfig(plannerType = PlannerType.Exhaustive)
}
class DpPlannerDistributedSuite extends DistributedSuite {
- override protected def conf: CboConfig = CboConfig(plannerType = PlannerType.Dp)
+ override protected def conf: RasConfig = RasConfig(plannerType = PlannerType.Dp)
}
abstract class DistributedSuite extends AnyFunSuite {
import DistributedSuite._
- protected def conf: CboConfig
+ protected def conf: RasConfig
test("Project - dry run") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
DistributedPropertyModel,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
val plan = DProject(DLeaf())
- val planner = cbo.newPlanner(plan, PropertySet(List(AnyDistribution, AnyOrdering)))
+ val planner = ras.newPlanner(plan, PropertySet(List(AnyDistribution, AnyOrdering)))
val out = planner.plan()
assert(out == DProject(DLeaf()))
}
test("Project - required distribution") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
DistributedPropertyModel,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
val plan = DProject(DLeaf())
val planner =
- cbo.newPlanner(plan, PropertySet(List(HashDistribution(List("a", "b")), AnyOrdering)))
+ ras.newPlanner(plan, PropertySet(List(HashDistribution(List("a", "b")), AnyOrdering)))
val out = planner.plan()
assert(out == DProject(DExchange(List("a", "b"), DLeaf())))
}
test("Aggregate - none-distribution constraint") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
DistributedPropertyModel,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
val plan = DAggregate(List("a", "b"), DLeaf())
val planner =
- cbo.newPlanner(plan, PropertySet(List(HashDistribution(List("b", "c")), AnyOrdering)))
+ ras.newPlanner(plan, PropertySet(List(HashDistribution(List("b", "c")), AnyOrdering)))
val out = planner.plan()
assert(
out == DExchange(
@@ -94,37 +94,37 @@ abstract class DistributedSuite extends AnyFunSuite {
}
test("Project - required ordering") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
DistributedPropertyModel,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
val plan = DProject(DLeaf())
val planner =
- cbo.newPlanner(plan, PropertySet(List(AnyDistribution, SimpleOrdering(List("a", "b")))))
+ ras.newPlanner(plan, PropertySet(List(AnyDistribution, SimpleOrdering(List("a", "b")))))
val out = planner.plan()
assert(out == DProject(DSort(List("a", "b"), DLeaf())))
}
test("Project - required distribution and ordering") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
DistributedPropertyModel,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
val plan = DProject(DLeaf())
val planner =
- cbo.newPlanner(
+ ras.newPlanner(
plan,
PropertySet(List(HashDistribution(List("a", "b")), SimpleOrdering(List("b", "c")))))
val out = planner.plan()
@@ -132,18 +132,18 @@ abstract class DistributedSuite extends AnyFunSuite {
}
test("Aggregate - avoid re-exchange") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
DistributedPropertyModel,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
val plan = DAggregate(List("a"), DProject(DAggregate(List("a", "b"), DLeaf())))
- val planner = cbo.newPlanner(plan, PropertySet(List(AnyDistribution, AnyOrdering)))
+ val planner = ras.newPlanner(plan, PropertySet(List(AnyDistribution, AnyOrdering)))
val out = planner.plan()
assert(
out == DAggregate(
@@ -152,19 +152,19 @@ abstract class DistributedSuite extends AnyFunSuite {
}
test("Aggregate - avoid re-exchange, required ordering") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
DistributedPropertyModel,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
val plan = DAggregate(List("a"), DProject(DAggregate(List("a", "b"), DLeaf())))
val planner =
- cbo.newPlanner(plan, PropertySet(List(AnyDistribution, SimpleOrdering(List("b", "c")))))
+ ras.newPlanner(plan, PropertySet(List(AnyDistribution, SimpleOrdering(List("b", "c")))))
val out = planner.plan()
assert(
out == DSort(
@@ -173,18 +173,18 @@ abstract class DistributedSuite extends AnyFunSuite {
}
ignore("Aggregate - avoid re-exchange, partial") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
DistributedPropertyModel,
ExplainImpl,
- CboRule.Factory.reuse(List(PartialAggregateRule)))
+ RasRule.Factory.reuse(List(PartialAggregateRule)))
.withNewConfig(_ => conf)
val plan = DAggregate(List("a"), DProject(DAggregate(List("a", "b"), DLeaf())))
- val planner = cbo.newPlanner(plan, PropertySet(List(AnyDistribution, AnyOrdering)))
+ val planner = ras.newPlanner(plan, PropertySet(List(AnyDistribution, AnyOrdering)))
val out = planner.plan()
// FIXME: Should push partial agg down through exchange, otherwise we'd have to write
// a rule for that
@@ -202,7 +202,7 @@ abstract class DistributedSuite extends AnyFunSuite {
object DistributedSuite {
- object PartialAggregateRule extends CboRule[TestNode] {
+ object PartialAggregateRule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case DAggregate(keys, child) => List(DFinalAggregate(keys, DPartialAggregate(keys, child)))
@@ -317,7 +317,7 @@ object DistributedSuite {
}
}
- private class EnforceDistribution(distribution: Distribution) extends CboRule[TestNode] {
+ private class EnforceDistribution(distribution: Distribution) extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = (node, distribution) match {
case (d: DNode, HashDistribution(keys)) => List(DExchange(keys, d))
case (d: DNode, AnyDistribution) => List(d)
@@ -328,7 +328,7 @@ object DistributedSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- private class EnforceOrdering(ordering: Ordering) extends CboRule[TestNode] {
+ private class EnforceOrdering(ordering: Ordering) extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = (node, ordering) match {
case (d: DNode, SimpleOrdering(keys)) => List(DSort(keys, d))
case (d: DNode, AnyOrdering) => List(d)
@@ -344,7 +344,7 @@ object DistributedSuite {
override def newEnforcerRuleFactory(propertyDef: PropertyDef[TestNode, _ <: Property[TestNode]])
: EnforcerRuleFactory[TestNode] = new EnforcerRuleFactory[TestNode] {
- override def newEnforcerRules(constraint: Property[TestNode]): Seq[CboRule[TestNode]] = {
+ override def newEnforcerRules(constraint: Property[TestNode]): Seq[RasRule[TestNode]] = {
constraint match {
case distribution: Distribution => List(new EnforceDistribution(distribution))
case ordering: Ordering => List(new EnforceOrdering(ordering))
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/specific/JoinReorderSuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/specific/JoinReorderSuite.scala
similarity index 82%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/specific/JoinReorderSuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/specific/JoinReorderSuite.scala
index 1a15e57f0..366955401 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/specific/JoinReorderSuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/specific/JoinReorderSuite.scala
@@ -14,73 +14,73 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.specific
+package org.apache.gluten.ras.specific
-import org.apache.gluten.cbo.{Cbo, CboConfig}
-import org.apache.gluten.cbo.CboConfig.PlannerType
-import org.apache.gluten.cbo.CboSuiteBase._
-import org.apache.gluten.cbo.rule.{CboRule, Shape, Shapes}
+import org.apache.gluten.ras.{Ras, RasConfig}
+import org.apache.gluten.ras.RasConfig.PlannerType
+import org.apache.gluten.ras.RasSuiteBase._
+import org.apache.gluten.ras.rule.{RasRule, Shape, Shapes}
import org.scalatest.funsuite.AnyFunSuite
class ExhaustivePlannerJoinReorderSuite extends JoinReorderSuite {
- override protected def conf: CboConfig = CboConfig(plannerType = PlannerType.Exhaustive)
+ override protected def conf: RasConfig = RasConfig(plannerType = PlannerType.Exhaustive)
}
class DpPlannerJoinReorderSuite extends JoinReorderSuite {
- override protected def conf: CboConfig = CboConfig(plannerType = PlannerType.Dp)
+ override protected def conf: RasConfig = RasConfig(plannerType = PlannerType.Dp)
}
abstract class JoinReorderSuite extends AnyFunSuite {
import JoinReorderSuite._
- protected def conf: CboConfig
+ protected def conf: RasConfig
test("3 way join - dry run") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.none())
+ RasRule.Factory.none())
.withNewConfig(_ => conf)
val plan = LeftJoin(LeftJoin(Scan(50), Scan(200)), Scan(100))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val out = planner.plan()
assert(out == plan)
}
test("3 way join - reorder") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(JoinAssociateRule, JoinCommuteRule)))
+ RasRule.Factory.reuse(List(JoinAssociateRule, JoinCommuteRule)))
.withNewConfig(_ => conf)
val plan = LeftJoin(LeftJoin(Scan(200), Scan(100)), Scan(30))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val out = planner.plan()
assert(out == LeftJoin(LeftJoin(Scan(30), Scan(200)), Scan(100)))
}
test("5 way join - reorder") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(JoinAssociateRule, JoinCommuteRule)))
+ RasRule.Factory.reuse(List(JoinAssociateRule, JoinCommuteRule)))
.withNewConfig(_ => conf)
val plan =
LeftJoin(LeftJoin(Scan(2000), Scan(300)), LeftJoin(LeftJoin(Scan(200), Scan(1000)), Scan(50)))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val out = planner.plan()
assert(
out == LeftJoin(
@@ -90,35 +90,35 @@ abstract class JoinReorderSuite extends AnyFunSuite {
// too slow
ignore("7 way join - reorder") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(JoinAssociateRule, JoinCommuteRule)))
+ RasRule.Factory.reuse(List(JoinAssociateRule, JoinCommuteRule)))
.withNewConfig(_ => conf)
val plan = LeftJoin(
LeftJoin(
LeftJoin(Scan(2000), Scan(300)),
LeftJoin(LeftJoin(Scan(200), Scan(1000)), Scan(50))),
LeftJoin(Scan(700), Scan(3000)))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val out = planner.plan()
throw new UnsupportedOperationException("Not yet implemented")
}
// too slow
ignore("9 way join - reorder") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(JoinAssociateRule, JoinCommuteRule)))
+ RasRule.Factory.reuse(List(JoinAssociateRule, JoinCommuteRule)))
.withNewConfig(_ => conf)
val plan = LeftJoin(
LeftJoin(
@@ -126,21 +126,21 @@ abstract class JoinReorderSuite extends AnyFunSuite {
LeftJoin(LeftJoin(Scan(200), Scan(1000)), Scan(50))),
LeftJoin(LeftJoin(Scan(700), Scan(3000)), LeftJoin(Scan(9000), Scan(1000)))
)
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val out = planner.plan()
throw new UnsupportedOperationException("Not yet implemented")
}
// too slow
ignore("12 way join - reorder") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(List(JoinAssociateRule, JoinCommuteRule)))
+ RasRule.Factory.reuse(List(JoinAssociateRule, JoinCommuteRule)))
.withNewConfig(_ => conf)
val plan = LeftJoin(
LeftJoin(
@@ -151,56 +151,56 @@ abstract class JoinReorderSuite extends AnyFunSuite {
),
LeftJoin(LeftJoin(Scan(5000), Scan(1200)), Scan(150))
)
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val out = planner.plan()
throw new UnsupportedOperationException("Not yet implemented")
}
test("2 way join - reorder, left deep only") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(leftDeepJoinRules(2)))
+ RasRule.Factory.reuse(leftDeepJoinRules(2)))
.withNewConfig(_ => conf)
val plan = LeftJoin(Scan(200), Scan(30))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val out = planner.plan()
assert(out == LeftDeepJoin(Scan(30), Scan(200)))
}
test("3 way join - reorder, left deep only") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(leftDeepJoinRules(3)))
+ RasRule.Factory.reuse(leftDeepJoinRules(3)))
.withNewConfig(_ => conf)
val plan = LeftJoin(LeftJoin(Scan(200), Scan(100)), Scan(30))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val out = planner.plan()
assert(out == LeftDeepJoin(LeftDeepJoin(Scan(30), Scan(200)), Scan(100)))
}
test("5 way join - reorder, left deep only") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(leftDeepJoinRules(5)))
+ RasRule.Factory.reuse(leftDeepJoinRules(5)))
.withNewConfig(_ => conf)
val plan =
LeftJoin(LeftJoin(Scan(2000), Scan(300)), LeftJoin(LeftJoin(Scan(200), Scan(1000)), Scan(50)))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val out = planner.plan()
assert(
out == LeftDeepJoin(
@@ -209,21 +209,21 @@ abstract class JoinReorderSuite extends AnyFunSuite {
}
test("7 way join - reorder, left deep only") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(leftDeepJoinRules(7)))
+ RasRule.Factory.reuse(leftDeepJoinRules(7)))
.withNewConfig(_ => conf)
val plan = LeftJoin(
LeftJoin(
LeftJoin(Scan(2000), Scan(300)),
LeftJoin(LeftJoin(Scan(200), Scan(1000)), Scan(50))),
LeftJoin(Scan(700), Scan(3000)))
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val out = planner.plan()
assert(
out == LeftDeepJoin(
@@ -236,14 +236,14 @@ abstract class JoinReorderSuite extends AnyFunSuite {
}
test("9 way join - reorder, left deep only") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(leftDeepJoinRules(9)))
+ RasRule.Factory.reuse(leftDeepJoinRules(9)))
.withNewConfig(_ => conf)
val plan = LeftJoin(
LeftJoin(
@@ -251,7 +251,7 @@ abstract class JoinReorderSuite extends AnyFunSuite {
LeftJoin(LeftJoin(Scan(200), Scan(1000)), Scan(50))),
LeftJoin(LeftJoin(Scan(700), Scan(3000)), LeftJoin(Scan(9000), Scan(1000)))
)
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val out = planner.plan()
assert(
out == LeftDeepJoin(
@@ -273,14 +273,14 @@ abstract class JoinReorderSuite extends AnyFunSuite {
// too slow
ignore("12 way join - reorder, left deep only") {
- val cbo =
- Cbo[TestNode](
+ val ras =
+ Ras[TestNode](
PlanModelImpl,
CostModelImpl,
MetadataModelImpl,
PropertyModelImpl,
ExplainImpl,
- CboRule.Factory.reuse(leftDeepJoinRules(12)))
+ RasRule.Factory.reuse(leftDeepJoinRules(12)))
.withNewConfig(_ => conf)
val plan = LeftJoin(
LeftJoin(
@@ -291,7 +291,7 @@ abstract class JoinReorderSuite extends AnyFunSuite {
),
LeftJoin(LeftJoin(Scan(5000), Scan(1200)), Scan(150))
)
- val planner = cbo.newPlanner(plan)
+ val planner = ras.newPlanner(plan)
val out = planner.plan()
throw new UnsupportedOperationException("Not yet implemented")
}
@@ -299,7 +299,7 @@ abstract class JoinReorderSuite extends AnyFunSuite {
object JoinReorderSuite {
- object JoinAssociateRule extends CboRule[TestNode] {
+ object JoinAssociateRule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case LeftJoin(LeftJoin(a, b), c) => List(LeftJoin(a, LeftJoin(b, c)))
case LeftJoin(a, LeftJoin(b, c)) => List(LeftJoin(LeftJoin(a, b), c))
@@ -309,7 +309,7 @@ object JoinReorderSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- object JoinCommuteRule extends CboRule[TestNode] {
+ object JoinCommuteRule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case LeftJoin(a, b) => List(LeftJoin(b, a))
case other => List.empty
@@ -354,7 +354,7 @@ object JoinReorderSuite {
// Rules and node types for left deep join
- private def leftDeepJoinRules(expandThreshold: Int): List[CboRule[TestNode]] = {
+ private def leftDeepJoinRules(expandThreshold: Int): List[RasRule[TestNode]] = {
List(
MultiJoinRule,
MultiJoinMergeRule,
@@ -364,7 +364,7 @@ object JoinReorderSuite {
)
}
- object MultiJoinRule extends CboRule[TestNode] {
+ object MultiJoinRule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case LeftJoin(left, right) => List(MultiJoin(List(left, right)))
case _ => List.empty
@@ -373,7 +373,7 @@ object JoinReorderSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- object MultiJoinMergeRule extends CboRule[TestNode] {
+ object MultiJoinMergeRule extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = {
val out = shift0(node)
@@ -393,7 +393,7 @@ object JoinReorderSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- case class MultiJoinToLeftDeepJoinRule(expandThreshold: Int) extends CboRule[TestNode] {
+ case class MultiJoinToLeftDeepJoinRule(expandThreshold: Int) extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case MultiJoin(children) if children.size >= expandThreshold =>
List(children.reduce((a, b) => LeftDeepJoin(a, b)))
@@ -403,7 +403,7 @@ object JoinReorderSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(1)
}
- object LeftDeepJoinCommuteRule2 extends CboRule[TestNode] {
+ object LeftDeepJoinCommuteRule2 extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case LeftDeepJoin(s1 @ Scan(a), s2 @ Scan(b)) => List(LeftDeepJoin(s2, s1))
case _ => List.empty
@@ -412,7 +412,7 @@ object JoinReorderSuite {
override def shape(): Shape[TestNode] = Shapes.fixedHeight(2)
}
- object LeftDeepJoinCommuteRule3 extends CboRule[TestNode] {
+ object LeftDeepJoinCommuteRule3 extends RasRule[TestNode] {
override def shift(node: TestNode): Iterable[TestNode] = node match {
case LeftDeepJoin(LeftDeepJoin(a, s1 @ Scan(_)), s2 @ Scan(_)) =>
List(LeftDeepJoin(LeftDeepJoin(a, s2), s1))
diff --git a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/util/IndexDisjointSetSuite.scala b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/util/IndexDisjointSetSuite.scala
similarity index 98%
rename from gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/util/IndexDisjointSetSuite.scala
rename to gluten-ras/common/src/test/scala/org/apache/gluten/ras/util/IndexDisjointSetSuite.scala
index df576cc2f..47f91d9e8 100644
--- a/gluten-cbo/common/src/test/scala/org/apache/gluten/cbo/util/IndexDisjointSetSuite.scala
+++ b/gluten-ras/common/src/test/scala/org/apache/gluten/ras/util/IndexDisjointSetSuite.scala
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.cbo.util
+package org.apache.gluten.ras.util
import org.scalatest.funsuite.AnyFunSuite
diff --git a/gluten-cbo/planner/pom.xml b/gluten-ras/planner/pom.xml
similarity index 88%
rename from gluten-cbo/planner/pom.xml
rename to gluten-ras/planner/pom.xml
index 003bf4e9c..1ad4af18e 100644
--- a/gluten-cbo/planner/pom.xml
+++ b/gluten-ras/planner/pom.xml
@@ -4,16 +4,16 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.gluten</groupId>
- <artifactId>gluten-cbo</artifactId>
+ <artifactId>gluten-ras</artifactId>
<version>1.2.0-SNAPSHOT</version>
</parent>
- <artifactId>gluten-cbo-planner</artifactId>
- <name>Gluten Cbo Planner</name>
+ <artifactId>gluten-ras-planner</artifactId>
+ <name>Gluten Ras Planner</name>
<dependencies>
<dependency>
<groupId>org.apache.gluten</groupId>
- <artifactId>gluten-cbo-common</artifactId>
+ <artifactId>gluten-ras-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
diff --git a/gluten-cbo/planner/src/main/scala/org/apache/gluten/planner/.gitkeep b/gluten-ras/planner/src/main/scala/org/apache/gluten/planner/.gitkeep
similarity index 69%
rename from gluten-cbo/planner/src/main/scala/org/apache/gluten/planner/.gitkeep
rename to gluten-ras/planner/src/main/scala/org/apache/gluten/planner/.gitkeep
index 54d9eab91..90e4ec906 100644
--- a/gluten-cbo/planner/src/main/scala/org/apache/gluten/planner/.gitkeep
+++ b/gluten-ras/planner/src/main/scala/org/apache/gluten/planner/.gitkeep
@@ -1 +1 @@
-The module is kept for adding code in future to test Vanilla Spark with CBO without Gluten.
+The module is kept for adding code in future to test Vanilla Spark with RAS without Gluten.
diff --git a/gluten-cbo/planner/src/test/scala/org/apache/gluten/planner/.gitkeep b/gluten-ras/planner/src/test/scala/org/apache/gluten/planner/.gitkeep
similarity index 69%
rename from gluten-cbo/planner/src/test/scala/org/apache/gluten/planner/.gitkeep
rename to gluten-ras/planner/src/test/scala/org/apache/gluten/planner/.gitkeep
index 54d9eab91..90e4ec906 100644
--- a/gluten-cbo/planner/src/test/scala/org/apache/gluten/planner/.gitkeep
+++ b/gluten-ras/planner/src/test/scala/org/apache/gluten/planner/.gitkeep
@@ -1 +1 @@
-The module is kept for adding code in future to test Vanilla Spark with CBO without Gluten.
+The module is kept for adding code in future to test Vanilla Spark with RAS without Gluten.
diff --git a/gluten-cbo/pom.xml b/gluten-ras/pom.xml
similarity index 98%
rename from gluten-cbo/pom.xml
rename to gluten-ras/pom.xml
index c9bb570b7..e2e8fccb2 100644
--- a/gluten-cbo/pom.xml
+++ b/gluten-ras/pom.xml
@@ -19,9 +19,9 @@
<artifactId>gluten-parent</artifactId>
<version>1.2.0-SNAPSHOT</version>
</parent>
- <artifactId>gluten-cbo</artifactId>
+ <artifactId>gluten-ras</artifactId>
<packaging>pom</packaging>
- <name>Gluten Cbo</name>
+ <name>Gluten Ras</name>
<modules>
<module>common</module>
diff --git a/pom.xml b/pom.xml
index 3a6065dd0..b5833b3ad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,7 +34,7 @@
<module>gluten-ui</module>
<module>package</module>
<module>shims</module>
- <module>gluten-cbo</module>
+ <module>gluten-ras</module>
</modules>
<properties>
diff --git a/shims/common/src/main/scala/org/apache/gluten/GlutenConfig.scala b/shims/common/src/main/scala/org/apache/gluten/GlutenConfig.scala
index 3fe3f5fa7..130dbf7bc 100644
--- a/shims/common/src/main/scala/org/apache/gluten/GlutenConfig.scala
+++ b/shims/common/src/main/scala/org/apache/gluten/GlutenConfig.scala
@@ -41,7 +41,7 @@ class GlutenConfig(conf: SQLConf) extends Logging {
def enableGluten: Boolean = conf.getConf(GLUTEN_ENABLED)
- def enableAdvancedCbo: Boolean = conf.getConf(ADVANCED_CBO_ENABLED)
+ def enableRas: Boolean = conf.getConf(RAS_ENABLED)
// FIXME the option currently controls both JVM and native validation against a Substrait plan.
def enableNativeValidation: Boolean = conf.getConf(NATIVE_VALIDATION_ENABLED)
@@ -667,16 +667,12 @@ object GlutenConfig {
.booleanConf
.createWithDefault(GLUTEN_ENABLE_BY_DEFAULT)
- val ADVANCED_CBO_ENABLED =
- buildConf("spark.gluten.sql.advanced.cbo.enabled")
+ val RAS_ENABLED =
+ buildConf("spark.gluten.sql.ras.enabled")
.doc(
- "Experimental: Enables Gluten's advanced CBO features during physical planning. " +
- "E.g, More efficient fallback strategy, etc. The option can be turned on and off " +
- "individually despite vanilla Spark's CBO settings. Note, Gluten's query optimizer " +
- "may still adopt a subset of its advanced CBO capabilities even this option " +
- "is off. Enabling it would cause Gluten consider using CBO for optimization " +
- "more aggressively. Note, this feature is still in development and may not bring " +
- "performance profits.")
+ "Experimental: Enables RAS (relation algebra selector) during physical " +
+ "planning to generate more efficient query plan. Note, this feature is still in " +
+ "development and may not bring performance profits.")
.booleanConf
.createWithDefault(false)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org