silundong commented on code in PR #4492:
URL: https://github.com/apache/calcite/pull/4492#discussion_r2255839268


##########
core/src/main/java/org/apache/calcite/plan/CommonRelExpressionRegistry.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.plan;
+
+import org.apache.calcite.rel.RelNode;
+
+import org.apiguardian.api.API;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Stream;
+
+/**
+ * A registry of common relational expressions for a given query.
+ *
+ * <p>The registry is only meant to hold common expressions for a single query.
+ *
+ * <p>The class is not thread-safe.
+ */
+@API(since = "1.41.0", status = API.Status.INTERNAL)
+public final class CommonRelExpressionRegistry {
+  /**
+   * A unique collection of common expressions.
+   *
+   * <p>The expressions may contain internal planning concepts such as {@link 
org.apache.calcite.plan.hep.HepRelVertex}.
+   */
+  private final Map<String, RelNode> rels = new HashMap<>();
+
+  /**
+   * Adds the specified expression to this registry.
+   *
+   * @param rel a relational expression to be added to the registry.
+   */
+  public void add(RelNode rel) {
+    this.rels.put(rel.getDigest(), rel);

Review Comment:
   `rel.getDigest()` return `RelDigest.toString()`, which prints the content 
defined in `explainTerms(RelWriter pw)`, as well as the input class name and 
id. If the plan is not registered in the HepPlanner (`noDag` is false) or 
VolcanoPlanner, even if two RelNodes in the plan are the same, they are 
different objects with different id. Therefore, as far as I know, determining 
RelNode equivalence typically uses the RelDigest object, not its string 
representation.
   However, the current implement uses HepPlanner (`noDag` is false by 
default), it's ok.  So, is it necessary to add a comment here to clarify this 
premise?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to