Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: move Column related tests and rename column.rs #11573

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 46 additions & 0 deletions datafusion/physical-expr-common/src/expressions/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
46 changes: 0 additions & 46 deletions datafusion/physical-expr/src/expressions/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,49 +100,3 @@ impl PartialEq<dyn Any> for UnKnownColumn {
false
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like datafusion/physical-expr/src/expressions/column.rs could also be renamed to datafusion/physical-expr/src/expressions/unknown_column.rs or datafusion/physical-expr/src/expressions/unknown.rs to better match its contents

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed it to unknown_column.rs in f4407ac

#[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(())
}
}