alamb commented on issue #13753:
URL: https://github.com/apache/datafusion/issues/13753#issuecomment-2541366688
> I would said we made it public in datafusion-sql (or upstream to
sql-parser) but not moved to datafusion-common. I think we should eliminate
dependency to sql-parser in datafusion-common, we need to move those functions
or structs that have dependency to sql-parser out of datafusion-common to
datafusion-sql
I agree that making the builders / etc public in datafusion-sql is better
than dumping more stuff in datafusion-common
Another potential thought might be to move the unparsing code into its own
crate now given its non trivial complexity now. For example
`datafusion-unparser`
Another potential approach that would avoid adding a dependency on
`UserDefinedLogicalNode`(which is in `datafusion-expr`) on the unparser /
sqlparser might be:
1. Create a new `Unparseable` trait
2. Have the unparser try and downcast the `UserDefinedLogicalNode`
So something like
```rust
pub trait Unparseable {
/// User-defined nodes can override this method to provide a custom
/// implementation for the unparser.
fn unparse(
&self,
unparser: &Unparser,
query: &mut Option<QueryBuilder>,
select: &mut Option<SelectBuilder>,
relation: &mut Option<RelationBuilder>,
table_with_joins: &mut Option<TableWithJoinsBuilder>,
) -> Result<()> {
not_impl_err!("custom unparsing not implemented")
}
}
```
And then the unparser could do something like:
```rust
let user_defined_local_node: dyn &UserDefinedLogicalNode = ...;
// is the user defined node unparseable?
let Some(unparseable) = user_defined_local_node
.as_any()
.downcast_ref::<Unparseable>() else {
return plan_err!("Node type {} does not implement Unparseable",
user_defined_local_node.name())
}
let sql_nodes = unparseable.unparse(unparser, ....)
```
🤔
--
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]