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


##########
datafusion/sql/src/unparser/extension_unparser.rs:
##########
@@ -0,0 +1,66 @@
+// 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 crate::unparser::ast::{QueryBuilder, RelationBuilder, SelectBuilder};
+use crate::unparser::Unparser;
+use datafusion_expr::UserDefinedLogicalNode;
+use sqlparser::ast::Statement;
+
+/// This trait allows users to define custom unparser logic for their custom 
logical nodes.
+pub trait UserDefinedLogicalNodeUnparser {
+    /// Unparse the custom logical node to SQL within a statement.
+    ///
+    /// This method is called when the custom logical node is part of a 
statement.
+    /// e.g. `SELECT * FROM custom_logical_node`
+    ///
+    /// The return value should be [UnparseResult::WithinStatement] if the 
custom logical node was successfully unparsed.
+    /// Otherwise, return [UnparseResult::Original].
+    fn unparse(
+        &self,
+        _node: &dyn UserDefinedLogicalNode,
+        _unparser: &Unparser,
+        _query: &mut Option<&mut QueryBuilder>,
+        _select: &mut Option<&mut SelectBuilder>,
+        _relation: &mut Option<&mut RelationBuilder>,
+    ) -> datafusion_common::Result<UnparseResult> {
+        Ok(UnparseResult::Original)
+    }
+
+    /// Unparse the custom logical node to a statement.
+    ///
+    /// This method is called when the custom logical node is a custom 
statement.
+    ///
+    /// The return value should be [UnparseResult::Statement] if the custom 
logical node was successfully unparsed.
+    /// Otherwise, return [UnparseResult::Original].
+    fn unparse_to_statement(
+        &self,
+        _node: &dyn UserDefinedLogicalNode,
+        _unparser: &Unparser,
+    ) -> datafusion_common::Result<UnparseResult> {
+        Ok(UnparseResult::Original)
+    }
+}
+
+/// The result of unparsing a custom logical node.
+pub enum UnparseResult {

Review Comment:
   I would use two separate enums here since one variant can never be emitted 
in one of the functions, and vice-versa - better type safety, and removes one 
arm of the match clause that just returns an error anyway.
   
   Also perhaps `Unmodified` or `Unmatched` instead of `Original`? It's not 
immediately obvious what an UnparseResult::Original means, but that is quite 
minor - also fine to leave as is.



-- 
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: github-unsubscr...@datafusion.apache.org

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


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

Reply via email to