alamb commented on issue #9495:
URL: 
https://github.com/apache/arrow-datafusion/issues/9495#issuecomment-1986424803

   > I split out datafusion-federation's SQL Writer code into its own package 
and added an example for 
[expressions](https://github.com/datafusion-contrib/datafusion-federation/blob/main/sql-writer/examples/expr.rs)
 and 
[plans](https://github.com/datafusion-contrib/datafusion-federation/blob/main/sql-writer/examples/plan.rs).
 I intend to mature it over time. It's open to contributions and/or moving to a 
more canonical place.
   
   
   Thank you very much @backkem -- this is really quite cool.
   
   Here is my suggestion:
   
   We port the `expr_to_sql` upstream into DataFusion  (as this I think is 
easier and has been asked for several times) and we can obsess about making it 
feature complete / tested in this repo. Once that project is complete, we move 
on to the `LogicalPlans` (aka 
https://github.com/apache/arrow-datafusion/issues/8661)
   
   I suggest this API:
   * Crate: 
[`datafusion-sql`](https://docs.rs/datafusion/latest/datafusion/sql/index.html) 
crate 
   * Module: `datafusion_sql::unparser`. In the file 
`datafusion/sql/src/unparser/expr.rs`
   * API
   
   One function
   ```rust
   /// Convert a DataFusion [`Expr`] to `sqlparser::ast::Expr`
   ///
   /// This function is the opposite of `SqlToRel::sql_to_expr`
   ///
   /// Example
   /// ```
   /// let expr = col("a").gt(lit(4));
   /// let sql = expr_to_sql(&expr)?;
   ///
   /// assert_eq(sql.to_string(), "a > 4")
   /// ```
   fn expr_to_sql(expr: Expr) -> Result<sqlparser::ast::Expr> {
   ...
   }
   ```
   
   
   So it seems like the needed steps are:
   1. Agree on new API (see above proposal)
   1. port `expr_to_sql` to the new location
   2. Write tests that cover the new code (maybe round trip Expr -> SQL -> 
Expr?)
   
   
   


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