Skip to content

Commit

Permalink
Move with_custom_scalar_overrides definition on Dialect trait level
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrebnov committed Jan 8, 2025
1 parent 13254d2 commit 7de565e
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions datafusion/sql/src/unparser/dialect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit 7de565e

Please sign in to comment.