Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ regex = "1.12"
rstest = "0.26.1"
serde_json = "1"
sha2 = "^0.11.0"
sqlparser = { version = "0.62.0", default-features = false, features = ["std", "visitor"] }
sqlparser = { git = "https://github.com/Embucket/datafusion-sqlparser-rs.git", rev = "1a3f48f60802d0f135a968a27c89a3351e78b159", default-features = false, features = [
"std",
"visitor",
] }
stacker = "0.1.24"
strum = "0.28.0"
strum_macros = "0.28.0"
Expand Down
53 changes: 38 additions & 15 deletions datafusion/sql/src/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,29 @@ use datafusion_expr::{
use sqlparser::ast::{
DuplicateTreatment, Expr as SQLExpr, Function as SQLFunction, FunctionArg,
FunctionArgExpr, FunctionArgumentClause, FunctionArgumentList, FunctionArguments,
LambdaFunction, ObjectName, OrderByExpr, Spanned, WindowType,
LambdaFunction, ObjectName, OrderByExpr, Spanned, WildcardAdditionalOptions,
WindowType,
};

fn function_wildcard_options(
options: WildcardAdditionalOptions,
) -> Result<Box<WildcardOptions>> {
if options.opt_alias.is_some() {
return not_impl_err!("wildcard function argument with AS alias");
}
if options.opt_replace.is_some() {
return not_impl_err!("wildcard function argument with REPLACE");
}

Ok(Box::new(WildcardOptions {
ilike: options.opt_ilike,
exclude: options.opt_exclude,
except: options.opt_except,
replace: None,
rename: options.opt_rename,
}))
}

/// Suggest a valid function based on an invalid input function name
///
/// Returns `None` if no valid matches are found. This happens when there are no
Expand Down Expand Up @@ -1076,23 +1096,10 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
Ok((expr, None))
}
FunctionArg::Unnamed(FunctionArgExpr::WildcardWithOptions(options)) => {
if options.opt_alias.is_some() {
return not_impl_err!("wildcard function argument with AS alias");
}
if options.opt_replace.is_some() {
return not_impl_err!("wildcard function argument with REPLACE");
}

#[expect(deprecated)]
let expr = Expr::Wildcard {
qualifier: None,
options: Box::new(WildcardOptions {
ilike: options.opt_ilike,
exclude: options.opt_exclude,
except: options.opt_except,
replace: None,
rename: options.opt_rename,
}),
options: function_wildcard_options(options)?,
};
Ok((expr, None))
}
Expand All @@ -1111,6 +1118,22 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
};
Ok((expr, None))
}
FunctionArg::Unnamed(FunctionArgExpr::QualifiedWildcardWithOptions(
object_name,
options,
)) => {
let qualifier = self.object_name_to_table_reference(object_name)?;
if schema.fields_indices_with_qualified(&qualifier).is_empty() {
return plan_err!("Invalid qualifier {qualifier}");
}

#[expect(deprecated)]
let expr = Expr::Wildcard {
qualifier: qualifier.into(),
options: function_wildcard_options(options)?,
};
Ok((expr, None))
}
// PostgreSQL dialect uses ExprNamed variant with expression for name
FunctionArg::ExprNamed {
name: SQLExpr::Identifier(name),
Expand Down
22 changes: 22 additions & 0 deletions datafusion/sql/tests/sql_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ use insta::{allow_duplicates, assert_snapshot};
use rstest::rstest;
use sqlparser::dialect::{
DatabricksDialect, Dialect, GenericDialect, HiveDialect, MySqlDialect,
SnowflakeDialect,
};
use sqlparser::parser::Parser;

Expand Down Expand Up @@ -2244,6 +2245,27 @@ fn scalar_expr_planner_applies_wildcard_ilike() {
);
}

#[test]
fn scalar_expr_planner_applies_qualified_wildcard_options() {
let state = mock_session_state().with_expr_planner(Arc::new(ScalarWildcardPlanner));
let plan = logical_plan_from_state(
"SELECT concat((p.* ILIKE '%name')) FROM person AS p",
&SnowflakeDialect {},
ParserOptions::default(),
state,
)
.unwrap();

assert_snapshot!(
plan,
@r"
Projection: concat(p.first_name, p.last_name)
SubqueryAlias: p
TableScan: person
"
);
}

#[test]
fn select_approx_median() {
let sql = "SELECT approx_median(age) FROM person";
Expand Down
Loading