Skip to content

Commit

Permalink
migrate AggregateExt to ExprFunctionExt
Browse files Browse the repository at this point in the history
Also removed `sqlparser` dependency since it's re-exported upstream.

Ref: apache/datafusion#11550
  • Loading branch information
Michael-J-Ward committed Aug 20, 2024
1 parent fee0b9c commit 6ed0c03
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
20 changes: 5 additions & 15 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ parking_lot = "0.12"
regex-syntax = "0.8"
syn = "2.0.68"
url = "2"
sqlparser = "0.47.0"

[build-dependencies]
pyo3-build-config = "0.21"
Expand Down
18 changes: 10 additions & 8 deletions src/common/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use datafusion::arrow::array::Array;
use datafusion::arrow::datatypes::{DataType, IntervalUnit, TimeUnit};
use datafusion_common::{DataFusionError, ScalarValue};
use datafusion_expr::sqlparser::ast::NullTreatment as DFNullTreatment;
use pyo3::{exceptions::PyValueError, prelude::*};

use crate::errors::py_datafusion_err;
Expand Down Expand Up @@ -775,20 +776,21 @@ pub enum NullTreatment {
RESPECT_NULLS,
}

impl From<NullTreatment> for sqlparser::ast::NullTreatment {
fn from(null_treatment: NullTreatment) -> sqlparser::ast::NullTreatment {

impl From<NullTreatment> for DFNullTreatment {
fn from(null_treatment: NullTreatment) -> DFNullTreatment {
match null_treatment {
NullTreatment::IGNORE_NULLS => sqlparser::ast::NullTreatment::IgnoreNulls,
NullTreatment::RESPECT_NULLS => sqlparser::ast::NullTreatment::RespectNulls,
NullTreatment::IGNORE_NULLS => DFNullTreatment::IgnoreNulls,
NullTreatment::RESPECT_NULLS => DFNullTreatment::RespectNulls,
}
}
}

impl From<sqlparser::ast::NullTreatment> for NullTreatment {
fn from(null_treatment: sqlparser::ast::NullTreatment) -> NullTreatment {
impl From<DFNullTreatment> for NullTreatment {
fn from(null_treatment: DFNullTreatment) -> NullTreatment {
match null_treatment {
sqlparser::ast::NullTreatment::IgnoreNulls => NullTreatment::IGNORE_NULLS,
sqlparser::ast::NullTreatment::RespectNulls => NullTreatment::RESPECT_NULLS,
DFNullTreatment::IgnoreNulls => NullTreatment::IGNORE_NULLS,
DFNullTreatment::RespectNulls => NullTreatment::RESPECT_NULLS,
}
}
}
12 changes: 5 additions & 7 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// under the License.

use datafusion::functions_aggregate::all_default_aggregate_functions;
use datafusion_expr::ExprFunctionExt as AggregateExt;
use datafusion_expr::ExprFunctionExt;
use pyo3::{prelude::*, wrap_pyfunction};

use crate::common::data_type::NullTreatment;
Expand All @@ -30,6 +30,7 @@ use datafusion::functions;
use datafusion::functions_aggregate;
use datafusion_common::{Column, ScalarValue, TableReference};
use datafusion_expr::expr::Alias;
use datafusion_expr::sqlparser::ast::NullTreatment as DFNullTreatment;
use datafusion_expr::{
expr::{find_df_window_func, AggregateFunction, Sort, WindowFunction},
lit, Expr, WindowFunctionDefinition,
Expand Down Expand Up @@ -340,9 +341,8 @@ pub fn first_value(
builder = builder.filter(filter.expr);
}

if let Some(null_treatment) = null_treatment {
builder = builder.null_treatment(null_treatment.into())
}
// would be nice if all the options builder methods accepted Option<T> ...
builder = builder.null_treatment(null_treatment.map(DFNullTreatment::from));

Ok(builder.build()?.into())
}
Expand Down Expand Up @@ -371,9 +371,7 @@ pub fn last_value(
builder = builder.filter(filter.expr);
}

if let Some(null_treatment) = null_treatment {
builder = builder.null_treatment(null_treatment.into())
}
builder = builder.null_treatment(null_treatment.map(DFNullTreatment::from));

Ok(builder.build()?.into())
}
Expand Down

0 comments on commit 6ed0c03

Please sign in to comment.