Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
comphead committed Aug 30, 2023
1 parent d07fd7a commit 7b125ea
Show file tree
Hide file tree
Showing 23 changed files with 81 additions and 81 deletions.
17 changes: 7 additions & 10 deletions datafusion/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ impl DataFusionError {
.split("\n\nbacktrace: ")
.collect::<Vec<&str>>()
.first()
.unwrap_or_else(|| &"")
.unwrap_or(&"")
.to_string()
}

Expand Down Expand Up @@ -514,16 +514,15 @@ mod test {
use arrow::error::ArrowError;

#[test]
fn arrow_error_to_datafusion() {
fn datafusion_error_to_arrow() {
let res = return_arrow_error().unwrap_err();
assert_eq!(
res.to_string(),
"External error: Error during planning: foo"
);
assert!(res
.to_string()
.starts_with("External error: Error during planning: foo"));
}

#[test]
fn datafusion_error_to_arrow() {
fn arrow_error_to_datafusion() {
let res = return_datafusion_error().unwrap_err();
assert_eq!(res.strip_backtrace(), "Arrow error: Schema error: bar");
}
Expand Down Expand Up @@ -641,9 +640,7 @@ mod test {
let e = e.find_root();

// DataFusionError does not implement Eq, so we use a string comparison + some cheap "same variant" test instead
dbg!(e.to_string());
dbg!(exp.to_string());
assert_eq!(e.strip_backtrace(), exp.to_string());
assert_eq!(e.strip_backtrace(), exp.strip_backtrace());
assert_eq!(std::mem::discriminant(e), std::mem::discriminant(&exp),)
}
}
10 changes: 5 additions & 5 deletions datafusion/core/tests/dataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ async fn sort_on_distinct_unprojected_columns() -> Result<()> {
.distinct()?
.sort(vec![Expr::Sort(Sort::new(Box::new(col("b")), false, true))])
.unwrap_err();
assert_eq!(err.to_string(), "Error during planning: For SELECT DISTINCT, ORDER BY expressions b must appear in select list");
assert_eq!(err.strip_backtrace(), "Error during planning: For SELECT DISTINCT, ORDER BY expressions b must appear in select list");
Ok(())
}

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

let expected = "Schema error: Ambiguous reference to unqualified field b";
assert_eq!(err.to_string(), expected);
assert_eq!(err.strip_backtrace(), expected);
Ok(())
}

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

let expected = "Schema error: Ambiguous reference to unqualified field b";
assert_eq!(err.to_string(), expected);
assert_eq!(err.strip_backtrace(), expected);
Ok(())
}

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

let expected = "Schema error: Ambiguous reference to unqualified field b";
assert_eq!(err.to_string(), expected);
assert_eq!(err.strip_backtrace(), expected);
Ok(())
}

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

let expected = "Schema error: Ambiguous reference to unqualified field b";
assert_eq!(err.to_string(), expected);
assert_eq!(err.strip_backtrace(), expected);
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/sql/joins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ async fn join_change_in_planner_without_sort_not_allowed() -> Result<()> {
match df.create_physical_plan().await {
Ok(_) => panic!("Expecting error."),
Err(e) => {
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")
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")
}
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions datafusion/core/tests/sql/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn create_external_table_with_ddl_ordered_non_cols() -> Result<()> {
Ok(_) => panic!("Expecting error."),
Err(e) => {
assert_eq!(
e.to_string(),
e.strip_backtrace(),
"Error during planning: Column a is not in schema"
)
}
Expand All @@ -85,7 +85,7 @@ async fn create_external_table_with_ddl_ordered_without_schema() -> Result<()> {
match ctx.state().create_logical_plan(sql).await {
Ok(_) => panic!("Expecting error."),
Err(e) => {
assert_eq!(e.to_string(), "Error during planning: Provide a schema before specifying the order while creating a table.")
assert_eq!(e.strip_backtrace(), "Error during planning: Provide a schema before specifying the order while creating a table.")
}
}
Ok(())
Expand Down
10 changes: 5 additions & 5 deletions datafusion/core/tests/sql/sql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn unsupported_ddl_returns_error() {
let sql = "create view test_view as select * from test";
let df = ctx.sql_with_options(sql, options).await;
assert_eq!(
df.unwrap_err().to_string(),
df.unwrap_err().strip_backtrace(),
"Error during planning: DDL not supported: CreateView"
);

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

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

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

Expand All @@ -110,7 +110,7 @@ async fn ddl_can_not_be_planned_by_session_state() {
let plan = state.create_logical_plan(sql).await.unwrap();
let physical_plan = state.create_physical_plan(&plan).await;
assert_eq!(
physical_plan.unwrap_err().to_string(),
physical_plan.unwrap_err().strip_backtrace(),
"This feature is not implemented: Unsupported logical plan: DropTable"
);
}
4 changes: 2 additions & 2 deletions datafusion/core/tests/sql/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ async fn test_cast_to_time_with_time_zone_should_not_work() -> Result<()> {
let results = plan_and_collect(&ctx, sql).await.unwrap_err();

assert_eq!(
results.to_string(),
results.strip_backtrace(),
"This feature is not implemented: Unsupported SQL type Time(None, WithTimeZone)"
);

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

assert_eq!(
results.to_string(),
results.strip_backtrace(),
"This feature is not implemented: Unsupported SQL type Time(None, Tz)"
);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion datafusion/execution/src/disk_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ mod tests {
let manager = DiskManager::try_new(config).unwrap();
assert!(!manager.tmp_files_enabled());
assert_eq!(
manager.create_tmp_file("Testing").unwrap_err().to_string(),
manager.create_tmp_file("Testing").unwrap_err().strip_backtrace(),
"Resources exhausted: Memory Exhausted while Testing (DiskManager is disabled)",
)
}
Expand Down
10 changes: 5 additions & 5 deletions datafusion/execution/src/memory_pool/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ mod tests {

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

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

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

r1.shrink(1990);
Expand All @@ -289,12 +289,12 @@ mod tests {
.with_can_spill(true)
.register(&pool);

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

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

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

let mut r4 = MemoryConsumer::new("s4").register(&pool);
let err = r4.try_grow(30).unwrap_err().to_string();
let err = r4.try_grow(30).unwrap_err().strip_backtrace();
assert_eq!(err, "Resources exhausted: Failed to allocate additional 30 bytes for s4 with 0 bytes already allocated - maximum available is 20");
}
}
10 changes: 5 additions & 5 deletions datafusion/execution/src/object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,20 @@ mod tests {
assert_eq!(url.as_str(), "s3://username:password@host:123/");

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

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

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

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

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

#[test]
Expand Down
2 changes: 1 addition & 1 deletion datafusion/expr/src/expr_rewriter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ mod test {
let error =
normalize_col_with_schemas_and_ambiguity_check(expr, &[&schemas], &[])
.unwrap_err()
.to_string();
.strip_backtrace();
assert_eq!(
error,
r#"Schema error: No field named b. Valid fields are "tableA".a."#
Expand Down
8 changes: 4 additions & 4 deletions datafusion/expr/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ mod tests {
let err =
LogicalPlanBuilder::scan("", table_source(&schema), projection).unwrap_err();
assert_eq!(
err.to_string(),
err.strip_backtrace(),
"Error during planning: table_name cannot be empty"
);
}
Expand Down Expand Up @@ -1651,8 +1651,8 @@ mod tests {
let err_msg1 = plan1.clone().union(plan2.clone().build()?).unwrap_err();
let err_msg2 = plan1.union_distinct(plan2.build()?).unwrap_err();

assert_eq!(err_msg1.to_string(), expected);
assert_eq!(err_msg2.to_string(), expected);
assert_eq!(err_msg1.strip_backtrace(), expected);
assert_eq!(err_msg2.strip_backtrace(), expected);

Ok(())
}
Expand Down Expand Up @@ -1876,7 +1876,7 @@ mod tests {
LogicalPlanBuilder::intersect(plan1.build()?, plan2.build()?, true)
.unwrap_err();

assert_eq!(err_msg1.to_string(), expected);
assert_eq!(err_msg1.strip_backtrace(), expected);

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,7 @@ digraph {
})),
empty_schema,
);
assert_eq!("Error during planning: Projection has mismatch between number of expressions (1) and number of fields in schema (0)", format!("{}", p.err().unwrap()));
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)");
Ok(())
}

Expand Down
6 changes: 3 additions & 3 deletions datafusion/expr/src/type_coercion/aggregates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ mod tests {
let input_types = vec![DataType::Int64, DataType::Int32];
let signature = fun.signature();
let result = coerce_types(&fun, &input_types, &signature);
assert_eq!("Error during planning: The function Min expects 1 arguments, but 2 were provided", result.unwrap_err().to_string());
assert_eq!("Error during planning: The function Min expects 1 arguments, but 2 were provided", result.unwrap_err().strip_backtrace());

// test input args is invalid data type for sum or avg
let fun = AggregateFunction::Sum;
Expand All @@ -586,14 +586,14 @@ mod tests {
let result = coerce_types(&fun, &input_types, &signature);
assert_eq!(
"Error during planning: The function Sum does not support inputs of type Utf8.",
result.unwrap_err().to_string()
result.unwrap_err().strip_backtrace()
);
let fun = AggregateFunction::Avg;
let signature = fun.signature();
let result = coerce_types(&fun, &input_types, &signature);
assert_eq!(
"Error during planning: The function Avg does not support inputs of type Utf8.",
result.unwrap_err().to_string()
result.unwrap_err().strip_backtrace()
);

// test count, array_agg, approx_distinct, min, max.
Expand Down
4 changes: 2 additions & 2 deletions datafusion/expr/src/window_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ mod tests {
};
let err = WindowFrame::try_from(window_frame).unwrap_err();
assert_eq!(
err.to_string(),
err.strip_backtrace(),
"Error during planning: Invalid window frame: start bound cannot be UNBOUNDED FOLLOWING".to_owned()
);

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

Expand Down
4 changes: 2 additions & 2 deletions datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ mod test {
};
let err = coerce_case_expression(case, &schema).unwrap_err();
assert_eq!(
err.to_string(),
err.strip_backtrace(),
"Error during planning: \
Failed to coerce case (Interval(MonthDayNano)) and \
when ([Float32, Binary, Utf8]) to common types in \
Expand All @@ -1475,7 +1475,7 @@ mod test {
};
let err = coerce_case_expression(case, &schema).unwrap_err();
assert_eq!(
err.to_string(),
err.strip_backtrace(),
"Error during planning: \
Failed to coerce then ([Date32, Float32, Binary]) and \
else (Some(Timestamp(Nanosecond, None))) to common types \
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 @@ -483,7 +483,7 @@ mod tests {
assert_eq!(
"Optimizer rule 'bad rule' failed\ncaused by\n\
Error during planning: rule failed",
err.to_string()
err.strip_backtrace()
);
}

Expand All @@ -507,7 +507,7 @@ mod tests {
metadata: {}, functional_dependencies: FunctionalDependencies { deps: [] } }. \
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",
err.to_string()
err.strip_backtrace()
);
}

Expand Down
5 changes: 4 additions & 1 deletion datafusion/physical-expr/src/aggregate/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,10 @@ mod tests {
"MIN/MAX is not expected to receive scalars of incompatible types {:?}",
(Decimal128(Some(123), 10, 2), Decimal128(Some(124), 10, 3))
));
assert_eq!(expect.to_string(), result.unwrap_err().to_string());
assert_eq!(
expect.strip_backtrace(),
result.unwrap_err().strip_backtrace()
);

// max batch
let array: ArrayRef = Arc::new(
Expand Down
2 changes: 1 addition & 1 deletion datafusion/physical-expr/src/array_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3213,7 +3213,7 @@ mod tests {

let array = array_append(&args);

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

fn return_array() -> ColumnarValue {
Expand Down
Loading

0 comments on commit 7b125ea

Please sign in to comment.