alamb commented on code in PR #5623:
URL: https://github.com/apache/arrow-datafusion/pull/5623#discussion_r1141036350


##########
datafusion/optimizer/src/optimizer.rs:
##########
@@ -419,6 +412,34 @@ impl Optimizer {
     }
 }
 
+/// Returns an error if plans have different schemas.

Review Comment:
   This is a nice refactor



##########
datafusion/optimizer/src/plan_signature.rs:
##########
@@ -0,0 +1,132 @@
+// 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.
+
+use std::{
+    collections::hash_map::DefaultHasher,
+    convert::Infallible,
+    hash::{Hash, Hasher},
+    num::NonZeroUsize,
+};
+
+use datafusion_expr::{LogicalPlan, PlanVisitor};
+
+/// Non-unique identifier of a [`LogicalPlan`].
+///
+/// See [`LogicalPlanSignature::compute`] for details.
+#[derive(Clone, Copy, PartialEq, Eq, Hash)]
+pub struct LogicalPlanSignature {
+    node_number: NonZeroUsize,
+    plan_hash: u64,
+}
+
+impl LogicalPlanSignature {
+    /// Returns [`LogicalPlanSignature`] of the given [`LogicalPlan`].
+    ///
+    /// It is a kind of [`LogicalPlan`] hashing with stronger guarantees.
+    ///
+    /// # Guarantees
+    ///
+    /// Consider two [`LogicalPlan`]s `p1` and `p2`.
+    ///
+    /// If `p1` and `p2` have a different number of [`LogicalPlan`]s, then
+    /// they will have different [`LogicalPlanSignature`]s.
+    ///
+    /// If `p1` and `p2` have a different [`Hash`], then
+    /// they will have different [`LogicalPlanSignature`]s.
+    ///
+    /// # Caveats
+    ///
+    /// The intention of [`LogicalPlanSignature`] is to have a lower chance
+    /// of hash collisions.
+    ///
+    /// There exist different [`LogicalPlan`]s with the same
+    /// [`LogicalPlanSignature`].
+    ///
+    /// When two [`LogicalPlan`]s differ only in metadata, then they will have
+    /// the same [`LogicalPlanSignature`]s (due to hash implementation in
+    /// [`LogicalPlan`]).
+    pub fn compute(plan: &LogicalPlan) -> Self {

Review Comment:
   I think `pub fn new()` would be more idiomatic to construct a new plan



-- 
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