phillipleblanc commented on code in PR #11082:
URL: https://github.com/apache/datafusion/pull/11082#discussion_r1650294115


##########
datafusion/sql/src/unparser/rewrite.rs:
##########
@@ -0,0 +1,96 @@
+// 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::sync::Arc;
+
+use datafusion_common::{
+    tree_node::{Transformed, TransformedResult, TreeNode, TreeNodeRewriter},
+    Result,
+};
+use datafusion_expr::{Expr, LogicalPlan, Sort};
+
+/// Normalize the schema of a union plan to remove qualifiers from the schema 
fields.
+pub(super) struct NormalizeUnionSchema {}
+
+impl NormalizeUnionSchema {
+    pub fn new() -> Self {
+        Self {}
+    }
+}
+
+impl TreeNodeRewriter for NormalizeUnionSchema {
+    type Node = LogicalPlan;
+
+    /// Invoked while traversing down the tree before any children are 
rewritten.
+    /// Default implementation returns the node as is and continues recursion.
+    fn f_down(&mut self, plan: LogicalPlan) -> 
Result<Transformed<LogicalPlan>> {
+        match plan {
+            LogicalPlan::Union(mut union) => {
+                let schema = match Arc::try_unwrap(union.schema) {
+                    Ok(inner) => inner,
+                    Err(schema) => (*schema).clone(),
+                };
+                let schema = schema.strip_qualifiers();
+
+                union.schema = Arc::new(schema);
+                Ok(Transformed::yes(LogicalPlan::Union(union)))
+            }
+            LogicalPlan::Sort(sort) => {

Review Comment:
   Added some documentation to the rewrite function



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to