Skip to content
Draft
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
110 changes: 17 additions & 93 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ regex = "1.12"
rstest = "0.26.1"
serde_json = "1"
sha2 = "^0.11.0"
sqlparser = { version = "0.61.0", default-features = false, features = ["std", "visitor"] }
sqlparser = { git = "https://github.com/apache/datafusion-sqlparser-rs", rev = "9833c033bc44c487b4425272cc8cea80971b5239", default-features = false, features = ["std", "visitor"] }
strum = "0.28.0"
strum_macros = "0.28.0"
tempfile = "3"
Expand Down
4 changes: 2 additions & 2 deletions datafusion/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4123,8 +4123,8 @@ mod test {
wildcard_with_options(wildcard_options(
None,
Some(ExcludeSelectItem::Multiple(vec![
Ident::from("c1"),
Ident::from("c2")
Ident::from("c1").into(),
Ident::from("c2").into()
])),
None,
None,
Expand Down
31 changes: 31 additions & 0 deletions datafusion/expr/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,38 @@ fn get_excluded_columns(
idents.push(&excepts.first_element);
idents.extend(&excepts.additional_elements);
}
// Declared outside the `if let` so `idents.extend(exclude_owned.iter())`
// below can borrow references that outlive the inner scope.
#[cfg(feature = "sql")]
let exclude_owned: Vec<sqlparser::ast::Ident>;
if let Some(exclude) = opt_exclude {
#[cfg(feature = "sql")]
{
let object_name_to_ident =
|name: &sqlparser::ast::ObjectName| -> Result<sqlparser::ast::Ident> {
if name.0.len() != 1 {
return plan_err!(
"EXCLUDE with multi-part identifiers is not supported: {name}"
);
}
let part = &name.0[0];
let Some(ident) = part.as_ident() else {
return plan_err!(
"EXCLUDE with non-identifier name part is not supported: {part}"
);
};
Ok(ident.clone())
};
exclude_owned = match exclude {
ExcludeSelectItem::Single(name) => vec![object_name_to_ident(name)?],
ExcludeSelectItem::Multiple(names) => names
.iter()
.map(object_name_to_ident)
.collect::<Result<Vec<_>>>()?,
};
idents.extend(exclude_owned.iter());
}
#[cfg(not(feature = "sql"))]
match exclude {
ExcludeSelectItem::Single(ident) => idents.push(ident),
ExcludeSelectItem::Multiple(idents_inner) => idents.extend(idents_inner),
Expand Down
15 changes: 10 additions & 5 deletions datafusion/sql/src/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,10 +927,15 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
);
}

if lambda.params.iter().any(|p| p.data_type.is_some()) {
return not_impl_err!(
"Lambda parameters with explicit data types are not supported"
);
}
let params = lambda
.params
.iter()
.map(|p| crate::utils::normalize_ident(p.clone()))
.map(|p| crate::utils::normalize_ident(p.name.clone()))
.collect();

let lambda_parameters = std::iter::zip(lambda_params, &params)
Expand Down Expand Up @@ -1181,19 +1186,19 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
/// After normalization with [normalize_ident], check whether all params are unique
///
/// [normalize_ident]: crate::utils::normalize_ident
fn all_unique(params: &[sqlparser::ast::Ident]) -> bool {
fn all_unique(params: &[sqlparser::ast::LambdaFunctionParameter]) -> bool {
match params.len() {
0 | 1 => true,
2 => {
crate::utils::normalize_ident(params[0].clone())
!= crate::utils::normalize_ident(params[1].clone())
crate::utils::normalize_ident(params[0].name.clone())
!= crate::utils::normalize_ident(params[1].name.clone())
}
_ => {
let mut set = HashSet::with_capacity(params.len());

params
.iter()
.map(|p| crate::utils::normalize_ident(p.clone()))
.map(|p| crate::utils::normalize_ident(p.name.clone()))
.all(|p| set.insert(p))
}
}
Expand Down
8 changes: 4 additions & 4 deletions datafusion/sql/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
negated: bool,
expr: SQLExpr,
pattern: SQLExpr,
escape_char: Option<Value>,
escape_char: Option<ValueWithSpan>,
schema: &DFSchema,
planner_context: &mut PlannerContext,
case_insensitive: bool,
Expand All @@ -910,7 +910,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
return not_impl_err!("ANY in LIKE expression");
}
let pattern = self.sql_expr_to_logical_expr(pattern, schema, planner_context)?;
let escape_char = match escape_char {
let escape_char = match escape_char.map(|v| v.value) {
Some(Value::SingleQuotedString(char)) if char.len() == 1 => {
Some(char.chars().next().unwrap())
}
Expand All @@ -935,7 +935,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
negated: bool,
expr: SQLExpr,
pattern: SQLExpr,
escape_char: Option<Value>,
escape_char: Option<ValueWithSpan>,
schema: &DFSchema,
planner_context: &mut PlannerContext,
) -> Result<Expr> {
Expand All @@ -944,7 +944,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
if pattern_type != DataType::Utf8 && pattern_type != DataType::Null {
return plan_err!("Invalid pattern in SIMILAR TO expression");
}
let escape_char = match escape_char {
let escape_char = match escape_char.map(|v| v.value) {
Some(Value::SingleQuotedString(char)) if char.len() == 1 => {
Some(char.chars().next().unwrap())
}
Expand Down
1 change: 1 addition & 0 deletions datafusion/sql/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
// Apply to all fields
columns: vec![],
explicit: true,
at: None,
},
),
PipeOperator::Union {
Expand Down
6 changes: 6 additions & 0 deletions datafusion/sql/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,9 @@ impl<S: ContextProvider> SqlToRel<'_, S> {

Ok(SelectExpr::Expression(expr))
}
SelectItem::ExprWithAliases { .. } => {
not_impl_err!("SELECT item with multiple aliases is not supported")
}
SelectItem::Wildcard(options) => {
Self::check_wildcard_options(&options)?;
if empty_from {
Expand Down Expand Up @@ -886,11 +889,14 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
opt_rename,
opt_replace: _opt_replace,
opt_ilike: _opt_ilike,
opt_alias,
wildcard_token: _wildcard_token,
} = options;

if opt_rename.is_some() {
not_impl_err!("wildcard * with RENAME not supported ")
} else if opt_alias.is_some() {
not_impl_err!("wildcard * with AS alias not supported")
} else {
Ok(())
}
Expand Down
Loading
Loading