Skip to content

Commit 0de7d81

Browse files
authored
Minor: Remove datafusion-core dev dependency from datafusion-sql (#4589)
1 parent b3d1cb1 commit 0de7d81

3 files changed

Lines changed: 60 additions & 66 deletions

File tree

datafusion/core/tests/sql/udf.rs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use datafusion::{
2121
execution::registry::FunctionRegistry,
2222
physical_plan::{expressions::AvgAccumulator, functions::make_scalar_function},
2323
};
24-
use datafusion_common::cast::as_int32_array;
25-
use datafusion_expr::{create_udaf, LogicalPlanBuilder};
24+
use datafusion_common::{cast::as_int32_array, ScalarValue};
25+
use datafusion_expr::{create_udaf, Accumulator, AggregateState, LogicalPlanBuilder};
2626

2727
/// test that casting happens on udfs.
2828
/// c11 is f32, but `custom_sqrt` requires f64. Casting happens but the logical plan and
@@ -168,3 +168,61 @@ async fn simple_udaf() -> Result<()> {
168168

169169
Ok(())
170170
}
171+
172+
#[test]
173+
fn udaf_as_window_func() -> Result<()> {
174+
#[derive(Debug)]
175+
struct MyAccumulator;
176+
177+
impl Accumulator for MyAccumulator {
178+
fn state(&self) -> Result<Vec<AggregateState>> {
179+
unimplemented!()
180+
}
181+
182+
fn update_batch(&mut self, _: &[ArrayRef]) -> Result<()> {
183+
unimplemented!()
184+
}
185+
186+
fn merge_batch(&mut self, _: &[ArrayRef]) -> Result<()> {
187+
unimplemented!()
188+
}
189+
190+
fn evaluate(&self) -> Result<ScalarValue> {
191+
unimplemented!()
192+
}
193+
194+
fn size(&self) -> usize {
195+
unimplemented!()
196+
}
197+
}
198+
199+
let my_acc = create_udaf(
200+
"my_acc",
201+
DataType::Int32,
202+
Arc::new(DataType::Int32),
203+
Volatility::Immutable,
204+
Arc::new(|_| Ok(Box::new(MyAccumulator))),
205+
Arc::new(vec![DataType::Int32]),
206+
);
207+
208+
let mut context = SessionContext::new();
209+
context.register_table(
210+
"my_table",
211+
Arc::new(datafusion::datasource::empty::EmptyTable::new(Arc::new(
212+
Schema::new(vec![
213+
Field::new("a", DataType::UInt32, false),
214+
Field::new("b", DataType::Int32, false),
215+
]),
216+
))),
217+
)?;
218+
context.register_udaf(my_acc);
219+
220+
let sql = "SELECT a, MY_ACC(b) OVER(PARTITION BY a) FROM my_table";
221+
let expected = r#"Projection: my_table.a, AggregateUDF { name: "my_acc", signature: Signature { type_signature: Exact([Int32]), volatility: Immutable }, fun: "<FUNC>" }(my_table.b) PARTITION BY [my_table.a] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
222+
WindowAggr: windowExpr=[[AggregateUDF { name: "my_acc", signature: Signature { type_signature: Exact([Int32]), volatility: Immutable }, fun: "<FUNC>" }(my_table.b) PARTITION BY [my_table.a] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING]]
223+
TableScan: my_table"#;
224+
225+
let plan = context.create_logical_plan(sql)?;
226+
assert_eq!(format!("{:?}", plan), expected);
227+
Ok(())
228+
}

datafusion/sql/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,3 @@ datafusion-common = { path = "../common", version = "15.0.0" }
4242
datafusion-expr = { path = "../expr", version = "15.0.0" }
4343
log = "^0.4"
4444
sqlparser = "0.28"
45-
46-
[dev-dependencies]
47-
datafusion = { path = "../core" }

datafusion/sql/src/planner.rs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,14 +3301,11 @@ fn ensure_any_column_reference_is_unambiguous(
33013301

33023302
#[cfg(test)]
33033303
mod tests {
3304-
use datafusion::arrow::array::ArrayRef;
3305-
use datafusion::prelude::SessionContext;
33063304
use std::any::Any;
33073305

33083306
use sqlparser::dialect::{Dialect, GenericDialect, HiveDialect, MySqlDialect};
33093307

33103308
use datafusion_common::assert_contains;
3311-
use datafusion_expr::{create_udaf, Accumulator, AggregateState, Volatility};
33123309

33133310
use super::*;
33143311

@@ -5330,64 +5327,6 @@ mod tests {
53305327
quick_test(sql, expected);
53315328
}
53325329

5333-
#[test]
5334-
fn udaf_as_window_func() -> Result<()> {
5335-
#[derive(Debug)]
5336-
struct MyAccumulator;
5337-
5338-
impl Accumulator for MyAccumulator {
5339-
fn state(&self) -> Result<Vec<AggregateState>> {
5340-
unimplemented!()
5341-
}
5342-
5343-
fn update_batch(&mut self, _: &[ArrayRef]) -> Result<()> {
5344-
unimplemented!()
5345-
}
5346-
5347-
fn merge_batch(&mut self, _: &[ArrayRef]) -> Result<()> {
5348-
unimplemented!()
5349-
}
5350-
5351-
fn evaluate(&self) -> Result<ScalarValue> {
5352-
unimplemented!()
5353-
}
5354-
5355-
fn size(&self) -> usize {
5356-
unimplemented!()
5357-
}
5358-
}
5359-
5360-
let my_acc = create_udaf(
5361-
"my_acc",
5362-
DataType::Int32,
5363-
Arc::new(DataType::Int32),
5364-
Volatility::Immutable,
5365-
Arc::new(|_| Ok(Box::new(MyAccumulator))),
5366-
Arc::new(vec![DataType::Int32]),
5367-
);
5368-
5369-
let mut context = SessionContext::new();
5370-
context.register_table(
5371-
TableReference::Bare { table: "my_table" },
5372-
Arc::new(datafusion::datasource::empty::EmptyTable::new(Arc::new(
5373-
Schema::new(vec![
5374-
Field::new("a", DataType::UInt32, false),
5375-
Field::new("b", DataType::Int32, false),
5376-
]),
5377-
))),
5378-
)?;
5379-
context.register_udaf(my_acc);
5380-
5381-
let sql = "SELECT a, MY_ACC(b) OVER(PARTITION BY a) FROM my_table";
5382-
let expected = r#"Projection: my_table.a, AggregateUDF { name: "my_acc", signature: Signature { type_signature: Exact([Int32]), volatility: Immutable }, fun: "<FUNC>" }(my_table.b) PARTITION BY [my_table.a] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
5383-
WindowAggr: windowExpr=[[AggregateUDF { name: "my_acc", signature: Signature { type_signature: Exact([Int32]), volatility: Immutable }, fun: "<FUNC>" }(my_table.b) PARTITION BY [my_table.a] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING]]
5384-
TableScan: my_table"#;
5385-
5386-
let plan = context.create_logical_plan(sql)?;
5387-
assert_eq!(format!("{:?}", plan), expected);
5388-
Ok(())
5389-
}
5390-
53915330
#[test]
53925331
fn select_typed_date_string() {
53935332
let sql = "SELECT date '2020-12-10' AS date";

0 commit comments

Comments
 (0)