datafusion_sql::unparser

Function expr_to_sql

Source
pub fn expr_to_sql(expr: &Expr) -> Result<Expr>
Expand description

Convert a DataFusion Expr to ast::Expr

This function is the opposite of SqlToRel::sql_to_expr and can be used to, among other things, convert Exprs to SQL strings. Such strings could be used to pass filters or other expressions to another SQL engine.

§Errors

Throws an error if Expr can not be represented by an ast::Expr

§See Also

§Example

use datafusion_expr::{col, lit};
use datafusion_sql::unparser::expr_to_sql;
let expr = col("a").gt(lit(4)); // form an expression `a > 4`
let sql = expr_to_sql(&expr).unwrap(); // convert to ast::Expr
// use the Display impl to convert to SQL text
assert_eq!(sql.to_string(), "(a > 4)")