From 7de565ef746d99dcc651c06f6f7fc807ff3f6db6 Mon Sep 17 00:00:00 2001 From: sgrebnov Date: Wed, 8 Jan 2025 11:18:16 +0300 Subject: [PATCH] Move `with_custom_scalar_overrides` definition on `Dialect` trait level --- datafusion/sql/src/unparser/dialect.rs | 34 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/datafusion/sql/src/unparser/dialect.rs b/datafusion/sql/src/unparser/dialect.rs index 02b04baecad0..5c318a96ef6c 100644 --- a/datafusion/sql/src/unparser/dialect.rs +++ b/datafusion/sql/src/unparser/dialect.rs @@ -153,6 +153,18 @@ pub trait Dialect: Send + Sync { Ok(None) } + /// Extends the dialect's default rules for unparsing scalar functions. + /// This is useful for supporting application-specific UDFs or custom engine extensions. + fn with_custom_scalar_overrides( + self, + _handlers: Vec<(&str, ScalarFnToSqlHandler)>, + ) -> Self + where + Self: Sized, + { + unimplemented!("Custom scalar overrides are not supported by this dialect yet"); + } + /// Allow to unparse a qualified column with a full qualified name /// (e.g. catalog_name.schema_name.table_name.column_name) /// Otherwise, the column will be unparsed with only the table name and column name @@ -320,17 +332,6 @@ impl DuckDBDialect { custom_scalar_fn_overrides: HashMap::new(), } } - - pub fn with_custom_scalar_overrides( - mut self, - handlers: Vec<(&str, ScalarFnToSqlHandler)>, - ) -> Self { - for (func_name, handler) in handlers { - self.custom_scalar_fn_overrides - .insert(func_name.to_string(), handler); - } - self - } } impl Dialect for DuckDBDialect { @@ -346,6 +347,17 @@ impl Dialect for DuckDBDialect { BinaryOperator::DuckIntegerDivide } + fn with_custom_scalar_overrides( + mut self, + handlers: Vec<(&str, ScalarFnToSqlHandler)>, + ) -> Self { + for (func_name, handler) in handlers { + self.custom_scalar_fn_overrides + .insert(func_name.to_string(), handler); + } + self + } + fn scalar_function_to_sql_overrides( &self, unparser: &Unparser,