Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
comphead committed Sep 2, 2023
1 parent 7bc2954 commit c7a51b6
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 150 deletions.
2 changes: 1 addition & 1 deletion datafusion/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl Display for DataFusionError {
write!(f, "This feature is not implemented: {desc}")
}
DataFusionError::Internal(ref desc) => {
write!(f, "Internal error: {desc}. This was likely caused by a bug in DataFusion's \
write!(f, "Internal error: {desc}.\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")
}
DataFusionError::Plan(ref desc) => {
Expand Down
22 changes: 10 additions & 12 deletions datafusion/core/src/datasource/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,11 @@ mod tests {
],
)?;

match MemTable::try_new(schema2, vec![vec![batch]]) {
Err(DataFusionError::Plan(e)) => {
assert_eq!("\"Mismatch between schema and batches\"", format!("{e:?}"))
}
_ => panic!("MemTable::new should have failed due to schema mismatch"),
}
let e = MemTable::try_new(schema2, vec![vec![batch]]).unwrap_err();
assert_eq!(
"Error during planning: Mismatch between schema and batches",
e.strip_backtrace()
);

Ok(())
}
Expand All @@ -466,12 +465,11 @@ mod tests {
],
)?;

match MemTable::try_new(schema2, vec![vec![batch]]) {
Err(DataFusionError::Plan(e)) => {
assert_eq!("\"Mismatch between schema and batches\"", format!("{e:?}"))
}
_ => panic!("MemTable::new should have failed due to schema mismatch"),
}
let e = MemTable::try_new(schema2, vec![vec![batch]]).unwrap_err();
assert_eq!(
"Error during planning: Mismatch between schema and batches",
e.strip_backtrace()
);

Ok(())
}
Expand Down
25 changes: 10 additions & 15 deletions datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2222,14 +2222,11 @@ digraph {
..Default::default()
};
let plan = test_plan();
let res = plan.visit(&mut visitor);

if let Err(DataFusionError::NotImplemented(e)) = res {
assert_eq!("Error in pre_visit", e);
} else {
panic!("Expected an error");
}

let res = plan.visit(&mut visitor).unwrap_err();
assert_eq!(
"This feature is not implemented: Error in pre_visit",
res.strip_backtrace()
);
assert_eq!(
visitor.inner.strings,
vec!["pre_visit Projection", "pre_visit Filter"]
Expand All @@ -2243,13 +2240,11 @@ digraph {
..Default::default()
};
let plan = test_plan();
let res = plan.visit(&mut visitor);
if let Err(DataFusionError::NotImplemented(e)) = res {
assert_eq!("Error in post_visit", e);
} else {
panic!("Expected an error");
}

let res = plan.visit(&mut visitor).unwrap_err();
assert_eq!(
"This feature is not implemented: Error in post_visit",
res.strip_backtrace()
);
assert_eq!(
visitor.inner.strings,
vec![
Expand Down
14 changes: 4 additions & 10 deletions datafusion/expr/src/type_coercion/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,8 @@ fn null_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
mod tests {
use arrow::datatypes::DataType;

use datafusion_common::assert_contains;
use datafusion_common::Result;
use datafusion_common::{assert_contains, internal_err, DataFusionError};

use crate::Operator;

Expand All @@ -791,15 +791,9 @@ mod tests {
let result_type =
get_input_types(&DataType::Float32, &Operator::Plus, &DataType::Utf8);

if let Err(DataFusionError::Plan(e)) = result_type {
assert_eq!(
e,
"Cannot coerce arithmetic expression Float32 + Utf8 to valid types"
);
Ok(())
} else {
internal_err!("Coercion should have returned an DataFusionError::Internal")
}
let e = result_type.unwrap_err();
assert_eq!(e.strip_backtrace(), "Error during planning: Cannot coerce arithmetic expression Float32 + Utf8 to valid types");
Ok(())
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,8 @@ mod test {
.err()
.unwrap();
assert_eq!(
r#"Context("type_coercion", Plan("Coercion from [Utf8] to the signature Uniform(1, [Int32]) failed."))"#,
&format!("{err:?}")
"type_coercion\ncaused by\nError during planning: Coercion from [Utf8] to the signature Uniform(1, [Int32]) failed.",
err.strip_backtrace()
);
Ok(())
}
Expand Down Expand Up @@ -944,8 +944,8 @@ mod test {
.err()
.unwrap();
assert_eq!(
r#"Context("type_coercion", Plan("Coercion from [Utf8] to the signature Uniform(1, [Float64]) failed."))"#,
&format!("{err:?}")
"type_coercion\ncaused by\nError during planning: Coercion from [Utf8] to the signature Uniform(1, [Float64]) failed.",
err.strip_backtrace()
);
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions datafusion/optimizer/src/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ mod tests {
DFField { qualifier: Some(Bare { table: \"test\" }), field: Field { name: \"a\", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} } }, \
DFField { qualifier: Some(Bare { table: \"test\" }), field: Field { name: \"b\", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} } }, \
DFField { qualifier: Some(Bare { table: \"test\" }), field: Field { name: \"c\", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} } }], \
metadata: {}, functional_dependencies: FunctionalDependencies { deps: [] } }. \
This was likely caused by a bug in DataFusion's code \
metadata: {}, functional_dependencies: FunctionalDependencies { deps: [] } }.\
\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",
err.strip_backtrace()
);
Expand Down
10 changes: 5 additions & 5 deletions datafusion/physical-expr/src/aggregate/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,14 +1148,14 @@ mod tests {

let right = ScalarValue::Decimal128(Some(124), 10, 3);
let result = max(&left, &right);
let expect = DataFusionError::Internal(format!(
let err_msg = format!(
"MIN/MAX is not expected to receive scalars of incompatible types {:?}",
(Decimal128(Some(123), 10, 2), Decimal128(Some(124), 10, 3))
));
assert_eq!(
expect.strip_backtrace(),
result.unwrap_err().strip_backtrace()
);
let expect = DataFusionError::Internal(err_msg);
assert!(expect
.strip_backtrace()
.starts_with(&result.unwrap_err().strip_backtrace()));

// max batch
let array: ArrayRef = Arc::new(
Expand Down
15 changes: 6 additions & 9 deletions datafusion/physical-expr/src/expressions/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,19 @@ mod test {
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_eq!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
but input schema only has 1 columns: [\"foo\"]. This was likely caused by a bug in \
DataFusion's code and we would welcome that you file an bug report in our issue tracker",
error)
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_eq!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
but input schema only has 1 columns: [\"foo\"]. This was likely caused by a bug in \
DataFusion's code and we would welcome that you file an bug report in our issue tracker",
error)
DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error))
}

#[test]
Expand All @@ -251,10 +249,9 @@ mod test {
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_eq!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
but input schema only has 1 columns: [\"foo\"]. This was likely caused by a bug in \
DataFusion's code and we would welcome that you file an bug report in our issue tracker",
error);
DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error));
Ok(())
}
}
2 changes: 1 addition & 1 deletion datafusion/physical-expr/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ mod tests {
match expr.evaluate(&batch) {
Ok(_) => assert!(false, "expected error"),
Err(error) => {
assert_eq!(error.to_string(), expected_error.to_string());
assert!(expected_error.strip_backtrace().starts_with(&error.strip_backtrace()));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions datafusion/sql/src/expr/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ mod test {
let expected = "Internal error: Incorrect number of identifiers: 0. \
This was likely caused by a bug in DataFusion's code and we would \
welcome that you file an bug report in our issue tracker";
assert_eq!(err.strip_backtrace(), expected);
assert!(expected.starts_with(&err.strip_backtrace()));

let ids = vec!["a".to_string()];
let (qualifier, column) = form_identifier(&ids)?;
Expand Down Expand Up @@ -470,7 +470,7 @@ mod test {
let expected = "Internal error: Incorrect number of identifiers: 5. \
This was likely caused by a bug in DataFusion's code and we would \
welcome that you file an bug report in our issue tracker";
assert_eq!(err.strip_backtrace(), expected);
assert!(expected.starts_with(&err.strip_backtrace()));

Ok(())
}
Expand Down
Loading

0 comments on commit c7a51b6

Please sign in to comment.