Apache DataFusion SQL Query Engine
Minor: move `Column` related tests and rename `column.rs` (#11573)
Jonah Gao4417a9404f99
diff --git a/datafusion/physical-expr-common/src/expressions/column.rs b/datafusion/physical-expr-common/src/expressions/column.rsindex d972d35b9e..5397599ea2 100644--- a/datafusion/physical-expr-common/src/expressions/column.rs+++ b/datafusion/physical-expr-common/src/expressions/column.rs@@ -135,3 +135,49 @@ impl Column {pub fn col(name: &str, schema: &Schema) -> Result<Arc<dyn PhysicalExpr>> {Ok(Arc::new(Column::new_with_schema(name, schema)?))}++#[cfg(test)]+mod test {+ use super::Column;+ use crate::physical_expr::PhysicalExpr;++ use arrow::array::StringArray;+ use arrow::datatypes::{DataType, Field, Schema};+ use arrow::record_batch::RecordBatch;+ use datafusion_common::Result;++ use std::sync::Arc;++ #[test]+ fn out_of_bounds_data_type() {+ let schema = Schema::new(vec![Field::new("foo", DataType::Utf8, true)]);+ let col = Column::new("id", 9);+ let error = col.data_type(&schema).expect_err("error").strip_backtrace();+ assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \+ but input schema only has 1 columns: [\"foo\"].\nThis was likely caused by a bug in \+ DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error))+ }++ #[test]+ fn out_of_bounds_nullable() {+ let schema = Schema::new(vec![Field::new("foo", DataType::Utf8, true)]);+ let col = Column::new("id", 9);+ let error = col.nullable(&schema).expect_err("error").strip_backtrace();+ assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \+ but input schema only has 1 columns: [\"foo\"].\nThis was likely caused by a bug in \+ DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error))+ }++ #[test]+ fn out_of_bounds_evaluate() -> Result<()> {+ let schema = Schema::new(vec![Field::new("foo", DataType::Utf8, true)]);+ let data: StringArray = vec!["data"].into();+ let batch = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(data)])?;+ let col = Column::new("id", 9);+ let error = col.evaluate(&batch).expect_err("error").strip_backtrace();+ assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \+ but input schema only has 1 columns: [\"foo\"].\nThis was likely caused by a bug in \+ DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error));+ Ok(())+ }+}diff --git a/datafusion/physical-expr/src/expressions/mod.rs b/datafusion/physical-expr/src/expressions/mod.rsindex fa80bc9873..5a2bcb63b1 100644--- a/datafusion/physical-expr/src/expressions/mod.rs+++ b/datafusion/physical-expr/src/expressions/mod.rs@@ -20,7 +20,6 @@#[macro_use]mod binary;mod case;-mod column;mod in_list;mod is_not_null;mod is_null;@@ -29,6 +28,7 @@ mod negative;mod no_op;mod not;mod try_cast;+mod unknown_column;/// Module with some convenient methods used in expression buildingpub mod helpers {@@ -48,7 +48,6 @@ pub use crate::PhysicalSortExpr;pub use binary::{binary, BinaryExpr};pub use case::{case, CaseExpr};-pub use column::UnKnownColumn;pub use datafusion_expr::utils::format_state_name;pub use datafusion_physical_expr_common::expressions::column::{col, Column};pub use datafusion_physical_expr_common::expressions::literal::{lit, Literal};@@ -61,3 +60,4 @@ pub use negative::{negative, NegativeExpr};pub use no_op::NoOp;pub use not::{not, NotExpr};pub use try_cast::{try_cast, TryCastExpr};+pub use unknown_column::UnKnownColumn;diff --git a/datafusion/physical-expr/src/expressions/column.rs b/datafusion/physical-expr/src/expressions/unknown_column.rssimilarity index 56%rename from datafusion/physical-expr/src/expressions/column.rsrename to datafusion/physical-expr/src/expressions/unknown_column.rsindex ab43201ceb..cb7221e7fa 100644--- a/datafusion/physical-expr/src/expressions/column.rs+++ b/datafusion/physical-expr/src/expressions/unknown_column.rs@@ -15,7 +15,7 @@// specific language governing permissions and limitations// under the License.-//! Column expression+//! UnKnownColumn expressionuse std::any::Any;use std::hash::{Hash, Hasher};@@ -100,49 +100,3 @@ impl PartialEq<dyn Any> for UnKnownColumn {false}}--#[cfg(test)]-mod test {- use crate::expressions::Column;- use crate::PhysicalExpr;-- use arrow::array::StringArray;- use arrow::datatypes::{DataType, Field, Schema};- use arrow::record_batch::RecordBatch;- use datafusion_common::Result;-- use std::sync::Arc;-- #[test]- fn out_of_bounds_data_type() {- let schema = Schema::new(vec![Field::new("foo", DataType::Utf8, true)]);- let col = Column::new("id", 9);- let error = col.data_type(&schema).expect_err("error").strip_backtrace();- assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \- but input schema only has 1 columns: [\"foo\"].\nThis was likely caused by a bug in \- DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error))- }-- #[test]- fn out_of_bounds_nullable() {- let schema = Schema::new(vec![Field::new("foo", DataType::Utf8, true)]);- let col = Column::new("id", 9);- let error = col.nullable(&schema).expect_err("error").strip_backtrace();- assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \- but input schema only has 1 columns: [\"foo\"].\nThis was likely caused by a bug in \- DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error))- }-- #[test]- fn out_of_bounds_evaluate() -> Result<()> {- let schema = Schema::new(vec![Field::new("foo", DataType::Utf8, true)]);- let data: StringArray = vec!["data"].into();- let batch = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(data)])?;- let col = Column::new("id", 9);- let error = col.evaluate(&batch).expect_err("error").strip_backtrace();- assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \- but input schema only has 1 columns: [\"foo\"].\nThis was likely caused by a bug in \- DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error));- Ok(())- }-}