Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): sync DataFusion for the latest SQL syntax #1017

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 2 additions & 5 deletions wren-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ version = "0.1.0"

[workspace.dependencies]
async-trait = "0.1.80"
# We require the following commits
# https://github.com/apache/datafusion/pull/13241
# https://github.com/goldmedal/datafusion/pull/1
# https://github.com/goldmedal/sqlparser-rs/pull/1
datafusion = { git = "https://github.com/goldmedal/datafusion.git", branch = "wren/support-array-struct" }
# We require the latest sqlparser-rs to support the latest SQL syntax
datafusion = { git = "https://github.com/goldmedal/datafusion.git", branch = "wren/foward-to-compund-access" }
env_logger = "0.11.3"
hashbrown = "0.15.2"
log = { version = "0.4.14" }
Expand Down
2 changes: 1 addition & 1 deletion wren-core/core/src/logical_plan/analyze/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl ModelPlanNodeBuilder {
0,
Expr::Wildcard {
qualifier: None,
options: WildcardOptions::default(),
options: Box::new(WildcardOptions::default()),
},
);
}
Expand Down
3 changes: 3 additions & 0 deletions wren-core/core/src/mdl/dialect/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use datafusion::common::Result;
use datafusion::logical_expr::Expr;
use datafusion::sql::sqlparser::ast;
use datafusion::sql::sqlparser::ast::{Function, Ident, ObjectName};
use datafusion::sql::sqlparser::tokenizer::Span;
use datafusion::sql::unparser::Unparser;

pub(crate) fn function_args_to_sql(
Expand Down Expand Up @@ -55,6 +56,7 @@ pub(crate) fn scalar_function_to_sql_internal(
name: ObjectName(vec![Ident {
value: func_name.to_string(),
quote_style: None,
span: Span::empty(),
}]),
args: ast::FunctionArguments::List(ast::FunctionArgumentList {
duplicate_treatment: None,
Expand All @@ -66,5 +68,6 @@ pub(crate) fn scalar_function_to_sql_internal(
over: None,
within_group: vec![],
parameters: ast::FunctionArguments::None,
uses_odbc_syntax: false,
})))
}
10 changes: 6 additions & 4 deletions wren-core/core/src/mdl/dialect/wren_dialect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use datafusion::logical_expr::sqlparser::ast::{Ident, Subscript};
use datafusion::logical_expr::sqlparser::keywords::ALL_KEYWORDS;
use datafusion::logical_expr::Expr;
use datafusion::sql::sqlparser::ast;
use datafusion::sql::sqlparser::ast::{Array, Value};
use datafusion::sql::sqlparser::ast::{AccessExpr, Array, Value};
use datafusion::sql::sqlparser::tokenizer::Span;
use datafusion::sql::unparser::dialect::{Dialect, IntervalStyle};
use datafusion::sql::unparser::Unparser;
use regex::Regex;
Expand Down Expand Up @@ -118,9 +119,9 @@ impl WrenDialect {
}
let array = unparser.expr_to_sql(&args[0])?;
let index = unparser.expr_to_sql(&args[1])?;
Ok(ast::Expr::Subscript {
expr: Box::new(array),
subscript: Box::new(Subscript::Index { index }),
Ok(ast::Expr::CompoundFieldAccess {
root: Box::new(array),
access_chain: vec![AccessExpr::Subscript(Subscript::Index { index })],
})
}

Expand Down Expand Up @@ -184,6 +185,7 @@ impl WrenDialect {
Ident {
value: ident,
quote_style,
span: Span::empty(),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions wren-core/core/src/mdl/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ByPassScalarUDF {
name: name.to_string(),
return_type,
signature: Signature::one_of(
vec![TypeSignature::VariadicAny, TypeSignature::NullAry],
vec![TypeSignature::VariadicAny, TypeSignature::Nullary],
Volatility::Volatile,
),
}
Expand Down Expand Up @@ -115,7 +115,7 @@ impl ByPassAggregateUDF {
name: name.to_string(),
return_type,
signature: Signature::one_of(
vec![TypeSignature::VariadicAny, TypeSignature::NullAry],
vec![TypeSignature::VariadicAny, TypeSignature::Nullary],
Volatility::Volatile,
),
}
Expand Down Expand Up @@ -159,7 +159,7 @@ impl ByPassWindowFunction {
name: name.to_string(),
return_type,
signature: Signature::one_of(
vec![TypeSignature::VariadicAny, TypeSignature::NullAry],
vec![TypeSignature::VariadicAny, TypeSignature::Nullary],
Volatility::Volatile,
),
}
Expand Down
8 changes: 4 additions & 4 deletions wren-core/core/src/mdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use datafusion::execution::context::SessionState;
use datafusion::logical_expr::{AggregateUDF, ScalarUDF, WindowUDF};
use datafusion::prelude::SessionContext;
use datafusion::sql::parser::DFParser;
use datafusion::sql::sqlparser::ast::{Expr, Ident};
use datafusion::sql::sqlparser::ast::{Expr, ExprWithAlias, Ident};
use datafusion::sql::sqlparser::dialect::dialect_from_str;
use datafusion::sql::unparser::Unparser;
use datafusion::sql::TableReference;
Expand Down Expand Up @@ -214,11 +214,11 @@ impl WrenMDL {
}

if let Some(expression) = column.expression() {
let expr = WrenMDL::sql_to_expr(expression)?;
let ExprWithAlias { expr, alias } = WrenMDL::sql_to_expr(expression)?;
// if the column is a simple column reference, we can infer the column name
if let Some(name) = Self::collect_one_column(&expr) {
Ok(Some(Field::new(
name.value.clone(),
alias.map(|a| a.value).unwrap_or_else(|| name.value.clone()),
map_data_type(&column.r#type)?,
column.not_null,
)))
Expand All @@ -230,7 +230,7 @@ impl WrenMDL {
}
}

fn sql_to_expr(sql: &str) -> Result<Expr> {
fn sql_to_expr(sql: &str) -> Result<ExprWithAlias> {
let dialect = dialect_from_str("generic").ok_or_else(|| {
internal_datafusion_err!("Failed to create dialect from generic")
})?;
Expand Down
Loading