Skip to content

Commit 97bca0d

Browse files
committed
Plural types as Display
1 parent 787ddd0 commit 97bca0d

File tree

11 files changed

+36
-18
lines changed

11 files changed

+36
-18
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/expr/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ datafusion-functions-aggregate-common = { workspace = true }
5151
datafusion-functions-window-common = { workspace = true }
5252
datafusion-physical-expr-common = { workspace = true }
5353
indexmap = { workspace = true }
54+
itertools = { workspace = true }
5455
paste = "^1.0"
5556
recursive = { workspace = true, optional = true }
5657
serde_json = { workspace = true }

datafusion/expr/src/conditional_expressions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::expr::Case;
2020
use crate::{expr_schema::ExprSchemable, Expr};
2121
use arrow::datatypes::DataType;
2222
use datafusion_common::{plan_err, DFSchema, HashSet, Result};
23+
use itertools::Itertools as _;
2324

2425
/// Helper struct for building [Expr::Case]
2526
pub struct CaseBuilder {
@@ -83,7 +84,8 @@ impl CaseBuilder {
8384
let unique_types: HashSet<&DataType> = then_types.iter().collect();
8485
if unique_types.len() != 1 {
8586
return plan_err!(
86-
"CASE expression 'then' values had multiple data types: {unique_types:?}"
87+
"CASE expression 'then' values had multiple data types: {}",
88+
unique_types.iter().join(", ")
8789
);
8890
}
8991
}

datafusion/expr/src/logical_plan/statement.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use arrow::datatypes::DataType;
1919
use datafusion_common::{DFSchema, DFSchemaRef};
20+
use itertools::Itertools as _;
2021
use std::fmt::{self, Display};
2122
use std::sync::{Arc, LazyLock};
2223

@@ -110,7 +111,7 @@ impl Statement {
110111
Statement::Prepare(Prepare {
111112
name, data_types, ..
112113
}) => {
113-
write!(f, "Prepare: {name:?} {data_types:?}")
114+
write!(f, "Prepare: {name:?} {}", data_types.iter().join(", "))
114115
}
115116
Statement::Execute(Execute {
116117
name, parameters, ..

datafusion/expr/src/type_coercion/functions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use datafusion_expr_common::{
3636
type_coercion::binary::comparison_coercion_numeric,
3737
type_coercion::binary::string_coercion,
3838
};
39+
use itertools::Itertools as _;
3940
use std::sync::Arc;
4041

4142
/// Performs type coercion for scalar function arguments.
@@ -278,7 +279,8 @@ fn try_coerce_types(
278279

279280
// none possible -> Error
280281
plan_err!(
281-
"Failed to coerce arguments to satisfy a call to '{function_name}' function: coercion from {current_types:?} to the signature {type_signature:?} failed"
282+
"Failed to coerce arguments to satisfy a call to '{function_name}' function: coercion from {} to the signature {type_signature:?} failed",
283+
current_types.iter().join(", ")
282284
)
283285
}
284286

datafusion/functions-nested/src/concat.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ impl ScalarUDFImpl for ArrayConcat {
319319
}
320320
} else {
321321
plan_err!(
322-
"Failed to unify argument types of {}: {arg_types:?}",
323-
self.name()
322+
"Failed to unify argument types of {}: {}",
323+
self.name(),
324+
arg_types.iter().join(", ")
324325
)
325326
}
326327
}

datafusion/functions-nested/src/make_array.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use datafusion_expr::{
3939
ColumnarValue, Documentation, ScalarUDFImpl, Signature, Volatility,
4040
};
4141
use datafusion_macros::user_doc;
42+
use itertools::Itertools as _;
4243

4344
make_udf_expr_and_func!(
4445
MakeArray,
@@ -132,8 +133,9 @@ impl ScalarUDFImpl for MakeArray {
132133
Ok(vec![unified; arg_types.len()])
133134
} else {
134135
plan_err!(
135-
"Failed to unify argument types of {}: {arg_types:?}",
136-
self.name()
136+
"Failed to unify argument types of {}: {}",
137+
self.name(),
138+
arg_types.iter().join(", ")
137139
)
138140
}
139141
}

datafusion/functions-nested/src/utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use datafusion_common::cast::{
3131
use datafusion_common::{exec_err, internal_err, plan_err, Result, ScalarValue};
3232

3333
use datafusion_expr::ColumnarValue;
34+
use itertools::Itertools as _;
3435

3536
pub(crate) fn check_datatypes(name: &str, args: &[&ArrayRef]) -> Result<()> {
3637
let data_type = args[0].data_type();
@@ -39,7 +40,10 @@ pub(crate) fn check_datatypes(name: &str, args: &[&ArrayRef]) -> Result<()> {
3940
|| arg.data_type().equals_datatype(&DataType::Null)
4041
}) {
4142
let types = args.iter().map(|arg| arg.data_type()).collect::<Vec<_>>();
42-
return plan_err!("{name} received incompatible types: '{types:?}'.");
43+
return plan_err!(
44+
"{name} received incompatible types: '{}'.",
45+
types.iter().join(", ")
46+
);
4347
}
4448

4549
Ok(())

datafusion/optimizer/src/analyzer/type_coercion.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use std::sync::Arc;
2121

2222
use datafusion_expr::binary::BinaryTypeCoercer;
23-
use itertools::izip;
23+
use itertools::{izip, Itertools as _};
2424

2525
use arrow::datatypes::{DataType, Field, IntervalUnit, Schema};
2626

@@ -479,7 +479,7 @@ impl TreeNodeRewriter for TypeCoercionRewriter<'_> {
479479
get_coerce_type_for_list(&expr_data_type, &list_data_types);
480480
match result_type {
481481
None => plan_err!(
482-
"Can not find compatible types to compare {expr_data_type} with {list_data_types:?}"
482+
"Can not find compatible types to compare {expr_data_type} with {}", list_data_types.iter().join(", ")
483483
),
484484
Some(coerced_type) => {
485485
// find the coerced type
@@ -897,8 +897,9 @@ fn coerce_case_expression(case: Case, schema: &DFSchema) -> Result<Case> {
897897
get_coerce_type_for_case_expression(&when_types, Some(case_type));
898898
coerced_type.ok_or_else(|| {
899899
plan_datafusion_err!(
900-
"Failed to coerce case ({case_type}) and when ({when_types:?}) \
901-
to common types in CASE WHEN expression"
900+
"Failed to coerce case ({case_type}) and when ({}) \
901+
to common types in CASE WHEN expression",
902+
when_types.iter().join(", ")
902903
)
903904
})
904905
})
@@ -908,13 +909,15 @@ fn coerce_case_expression(case: Case, schema: &DFSchema) -> Result<Case> {
908909
|| {
909910
if let Some(else_type) = else_type {
910911
plan_datafusion_err!(
911-
"Failed to coerce then ({then_types:?}) and else ({else_type}) \
912-
to common types in CASE WHEN expression"
912+
"Failed to coerce then ({}) and else ({else_type}) \
913+
to common types in CASE WHEN expression",
914+
then_types.iter().join(", ")
913915
)
914916
} else {
915917
plan_datafusion_err!(
916-
"Failed to coerce then ({then_types:?}) and else (None) \
917-
to common types in CASE WHEN expression"
918+
"Failed to coerce then ({}) and else (None) \
919+
to common types in CASE WHEN expression",
920+
then_types.iter().join(", ")
918921
)
919922
}
920923
},

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ mod tests {
488488
let result_type = get_coerce_type(expr_type, &list_types);
489489
match result_type {
490490
None => plan_err!(
491-
"Can not find compatible types to compare {expr_type} with {list_types:?}"
491+
"Can not find compatible types to compare {expr_type} with {}",
492+
list_types.iter().join(", ")
492493
),
493494
Some(data_type) => {
494495
// find the coerced type

0 commit comments

Comments
 (0)