Skip to content

Commit e8df378

Browse files
committed
tests
1 parent bbdfbaa commit e8df378

File tree

23 files changed

+81
-81
lines changed

23 files changed

+81
-81
lines changed

datafusion/common/src/error.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl DataFusionError {
420420
.split("\n\nbacktrace: ")
421421
.collect::<Vec<&str>>()
422422
.first()
423-
.unwrap_or_else(|| &"")
423+
.unwrap_or(&"")
424424
.to_string()
425425
}
426426

@@ -514,16 +514,15 @@ mod test {
514514
use arrow::error::ArrowError;
515515

516516
#[test]
517-
fn arrow_error_to_datafusion() {
517+
fn datafusion_error_to_arrow() {
518518
let res = return_arrow_error().unwrap_err();
519-
assert_eq!(
520-
res.to_string(),
521-
"External error: Error during planning: foo"
522-
);
519+
assert!(res
520+
.to_string()
521+
.starts_with("External error: Error during planning: foo"));
523522
}
524523

525524
#[test]
526-
fn datafusion_error_to_arrow() {
525+
fn arrow_error_to_datafusion() {
527526
let res = return_datafusion_error().unwrap_err();
528527
assert_eq!(res.strip_backtrace(), "Arrow error: Schema error: bar");
529528
}
@@ -641,9 +640,7 @@ mod test {
641640
let e = e.find_root();
642641

643642
// DataFusionError does not implement Eq, so we use a string comparison + some cheap "same variant" test instead
644-
dbg!(e.to_string());
645-
dbg!(exp.to_string());
646-
assert_eq!(e.strip_backtrace(), exp.to_string());
643+
assert_eq!(e.strip_backtrace(), exp.strip_backtrace());
647644
assert_eq!(std::mem::discriminant(e), std::mem::discriminant(&exp),)
648645
}
649646
}

datafusion/core/tests/dataframe/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ async fn sort_on_distinct_unprojected_columns() -> Result<()> {
482482
.distinct()?
483483
.sort(vec![Expr::Sort(Sort::new(Box::new(col("b")), false, true))])
484484
.unwrap_err();
485-
assert_eq!(err.to_string(), "Error during planning: For SELECT DISTINCT, ORDER BY expressions b must appear in select list");
485+
assert_eq!(err.strip_backtrace(), "Error during planning: For SELECT DISTINCT, ORDER BY expressions b must appear in select list");
486486
Ok(())
487487
}
488488

@@ -501,7 +501,7 @@ async fn sort_on_ambiguous_column() -> Result<()> {
501501
.unwrap_err();
502502

503503
let expected = "Schema error: Ambiguous reference to unqualified field b";
504-
assert_eq!(err.to_string(), expected);
504+
assert_eq!(err.strip_backtrace(), expected);
505505
Ok(())
506506
}
507507

@@ -520,7 +520,7 @@ async fn group_by_ambiguous_column() -> Result<()> {
520520
.unwrap_err();
521521

522522
let expected = "Schema error: Ambiguous reference to unqualified field b";
523-
assert_eq!(err.to_string(), expected);
523+
assert_eq!(err.strip_backtrace(), expected);
524524
Ok(())
525525
}
526526

@@ -539,7 +539,7 @@ async fn filter_on_ambiguous_column() -> Result<()> {
539539
.unwrap_err();
540540

541541
let expected = "Schema error: Ambiguous reference to unqualified field b";
542-
assert_eq!(err.to_string(), expected);
542+
assert_eq!(err.strip_backtrace(), expected);
543543
Ok(())
544544
}
545545

@@ -558,7 +558,7 @@ async fn select_ambiguous_column() -> Result<()> {
558558
.unwrap_err();
559559

560560
let expected = "Schema error: Ambiguous reference to unqualified field b";
561-
assert_eq!(err.to_string(), expected);
561+
assert_eq!(err.strip_backtrace(), expected);
562562
Ok(())
563563
}
564564

datafusion/core/tests/sql/joins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ async fn join_change_in_planner_without_sort_not_allowed() -> Result<()> {
231231
match df.create_physical_plan().await {
232232
Ok(_) => panic!("Expecting error."),
233233
Err(e) => {
234-
assert_eq!(e.to_string(), "PipelineChecker\ncaused by\nError during planning: Join operation cannot operate on a non-prunable stream without enabling the 'allow_symmetric_joins_without_pruning' configuration flag")
234+
assert_eq!(e.strip_backtrace(), "PipelineChecker\ncaused by\nError during planning: Join operation cannot operate on a non-prunable stream without enabling the 'allow_symmetric_joins_without_pruning' configuration flag")
235235
}
236236
}
237237
Ok(())

datafusion/core/tests/sql/order.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async fn create_external_table_with_ddl_ordered_non_cols() -> Result<()> {
7070
Ok(_) => panic!("Expecting error."),
7171
Err(e) => {
7272
assert_eq!(
73-
e.to_string(),
73+
e.strip_backtrace(),
7474
"Error during planning: Column a is not in schema"
7575
)
7676
}
@@ -85,7 +85,7 @@ async fn create_external_table_with_ddl_ordered_without_schema() -> Result<()> {
8585
match ctx.state().create_logical_plan(sql).await {
8686
Ok(_) => panic!("Expecting error."),
8787
Err(e) => {
88-
assert_eq!(e.to_string(), "Error during planning: Provide a schema before specifying the order while creating a table.")
88+
assert_eq!(e.strip_backtrace(), "Error during planning: Provide a schema before specifying the order while creating a table.")
8989
}
9090
}
9191
Ok(())

datafusion/core/tests/sql/sql_api.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async fn unsupported_ddl_returns_error() {
3030
let sql = "create view test_view as select * from test";
3131
let df = ctx.sql_with_options(sql, options).await;
3232
assert_eq!(
33-
df.unwrap_err().to_string(),
33+
df.unwrap_err().strip_backtrace(),
3434
"Error during planning: DDL not supported: CreateView"
3535
);
3636

@@ -49,7 +49,7 @@ async fn unsupported_dml_returns_error() {
4949
let sql = "insert into test values (1)";
5050
let df = ctx.sql_with_options(sql, options).await;
5151
assert_eq!(
52-
df.unwrap_err().to_string(),
52+
df.unwrap_err().strip_backtrace(),
5353
"Error during planning: DML not supported: Insert Into"
5454
);
5555

@@ -70,7 +70,7 @@ async fn unsupported_copy_returns_error() {
7070
let sql = format!("copy (values(1)) to '{}'", tmpfile.to_string_lossy());
7171
let df = ctx.sql_with_options(&sql, options).await;
7272
assert_eq!(
73-
df.unwrap_err().to_string(),
73+
df.unwrap_err().strip_backtrace(),
7474
"Error during planning: DML not supported: COPY"
7575
);
7676

@@ -88,7 +88,7 @@ async fn unsupported_statement_returns_error() {
8888
let sql = "set datafusion.execution.batch_size = 5";
8989
let df = ctx.sql_with_options(sql, options).await;
9090
assert_eq!(
91-
df.unwrap_err().to_string(),
91+
df.unwrap_err().strip_backtrace(),
9292
"Error during planning: Statement not supported: SetVariable"
9393
);
9494

@@ -110,7 +110,7 @@ async fn ddl_can_not_be_planned_by_session_state() {
110110
let plan = state.create_logical_plan(sql).await.unwrap();
111111
let physical_plan = state.create_physical_plan(&plan).await;
112112
assert_eq!(
113-
physical_plan.unwrap_err().to_string(),
113+
physical_plan.unwrap_err().strip_backtrace(),
114114
"This feature is not implemented: Unsupported logical plan: DropTable"
115115
);
116116
}

datafusion/core/tests/sql/timestamp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ async fn test_cast_to_time_with_time_zone_should_not_work() -> Result<()> {
795795
let results = plan_and_collect(&ctx, sql).await.unwrap_err();
796796

797797
assert_eq!(
798-
results.to_string(),
798+
results.strip_backtrace(),
799799
"This feature is not implemented: Unsupported SQL type Time(None, WithTimeZone)"
800800
);
801801

@@ -828,7 +828,7 @@ async fn test_cast_to_timetz_should_not_work() -> Result<()> {
828828
let results = plan_and_collect(&ctx, sql).await.unwrap_err();
829829

830830
assert_eq!(
831-
results.to_string(),
831+
results.strip_backtrace(),
832832
"This feature is not implemented: Unsupported SQL type Time(None, Tz)"
833833
);
834834
Ok(())

datafusion/execution/src/disk_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ mod tests {
220220
let manager = DiskManager::try_new(config).unwrap();
221221
assert!(!manager.tmp_files_enabled());
222222
assert_eq!(
223-
manager.create_tmp_file("Testing").unwrap_err().to_string(),
223+
manager.create_tmp_file("Testing").unwrap_err().strip_backtrace(),
224224
"Resources exhausted: Memory Exhausted while Testing (DiskManager is disabled)",
225225
)
226226
}

datafusion/execution/src/memory_pool/pool.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@ mod tests {
261261

262262
assert_eq!(pool.reserved(), 4000);
263263

264-
let err = r2.try_grow(1).unwrap_err().to_string();
264+
let err = r2.try_grow(1).unwrap_err().strip_backtrace();
265265
assert_eq!(err, "Resources exhausted: Failed to allocate additional 1 bytes for r2 with 2000 bytes already allocated - maximum available is 0");
266266

267-
let err = r2.try_grow(1).unwrap_err().to_string();
267+
let err = r2.try_grow(1).unwrap_err().strip_backtrace();
268268
assert_eq!(err, "Resources exhausted: Failed to allocate additional 1 bytes for r2 with 2000 bytes already allocated - maximum available is 0");
269269

270270
r1.shrink(1990);
@@ -289,12 +289,12 @@ mod tests {
289289
.with_can_spill(true)
290290
.register(&pool);
291291

292-
let err = r3.try_grow(70).unwrap_err().to_string();
292+
let err = r3.try_grow(70).unwrap_err().strip_backtrace();
293293
assert_eq!(err, "Resources exhausted: Failed to allocate additional 70 bytes for r3 with 0 bytes already allocated - maximum available is 40");
294294

295295
//Shrinking r2 to zero doesn't allow a3 to allocate more than 45
296296
r2.free();
297-
let err = r3.try_grow(70).unwrap_err().to_string();
297+
let err = r3.try_grow(70).unwrap_err().strip_backtrace();
298298
assert_eq!(err, "Resources exhausted: Failed to allocate additional 70 bytes for r3 with 0 bytes already allocated - maximum available is 40");
299299

300300
// But dropping r2 does
@@ -307,7 +307,7 @@ mod tests {
307307
assert_eq!(pool.reserved(), 80);
308308

309309
let mut r4 = MemoryConsumer::new("s4").register(&pool);
310-
let err = r4.try_grow(30).unwrap_err().to_string();
310+
let err = r4.try_grow(30).unwrap_err().strip_backtrace();
311311
assert_eq!(err, "Resources exhausted: Failed to allocate additional 30 bytes for s4 with 0 bytes already allocated - maximum available is 20");
312312
}
313313
}

datafusion/execution/src/object_store.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,20 +234,20 @@ mod tests {
234234
assert_eq!(url.as_str(), "s3://username:password@host:123/");
235235

236236
let err = ObjectStoreUrl::parse("s3://bucket:invalid").unwrap_err();
237-
assert_eq!(err.to_string(), "External error: invalid port number");
237+
assert_eq!(err.strip_backtrace(), "External error: invalid port number");
238238

239239
let err = ObjectStoreUrl::parse("s3://bucket?").unwrap_err();
240-
assert_eq!(err.to_string(), "Execution error: ObjectStoreUrl must only contain scheme and authority, got: ?");
240+
assert_eq!(err.strip_backtrace(), "Execution error: ObjectStoreUrl must only contain scheme and authority, got: ?");
241241

242242
let err = ObjectStoreUrl::parse("s3://bucket?foo=bar").unwrap_err();
243-
assert_eq!(err.to_string(), "Execution error: ObjectStoreUrl must only contain scheme and authority, got: ?foo=bar");
243+
assert_eq!(err.strip_backtrace(), "Execution error: ObjectStoreUrl must only contain scheme and authority, got: ?foo=bar");
244244

245245
let err = ObjectStoreUrl::parse("s3://host:123/foo").unwrap_err();
246-
assert_eq!(err.to_string(), "Execution error: ObjectStoreUrl must only contain scheme and authority, got: /foo");
246+
assert_eq!(err.strip_backtrace(), "Execution error: ObjectStoreUrl must only contain scheme and authority, got: /foo");
247247

248248
let err =
249249
ObjectStoreUrl::parse("s3://username:password@host:123/foo").unwrap_err();
250-
assert_eq!(err.to_string(), "Execution error: ObjectStoreUrl must only contain scheme and authority, got: /foo");
250+
assert_eq!(err.strip_backtrace(), "Execution error: ObjectStoreUrl must only contain scheme and authority, got: /foo");
251251
}
252252

253253
#[test]

datafusion/expr/src/expr_rewriter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ mod test {
374374
let error =
375375
normalize_col_with_schemas_and_ambiguity_check(expr, &[&schemas], &[])
376376
.unwrap_err()
377-
.to_string();
377+
.strip_backtrace();
378378
assert_eq!(
379379
error,
380380
r#"Schema error: No field named b. Valid fields are "tableA".a."#

datafusion/expr/src/logical_plan/builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ mod tests {
15221522
let err =
15231523
LogicalPlanBuilder::scan("", table_source(&schema), projection).unwrap_err();
15241524
assert_eq!(
1525-
err.to_string(),
1525+
err.strip_backtrace(),
15261526
"Error during planning: table_name cannot be empty"
15271527
);
15281528
}
@@ -1651,8 +1651,8 @@ mod tests {
16511651
let err_msg1 = plan1.clone().union(plan2.clone().build()?).unwrap_err();
16521652
let err_msg2 = plan1.union_distinct(plan2.build()?).unwrap_err();
16531653

1654-
assert_eq!(err_msg1.to_string(), expected);
1655-
assert_eq!(err_msg2.to_string(), expected);
1654+
assert_eq!(err_msg1.strip_backtrace(), expected);
1655+
assert_eq!(err_msg2.strip_backtrace(), expected);
16561656

16571657
Ok(())
16581658
}
@@ -1876,7 +1876,7 @@ mod tests {
18761876
LogicalPlanBuilder::intersect(plan1.build()?, plan2.build()?, true)
18771877
.unwrap_err();
18781878

1879-
assert_eq!(err_msg1.to_string(), expected);
1879+
assert_eq!(err_msg1.strip_backtrace(), expected);
18801880

18811881
Ok(())
18821882
}

datafusion/expr/src/logical_plan/plan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,7 @@ digraph {
22722272
})),
22732273
empty_schema,
22742274
);
2275-
assert_eq!("Error during planning: Projection has mismatch between number of expressions (1) and number of fields in schema (0)", format!("{}", p.err().unwrap()));
2275+
assert_eq!(p.err().unwrap().strip_backtrace(), "Error during planning: Projection has mismatch between number of expressions (1) and number of fields in schema (0)");
22762276
Ok(())
22772277
}
22782278

datafusion/expr/src/type_coercion/aggregates.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ mod tests {
577577
let input_types = vec![DataType::Int64, DataType::Int32];
578578
let signature = fun.signature();
579579
let result = coerce_types(&fun, &input_types, &signature);
580-
assert_eq!("Error during planning: The function Min expects 1 arguments, but 2 were provided", result.unwrap_err().to_string());
580+
assert_eq!("Error during planning: The function Min expects 1 arguments, but 2 were provided", result.unwrap_err().strip_backtrace());
581581

582582
// test input args is invalid data type for sum or avg
583583
let fun = AggregateFunction::Sum;
@@ -586,14 +586,14 @@ mod tests {
586586
let result = coerce_types(&fun, &input_types, &signature);
587587
assert_eq!(
588588
"Error during planning: The function Sum does not support inputs of type Utf8.",
589-
result.unwrap_err().to_string()
589+
result.unwrap_err().strip_backtrace()
590590
);
591591
let fun = AggregateFunction::Avg;
592592
let signature = fun.signature();
593593
let result = coerce_types(&fun, &input_types, &signature);
594594
assert_eq!(
595595
"Error during planning: The function Avg does not support inputs of type Utf8.",
596-
result.unwrap_err().to_string()
596+
result.unwrap_err().strip_backtrace()
597597
);
598598

599599
// test count, array_agg, approx_distinct, min, max.

datafusion/expr/src/window_frame.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ mod tests {
332332
};
333333
let err = WindowFrame::try_from(window_frame).unwrap_err();
334334
assert_eq!(
335-
err.to_string(),
335+
err.strip_backtrace(),
336336
"Error during planning: Invalid window frame: start bound cannot be UNBOUNDED FOLLOWING".to_owned()
337337
);
338338

@@ -343,7 +343,7 @@ mod tests {
343343
};
344344
let err = WindowFrame::try_from(window_frame).unwrap_err();
345345
assert_eq!(
346-
err.to_string(),
346+
err.strip_backtrace(),
347347
"Error during planning: Invalid window frame: end bound cannot be UNBOUNDED PRECEDING".to_owned()
348348
);
349349

datafusion/optimizer/src/analyzer/type_coercion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ mod test {
14571457
};
14581458
let err = coerce_case_expression(case, &schema).unwrap_err();
14591459
assert_eq!(
1460-
err.to_string(),
1460+
err.strip_backtrace(),
14611461
"Error during planning: \
14621462
Failed to coerce case (Interval(MonthDayNano)) and \
14631463
when ([Float32, Binary, Utf8]) to common types in \
@@ -1475,7 +1475,7 @@ mod test {
14751475
};
14761476
let err = coerce_case_expression(case, &schema).unwrap_err();
14771477
assert_eq!(
1478-
err.to_string(),
1478+
err.strip_backtrace(),
14791479
"Error during planning: \
14801480
Failed to coerce then ([Date32, Float32, Binary]) and \
14811481
else (Some(Timestamp(Nanosecond, None))) to common types \

datafusion/optimizer/src/optimizer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ mod tests {
483483
assert_eq!(
484484
"Optimizer rule 'bad rule' failed\ncaused by\n\
485485
Error during planning: rule failed",
486-
err.to_string()
486+
err.strip_backtrace()
487487
);
488488
}
489489

@@ -507,7 +507,7 @@ mod tests {
507507
metadata: {}, functional_dependencies: FunctionalDependencies { deps: [] } }. \
508508
This 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",
510-
err.to_string()
510+
err.strip_backtrace()
511511
);
512512
}
513513

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,10 @@ mod tests {
11521152
"MIN/MAX is not expected to receive scalars of incompatible types {:?}",
11531153
(Decimal128(Some(123), 10, 2), Decimal128(Some(124), 10, 3))
11541154
));
1155-
assert_eq!(expect.to_string(), result.unwrap_err().to_string());
1155+
assert_eq!(
1156+
expect.strip_backtrace(),
1157+
result.unwrap_err().strip_backtrace()
1158+
);
11561159

11571160
// max batch
11581161
let array: ArrayRef = Arc::new(

datafusion/physical-expr/src/array_expressions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3213,7 +3213,7 @@ mod tests {
32133213

32143214
let array = array_append(&args);
32153215

3216-
assert_eq!(array.unwrap_err().to_string(), "Error during planning: array_append received incompatible types: '[Int64, Utf8]'.");
3216+
assert_eq!(array.unwrap_err().strip_backtrace(), "Error during planning: array_append received incompatible types: '[Int64, Utf8]'.");
32173217
}
32183218

32193219
fn return_array() -> ColumnarValue {

0 commit comments

Comments
 (0)