Apache DataFusion SQL Query Engine
Minor: Remove datafusion-core dev dependency from datafusion-sql (#4589)
Andrew Lamb0de7d819f5f5
diff --git a/datafusion/core/tests/sql/udf.rs b/datafusion/core/tests/sql/udf.rsindex f554b9424f..37a869f933 100644--- a/datafusion/core/tests/sql/udf.rs+++ b/datafusion/core/tests/sql/udf.rs@@ -21,8 +21,8 @@ use datafusion::{execution::registry::FunctionRegistry,physical_plan::{expressions::AvgAccumulator, functions::make_scalar_function},};-use datafusion_common::cast::as_int32_array;-use datafusion_expr::{create_udaf, LogicalPlanBuilder};+use datafusion_common::{cast::as_int32_array, ScalarValue};+use datafusion_expr::{create_udaf, Accumulator, AggregateState, LogicalPlanBuilder};/// test that casting happens on udfs./// c11 is f32, but `custom_sqrt` requires f64. Casting happens but the logical plan and@@ -168,3 +168,61 @@ async fn simple_udaf() -> Result<()> {Ok(())}++#[test]+fn udaf_as_window_func() -> Result<()> {+ #[derive(Debug)]+ struct MyAccumulator;++ impl Accumulator for MyAccumulator {+ fn state(&self) -> Result<Vec<AggregateState>> {+ unimplemented!()+ }++ fn update_batch(&mut self, _: &[ArrayRef]) -> Result<()> {+ unimplemented!()+ }++ fn merge_batch(&mut self, _: &[ArrayRef]) -> Result<()> {+ unimplemented!()+ }++ fn evaluate(&self) -> Result<ScalarValue> {+ unimplemented!()+ }++ fn size(&self) -> usize {+ unimplemented!()+ }+ }++ let my_acc = create_udaf(+ "my_acc",+ DataType::Int32,+ Arc::new(DataType::Int32),+ Volatility::Immutable,+ Arc::new(|_| Ok(Box::new(MyAccumulator))),+ Arc::new(vec![DataType::Int32]),+ );++ let mut context = SessionContext::new();+ context.register_table(+ "my_table",+ Arc::new(datafusion::datasource::empty::EmptyTable::new(Arc::new(+ Schema::new(vec![+ Field::new("a", DataType::UInt32, false),+ Field::new("b", DataType::Int32, false),+ ]),+ ))),+ )?;+ context.register_udaf(my_acc);++ let sql = "SELECT a, MY_ACC(b) OVER(PARTITION BY a) FROM my_table";+ 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+ 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]]+ TableScan: my_table"#;++ let plan = context.create_logical_plan(sql)?;+ assert_eq!(format!("{:?}", plan), expected);+ Ok(())+}diff --git a/datafusion/sql/Cargo.toml b/datafusion/sql/Cargo.tomlindex bc6add89aa..dd19e6affb 100644--- a/datafusion/sql/Cargo.toml+++ b/datafusion/sql/Cargo.toml@@ -42,6 +42,3 @@ datafusion-common = { path = "../common", version = "15.0.0" }datafusion-expr = { path = "../expr", version = "15.0.0" }log = "^0.4"sqlparser = "0.28"--[dev-dependencies]-datafusion = { path = "../core" }diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rsindex a04a71d4e6..86057aa622 100644--- a/datafusion/sql/src/planner.rs+++ b/datafusion/sql/src/planner.rs@@ -3301,14 +3301,11 @@ fn ensure_any_column_reference_is_unambiguous(#[cfg(test)]mod tests {- use datafusion::arrow::array::ArrayRef;- use datafusion::prelude::SessionContext;use std::any::Any;use sqlparser::dialect::{Dialect, GenericDialect, HiveDialect, MySqlDialect};use datafusion_common::assert_contains;- use datafusion_expr::{create_udaf, Accumulator, AggregateState, Volatility};use super::*;@@ -5330,64 +5327,6 @@ mod tests {quick_test(sql, expected);}- #[test]- fn udaf_as_window_func() -> Result<()> {- #[derive(Debug)]- struct MyAccumulator;-- impl Accumulator for MyAccumulator {- fn state(&self) -> Result<Vec<AggregateState>> {- unimplemented!()- }-- fn update_batch(&mut self, _: &[ArrayRef]) -> Result<()> {- unimplemented!()- }-- fn merge_batch(&mut self, _: &[ArrayRef]) -> Result<()> {- unimplemented!()- }-- fn evaluate(&self) -> Result<ScalarValue> {- unimplemented!()- }-- fn size(&self) -> usize {- unimplemented!()- }- }-- let my_acc = create_udaf(- "my_acc",- DataType::Int32,- Arc::new(DataType::Int32),- Volatility::Immutable,- Arc::new(|_| Ok(Box::new(MyAccumulator))),- Arc::new(vec![DataType::Int32]),- );-- let mut context = SessionContext::new();- context.register_table(- TableReference::Bare { table: "my_table" },- Arc::new(datafusion::datasource::empty::EmptyTable::new(Arc::new(- Schema::new(vec![- Field::new("a", DataType::UInt32, false),- Field::new("b", DataType::Int32, false),- ]),- ))),- )?;- context.register_udaf(my_acc);-- let sql = "SELECT a, MY_ACC(b) OVER(PARTITION BY a) FROM my_table";- 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- 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]]- TableScan: my_table"#;-- let plan = context.create_logical_plan(sql)?;- assert_eq!(format!("{:?}", plan), expected);- Ok(())- }-#[test]fn select_typed_date_string() {let sql = "SELECT date '2020-12-10' AS date";