zhztheplayer commented on code in PR #5058:
URL: https://github.com/apache/incubator-gluten/pull/5058#discussion_r1533287599


##########
gluten-cbo/common/src/main/scala/io/glutenproject/cbo/CboNode.scala:
##########
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.glutenproject.cbo
+
+trait CboNode[T <: AnyRef] {
+  def cbo(): Cbo[T]
+  def self(): T
+  def propSet(): PropertySet[T]
+}
+
+object CboNode {
+  implicit class CboNodeImplicits[T <: AnyRef](node: CboNode[T]) {
+    def isCanonical: Boolean = {
+      node.isInstanceOf[CanonicalNode[T]]
+    }
+
+    def asCanonical(): CanonicalNode[T] = {
+      node.asInstanceOf[CanonicalNode[T]]
+    }
+
+    def isGroup: Boolean = {
+      node.isInstanceOf[GroupNode[T]]
+    }
+
+    def asGroup(): GroupNode[T] = {
+      node.asInstanceOf[GroupNode[T]]
+    }
+  }
+}
+
+trait CanonicalNode[T <: AnyRef] extends CboNode[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)
+  }
+
+  // We put CboNode'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.getChildrenGroups(allGroups, node.self()).map(g => GroupNode(cbo, g))
+    }
+  }
+
+  private case class CanonicalNodeImpl[T <: AnyRef](
+      cbo: Cbo[T],
+      override val self: T,
+      override val propSet: PropertySet[T],
+      override val childrenCount: Int)
+    extends CanonicalNode[T]
+}
+
+trait GroupNode[T <: AnyRef] extends CboNode[T] {

Review Comment:
   A node that exactly represents a group.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@gluten.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@gluten.apache.org
For additional commands, e-mail: commits-h...@gluten.apache.org

Reply via email to