Skip to content

Commit

Permalink
DataFusion 41 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Aug 12, 2024
1 parent 84fad1e commit 8cd5187
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 35 deletions.
49 changes: 19 additions & 30 deletions vegafusion-sql/src/compile/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use crate::compile::scalar::ToSqlScalar;
use arrow::datatypes::DataType;
use datafusion_common::{DFSchema, ScalarValue};
use sqlparser::ast::{
BinaryOperator as SqlBinaryOperator, CastKind, Expr as SqlExpr, Function as SqlFunction,
FunctionArg as SqlFunctionArg, FunctionArgumentList, FunctionArguments, Ident,
ObjectName as SqlObjectName, UnaryOperator as SqlUnaryOperator, WindowFrame as SqlWindowFrame,
WindowFrameBound as SqlWindowBound, WindowFrameUnits as SqlWindowFrameUnits,
WindowSpec as SqlWindowSpec, WindowType,
BinaryOperator as SqlBinaryOperator, CastKind, DuplicateTreatment, Expr as SqlExpr,
Function as SqlFunction, FunctionArg as SqlFunctionArg, FunctionArgumentList,
FunctionArguments, Ident, ObjectName as SqlObjectName, UnaryOperator as SqlUnaryOperator,
WindowFrame as SqlWindowFrame, WindowFrameBound as SqlWindowBound,
WindowFrameUnits as SqlWindowFrameUnits, WindowSpec as SqlWindowSpec, WindowType,
};

use datafusion_expr::expr::{BinaryExpr, Case, Cast, Sort};
Expand Down Expand Up @@ -367,11 +367,7 @@ impl ToSqlExpr for Expr {
null_treatment: None,
over: None,
within_group: vec![],
parameters: FunctionArguments::List(FunctionArgumentList {
args: vec![],
duplicate_treatment: None,
clauses: vec![],
}),
parameters: FunctionArguments::None,
}));
}
UnorderedRowNumberMode::OrderByConstant => {
Expand Down Expand Up @@ -463,11 +459,7 @@ impl ToSqlExpr for Expr {
null_treatment: None,
over: Some(over),
within_group: vec![],
parameters: FunctionArguments::List(FunctionArgumentList {
args: vec![],
duplicate_treatment: None,
clauses: vec![],
}),
parameters: FunctionArguments::None,
};

Ok(SqlExpr::Function(sql_fun))
Expand Down Expand Up @@ -570,11 +562,7 @@ fn translate_scalar_function(
null_treatment: None,
over: None,
within_group: vec![],
parameters: FunctionArguments::List(FunctionArgumentList {
args: vec![],
duplicate_treatment: None,
clauses: vec![],
}),
parameters: FunctionArguments::None,
}))
} else if let Some(transformer) = dialect.scalar_transformers.get(fun_name) {
// Supported through AST transformation
Expand All @@ -590,7 +578,7 @@ fn translate_scalar_function(
fn translate_aggregate_function(
fun_name: &str,
args: &[Expr],
_distinct: bool, // Where should distinct go now?
distinct: bool,
dialect: &Dialect,
schema: &DFSchema,
) -> Result<SqlExpr> {
Expand All @@ -600,24 +588,25 @@ fn translate_aggregate_function(
quote_style: None,
};
let args = translate_function_args(args, dialect, schema)?;

Ok(SqlExpr::Function(SqlFunction {
let fn_expr = SqlExpr::Function(SqlFunction {
name: SqlObjectName(vec![ident]),
args: FunctionArguments::List(FunctionArgumentList {
args,
duplicate_treatment: None,
duplicate_treatment: if distinct {
Some(DuplicateTreatment::Distinct)
} else {
None
},
clauses: vec![],
}),
filter: None,
null_treatment: None,
over: None,
within_group: vec![],
parameters: FunctionArguments::List(FunctionArgumentList {
args: vec![],
duplicate_treatment: None,
clauses: vec![],
}),
}))
parameters: FunctionArguments::None,
});
println!("{}", fn_expr.to_string());
Ok(fn_expr)
} else if let Some(transformer) = dialect.aggregate_transformers.get(fun_name) {
// Supported through AST transformation
transformer.transform(args, dialect, schema)
Expand Down
6 changes: 1 addition & 5 deletions vegafusion-sql/src/compile/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,7 @@ impl ToSqlScalar for ScalarValue {
null_treatment: None,
over: None,
within_group: vec![],
parameters: FunctionArguments::List(FunctionArgumentList {
args: vec![],
duplicate_treatment: None,
clauses: vec![],
}),
parameters: FunctionArguments::None,
}))
}
ScalarValue::Date32(v) => date32_to_date(v, dialect),
Expand Down
1 change: 1 addition & 0 deletions vegafusion-sql/src/connection/datafusion_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ pub fn make_datafusion_context() -> SessionContext {
let session_state = SessionStateBuilder::new()
.with_config(config)
.with_runtime_env(runtime)
.with_default_features()
.build();

let ctx = SessionContext::new_with_state(session_state);
Expand Down

0 comments on commit 8cd5187

Please sign in to comment.