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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ __pycache__/
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
.python-version
venv
62 changes: 36 additions & 26 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ default = ["mimalloc"]
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync"] }
rand = "0.7"
pyo3 = { version = "~0.16.5", features = ["extension-module", "abi3", "abi3-py37"] }
datafusion = { version = "^10.0.0", features = ["pyarrow"] }
datafusion-expr = { version = "^10.0.0" }
datafusion-common = { version = "^10.0.0", features = ["pyarrow"] }
datafusion = { version = "^11.0.0", features = ["pyarrow"] }
datafusion-expr = { version = "^11.0.0" }
datafusion-common = { version = "^11.0.0", features = ["pyarrow"] }
uuid = { version = "0.8", features = ["v4"] }
mimalloc = { version = "*", optional = true, default-features = false }
async-trait = "0.1"
Expand Down
18 changes: 11 additions & 7 deletions src/udaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ use pyo3::{prelude::*, types::PyTuple};
use datafusion::arrow::array::ArrayRef;
use datafusion::arrow::datatypes::DataType;
use datafusion::arrow::pyarrow::PyArrowConvert;
use datafusion::common::ScalarValue;
use datafusion::error::{DataFusionError, Result};
use datafusion::logical_expr::{
Accumulator, AccumulatorFunctionImplementation, AggregateState, AggregateUDF,
};
use datafusion::logical_plan;
use datafusion_common::ScalarValue;
use datafusion_expr::Accumulator;
use datafusion_expr::AccumulatorFunctionImplementation;
use datafusion_expr::AggregateUDF;

use crate::expression::PyExpr;
use crate::utils::parse_volatility;
Expand All @@ -44,9 +44,13 @@ impl RustAccumulator {
}

impl Accumulator for RustAccumulator {
fn state(&self) -> Result<Vec<ScalarValue>> {
Python::with_gil(|py| self.accum.as_ref(py).call_method0("state")?.extract())
.map_err(|e| DataFusionError::Execution(format!("{}", e)))
fn state(&self) -> Result<Vec<AggregateState>> {
let py_result: PyResult<Vec<ScalarValue>> =
Python::with_gil(|py| self.accum.as_ref(py).call_method0("state")?.extract());
match py_result {
Ok(r) => Ok(r.into_iter().map(AggregateState::Scalar).collect()),
Err(e) => Err(DataFusionError::Execution(format!("{}", e))),
}
}

fn evaluate(&self) -> Result<ScalarValue> {
Expand Down