Skip to content

Commit a490b68

Browse files
committed
tests
1 parent 2a1423a commit a490b68

File tree

12 files changed

+144
-150
lines changed

12 files changed

+144
-150
lines changed

datafusion/common/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl Display for DataFusionError {
303303
write!(f, "This feature is not implemented: {desc}")
304304
}
305305
DataFusionError::Internal(ref desc) => {
306-
write!(f, "Internal error: {desc}. This was likely caused by a bug in DataFusion's \
306+
write!(f, "Internal error: {desc}.\nThis was likely caused by a bug in DataFusion's \
307307
code and we would welcome that you file an bug report in our issue tracker")
308308
}
309309
DataFusionError::Plan(ref desc) => {

datafusion/core/src/datasource/memory.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,11 @@ mod tests {
435435
],
436436
)?;
437437

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

445444
Ok(())
446445
}
@@ -466,12 +465,11 @@ mod tests {
466465
],
467466
)?;
468467

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

476474
Ok(())
477475
}

datafusion/expr/src/logical_plan/plan.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,14 +2597,11 @@ digraph {
25972597
..Default::default()
25982598
};
25992599
let plan = test_plan();
2600-
let res = plan.visit(&mut visitor);
2601-
2602-
if let Err(DataFusionError::NotImplemented(e)) = res {
2603-
assert_eq!("Error in pre_visit", e);
2604-
} else {
2605-
panic!("Expected an error");
2606-
}
2607-
2600+
let res = plan.visit(&mut visitor).unwrap_err();
2601+
assert_eq!(
2602+
"This feature is not implemented: Error in pre_visit",
2603+
res.strip_backtrace()
2604+
);
26082605
assert_eq!(
26092606
visitor.inner.strings,
26102607
vec!["pre_visit Projection", "pre_visit Filter"]
@@ -2618,13 +2615,11 @@ digraph {
26182615
..Default::default()
26192616
};
26202617
let plan = test_plan();
2621-
let res = plan.visit(&mut visitor);
2622-
if let Err(DataFusionError::NotImplemented(e)) = res {
2623-
assert_eq!("Error in post_visit", e);
2624-
} else {
2625-
panic!("Expected an error");
2626-
}
2627-
2618+
let res = plan.visit(&mut visitor).unwrap_err();
2619+
assert_eq!(
2620+
"This feature is not implemented: Error in post_visit",
2621+
res.strip_backtrace()
2622+
);
26282623
assert_eq!(
26292624
visitor.inner.strings,
26302625
vec![

datafusion/expr/src/type_coercion/binary.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ fn null_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
779779
mod tests {
780780
use arrow::datatypes::DataType;
781781

782+
use datafusion_common::assert_contains;
782783
use datafusion_common::Result;
783-
use datafusion_common::{assert_contains, internal_err, DataFusionError};
784784

785785
use crate::Operator;
786786

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

794-
if let Err(DataFusionError::Plan(e)) = result_type {
795-
assert_eq!(
796-
e,
797-
"Cannot coerce arithmetic expression Float32 + Utf8 to valid types"
798-
);
799-
Ok(())
800-
} else {
801-
internal_err!("Coercion should have returned an DataFusionError::Internal")
802-
}
794+
let e = result_type.unwrap_err();
795+
assert_eq!(e.strip_backtrace(), "Error during planning: Cannot coerce arithmetic expression Float32 + Utf8 to valid types");
796+
Ok(())
803797
}
804798

805799
#[test]

datafusion/optimizer/src/analyzer/type_coercion.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,8 @@ mod test {
873873
.err()
874874
.unwrap();
875875
assert_eq!(
876-
r#"Context("type_coercion", Plan("Coercion from [Utf8] to the signature Uniform(1, [Int32]) failed."))"#,
877-
&format!("{err:?}")
876+
"type_coercion\ncaused by\nError during planning: Coercion from [Utf8] to the signature Uniform(1, [Int32]) failed.",
877+
err.strip_backtrace()
878878
);
879879
Ok(())
880880
}
@@ -943,8 +943,8 @@ mod test {
943943
.err()
944944
.unwrap();
945945
assert_eq!(
946-
r#"Context("type_coercion", Plan("Coercion from [Utf8] to the signature Uniform(1, [Float64]) failed."))"#,
947-
&format!("{err:?}")
946+
"type_coercion\ncaused by\nError during planning: Coercion from [Utf8] to the signature Uniform(1, [Float64]) failed.",
947+
err.strip_backtrace()
948948
);
949949
Ok(())
950950
}

datafusion/optimizer/src/optimizer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ mod tests {
504504
DFField { qualifier: Some(Bare { table: \"test\" }), field: Field { name: \"a\", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} } }, \
505505
DFField { qualifier: Some(Bare { table: \"test\" }), field: Field { name: \"b\", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} } }, \
506506
DFField { qualifier: Some(Bare { table: \"test\" }), field: Field { name: \"c\", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} } }], \
507-
metadata: {}, functional_dependencies: FunctionalDependencies { deps: [] } }. \
508-
This was likely caused by a bug in DataFusion's code \
507+
metadata: {}, functional_dependencies: FunctionalDependencies { deps: [] } }.\
508+
\nThis was likely caused by a bug in DataFusion's code \
509509
and we would welcome that you file an bug report in our issue tracker",
510510
err.strip_backtrace()
511511
);

datafusion/physical-expr/src/aggregate/min_max.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,14 +1172,14 @@ mod tests {
11721172

11731173
let right = ScalarValue::Decimal128(Some(124), 10, 3);
11741174
let result = max(&left, &right);
1175-
let expect = DataFusionError::Internal(format!(
1175+
let err_msg = format!(
11761176
"MIN/MAX is not expected to receive scalars of incompatible types {:?}",
11771177
(Decimal128(Some(123), 10, 2), Decimal128(Some(124), 10, 3))
1178-
));
1179-
assert_eq!(
1180-
expect.strip_backtrace(),
1181-
result.unwrap_err().strip_backtrace()
11821178
);
1179+
let expect = DataFusionError::Internal(err_msg);
1180+
assert!(expect
1181+
.strip_backtrace()
1182+
.starts_with(&result.unwrap_err().strip_backtrace()));
11831183

11841184
// max batch
11851185
let array: ArrayRef = Arc::new(

datafusion/physical-expr/src/expressions/column.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,19 @@ mod test {
227227
let schema = Schema::new(vec![Field::new("foo", DataType::Utf8, true)]);
228228
let col = Column::new("id", 9);
229229
let error = col.data_type(&schema).expect_err("error").strip_backtrace();
230-
assert_eq!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
230+
assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
231231
but input schema only has 1 columns: [\"foo\"]. This was likely caused by a bug in \
232-
DataFusion's code and we would welcome that you file an bug report in our issue tracker",
233-
error)
232+
DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error))
234233
}
235234

236235
#[test]
237236
fn out_of_bounds_nullable() {
238237
let schema = Schema::new(vec![Field::new("foo", DataType::Utf8, true)]);
239238
let col = Column::new("id", 9);
240239
let error = col.nullable(&schema).expect_err("error").strip_backtrace();
241-
assert_eq!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
240+
assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
242241
but input schema only has 1 columns: [\"foo\"]. This was likely caused by a bug in \
243-
DataFusion's code and we would welcome that you file an bug report in our issue tracker",
244-
error)
242+
DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error))
245243
}
246244

247245
#[test]
@@ -251,10 +249,9 @@ mod test {
251249
let batch = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(data)])?;
252250
let col = Column::new("id", 9);
253251
let error = col.evaluate(&batch).expect_err("error").strip_backtrace();
254-
assert_eq!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
252+
assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
255253
but input schema only has 1 columns: [\"foo\"]. This was likely caused by a bug in \
256-
DataFusion's code and we would welcome that you file an bug report in our issue tracker",
257-
error);
254+
DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error));
258255
Ok(())
259256
}
260257
}

datafusion/physical-expr/src/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ mod tests {
10461046
match expr.evaluate(&batch) {
10471047
Ok(_) => assert!(false, "expected error"),
10481048
Err(error) => {
1049-
assert_eq!(error.to_string(), expected_error.to_string());
1049+
assert!(expected_error.strip_backtrace().starts_with(&error.strip_backtrace()));
10501050
}
10511051
}
10521052
}

datafusion/sql/src/expr/identifier.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ mod test {
432432
let expected = "Internal error: Incorrect number of identifiers: 0. \
433433
This was likely caused by a bug in DataFusion's code and we would \
434434
welcome that you file an bug report in our issue tracker";
435-
assert_eq!(err.strip_backtrace(), expected);
435+
assert!(expected.starts_with(&err.strip_backtrace()));
436436

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

475475
Ok(())
476476
}

0 commit comments

Comments
 (0)