Skip to content

Commit 631f9ab

Browse files
authored
Use Display formatting of DataType:s in error messages (#17565)
* Use Display formatting for DataTypes where I could find them * fix * More places * Less Debug * Cargo fmt * More cleanup * Plural types as Display * Fixes * Update some more tests and error messages * Update test snapshot * last (?) fixes * update another slt * Update instructions on how to run the tests * Ignore pending snapshot files in .gitignore * Running all the tests is so slow * just a trailing space * Update another test * Fix markdown formatting * Improve Display for NativeType * Update code related to error reporting of NativeType * Revert some formatting * fixelyfix * Another snapshot update
1 parent 9e36ec4 commit 631f9ab

File tree

82 files changed

+274
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+274
-255
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ docker_cache
3131
*.orig
3232
.*.swp
3333
.*.swo
34+
*.pending-snap
3435

3536
venv/*
3637

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-cli/CONTRIBUTING.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@
2121

2222
## Running Tests
2323

24-
Tests can be run using `cargo`
24+
First check out test files with
2525

2626
```shell
27-
cargo test
27+
git submodule update --init
28+
```
29+
30+
Then run all the tests with
31+
32+
```shell
33+
cargo test --all-targets
2834
```
2935

3036
## Running Storage Integration Tests

datafusion-examples/examples/custom_file_casts.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,18 @@ impl PhysicalExprAdapter for CustomCastsPhysicalExprAdapter {
183183
// For example, [DataFusion Comet](https://github.com/apache/datafusion-comet) has a [custom cast kernel](https://github.com/apache/datafusion-comet/blob/b4ac876ab420ed403ac7fc8e1b29f42f1f442566/native/spark-expr/src/conversion_funcs/cast.rs#L133-L138).
184184
expr.transform(|expr| {
185185
if let Some(cast) = expr.as_any().downcast_ref::<CastExpr>() {
186-
let input_data_type = cast.expr().data_type(&self.physical_file_schema)?;
186+
let input_data_type =
187+
cast.expr().data_type(&self.physical_file_schema)?;
187188
let output_data_type = cast.data_type(&self.physical_file_schema)?;
188189
if !cast.is_bigger_cast(&input_data_type) {
189-
return not_impl_err!("Unsupported CAST from {input_data_type:?} to {output_data_type:?}")
190+
return not_impl_err!(
191+
"Unsupported CAST from {input_data_type} to {output_data_type}"
192+
);
190193
}
191194
}
192195
Ok(Transformed::no(expr))
193-
}).data()
196+
})
197+
.data()
194198
}
195199

196200
fn with_partition_values(

datafusion/catalog/src/information_schema.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ fn get_udwf_args_and_return_types(
480480

481481
#[inline]
482482
fn remove_native_type_prefix(native_type: NativeType) -> String {
483-
format!("{native_type:?}")
483+
format!("{native_type}")
484484
}
485485

486486
#[async_trait]
@@ -827,8 +827,7 @@ impl InformationSchemaColumnsBuilder {
827827
self.is_nullables.append_value(nullable_str);
828828

829829
// "System supplied type" --> Use debug format of the datatype
830-
self.data_types
831-
.append_value(format!("{:?}", field.data_type()));
830+
self.data_types.append_value(field.data_type().to_string());
832831

833832
// "If data_type identifies a character or bit string type, the
834833
// declared maximum length; null for all other data types or

datafusion/common/src/dfschema.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ impl DFSchema {
669669
))
670670
{
671671
_plan_err!(
672-
"Schema mismatch: Expected field '{}' with type {:?}, \
673-
but got '{}' with type {:?}.",
672+
"Schema mismatch: Expected field '{}' with type {}, \
673+
but got '{}' with type {}.",
674674
f1.name(),
675675
f1.data_type(),
676676
f2.name(),
@@ -1063,7 +1063,7 @@ fn format_simple_data_type(data_type: &DataType) -> String {
10631063
format!("decimal256({precision}, {scale})")
10641064
}
10651065
DataType::Null => "null".to_string(),
1066-
_ => format!("{data_type:?}").to_lowercase(),
1066+
_ => format!("{data_type}").to_lowercase(),
10671067
}
10681068
}
10691069

@@ -1308,8 +1308,8 @@ impl SchemaExt for Schema {
13081308
.try_for_each(|(f1, f2)| {
13091309
if f1.name() != f2.name() || (!DFSchema::datatype_is_logically_equal(f1.data_type(), f2.data_type()) && !can_cast_types(f2.data_type(), f1.data_type())) {
13101310
_plan_err!(
1311-
"Inserting query schema mismatch: Expected table field '{}' with type {:?}, \
1312-
but got '{}' with type {:?}.",
1311+
"Inserting query schema mismatch: Expected table field '{}' with type {}, \
1312+
but got '{}' with type {}.",
13131313
f1.name(),
13141314
f1.data_type(),
13151315
f2.name(),

datafusion/common/src/nested_struct.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn cast_struct_column(
8787
} else {
8888
// Return error if source is not a struct type
8989
_plan_err!(
90-
"Cannot cast column of type {:?} to struct type. Source must be a struct to cast to struct.",
90+
"Cannot cast column of type {} to struct type. Source must be a struct to cast to struct.",
9191
source_col.data_type()
9292
)
9393
}
@@ -128,7 +128,7 @@ fn cast_struct_column(
128128
/// The struct casting logic requires that the source column must already be a struct type.
129129
/// This makes the function useful for:
130130
/// - Schema evolution scenarios where struct layouts change over time
131-
/// - Data migration between different struct schemas
131+
/// - Data migration between different struct schemas
132132
/// - Type-safe data processing pipelines that maintain struct type integrity
133133
///
134134
/// # Arguments
@@ -165,15 +165,15 @@ pub fn cast_column(
165165
/// Validates compatibility between source and target struct fields for casting operations.
166166
///
167167
/// This function implements comprehensive struct compatibility checking by examining:
168-
/// - Field name matching between source and target structs
168+
/// - Field name matching between source and target structs
169169
/// - Type castability for each matching field (including recursive struct validation)
170170
/// - Proper handling of missing fields (target fields not in source are allowed - filled with nulls)
171171
/// - Proper handling of extra fields (source fields not in target are allowed - ignored)
172172
///
173173
/// # Compatibility Rules
174174
/// - **Field Matching**: Fields are matched by name (case-sensitive)
175175
/// - **Missing Target Fields**: Allowed - will be filled with null values during casting
176-
/// - **Extra Source Fields**: Allowed - will be ignored during casting
176+
/// - **Extra Source Fields**: Allowed - will be ignored during casting
177177
/// - **Type Compatibility**: Each matching field must be castable using Arrow's type system
178178
/// - **Nested Structs**: Recursively validates nested struct compatibility
179179
///
@@ -188,7 +188,7 @@ pub fn cast_column(
188188
/// # Examples
189189
/// ```text
190190
/// // Compatible: source has extra field, target has missing field
191-
/// // Source: {a: i32, b: string, c: f64}
191+
/// // Source: {a: i32, b: string, c: f64}
192192
/// // Target: {a: i64, d: bool}
193193
/// // Result: Ok(()) - 'a' can cast i32->i64, 'b','c' ignored, 'd' filled with nulls
194194
///
@@ -230,7 +230,7 @@ pub fn validate_struct_compatibility(
230230
target_field.data_type(),
231231
) {
232232
return _plan_err!(
233-
"Cannot cast struct field '{}' from type {:?} to type {:?}",
233+
"Cannot cast struct field '{}' from type {} to type {}",
234234
target_field.name(),
235235
source_field.data_type(),
236236
target_field.data_type()

datafusion/common/src/param_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl ParamValues {
4848
for (i, (param_type, value)) in iter.enumerate() {
4949
if *param_type != value.data_type() {
5050
return _plan_err!(
51-
"Expected parameter of type {:?}, got {:?} at index {}",
51+
"Expected parameter of type {}, got {:?} at index {}",
5252
param_type,
5353
value.data_type(),
5454
i

datafusion/common/src/scalar/mod.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ impl ScalarValue {
11371137
DataType::Null => ScalarValue::Null,
11381138
_ => {
11391139
return _not_impl_err!(
1140-
"Can't create a null scalar from data_type \"{data_type:?}\""
1140+
"Can't create a null scalar from data_type \"{data_type}\""
11411141
);
11421142
}
11431143
})
@@ -1193,7 +1193,7 @@ impl ScalarValue {
11931193
match datatype {
11941194
DataType::Float32 => Ok(ScalarValue::from(std::f32::consts::PI)),
11951195
DataType::Float64 => Ok(ScalarValue::from(std::f64::consts::PI)),
1196-
_ => _internal_err!("PI is not supported for data type: {:?}", datatype),
1196+
_ => _internal_err!("PI is not supported for data type: {}", datatype),
11971197
}
11981198
}
11991199

@@ -1203,7 +1203,7 @@ impl ScalarValue {
12031203
DataType::Float32 => Ok(ScalarValue::from(consts::PI_UPPER_F32)),
12041204
DataType::Float64 => Ok(ScalarValue::from(consts::PI_UPPER_F64)),
12051205
_ => {
1206-
_internal_err!("PI_UPPER is not supported for data type: {:?}", datatype)
1206+
_internal_err!("PI_UPPER is not supported for data type: {}", datatype)
12071207
}
12081208
}
12091209
}
@@ -1214,7 +1214,7 @@ impl ScalarValue {
12141214
DataType::Float32 => Ok(ScalarValue::from(consts::NEGATIVE_PI_LOWER_F32)),
12151215
DataType::Float64 => Ok(ScalarValue::from(consts::NEGATIVE_PI_LOWER_F64)),
12161216
_ => {
1217-
_internal_err!("-PI_LOWER is not supported for data type: {:?}", datatype)
1217+
_internal_err!("-PI_LOWER is not supported for data type: {}", datatype)
12181218
}
12191219
}
12201220
}
@@ -1225,10 +1225,7 @@ impl ScalarValue {
12251225
DataType::Float32 => Ok(ScalarValue::from(consts::FRAC_PI_2_UPPER_F32)),
12261226
DataType::Float64 => Ok(ScalarValue::from(consts::FRAC_PI_2_UPPER_F64)),
12271227
_ => {
1228-
_internal_err!(
1229-
"PI_UPPER/2 is not supported for data type: {:?}",
1230-
datatype
1231-
)
1228+
_internal_err!("PI_UPPER/2 is not supported for data type: {}", datatype)
12321229
}
12331230
}
12341231
}
@@ -1243,10 +1240,7 @@ impl ScalarValue {
12431240
Ok(ScalarValue::from(consts::NEGATIVE_FRAC_PI_2_LOWER_F64))
12441241
}
12451242
_ => {
1246-
_internal_err!(
1247-
"-PI/2_LOWER is not supported for data type: {:?}",
1248-
datatype
1249-
)
1243+
_internal_err!("-PI/2_LOWER is not supported for data type: {}", datatype)
12501244
}
12511245
}
12521246
}
@@ -1256,7 +1250,7 @@ impl ScalarValue {
12561250
match datatype {
12571251
DataType::Float32 => Ok(ScalarValue::from(-std::f32::consts::PI)),
12581252
DataType::Float64 => Ok(ScalarValue::from(-std::f64::consts::PI)),
1259-
_ => _internal_err!("-PI is not supported for data type: {:?}", datatype),
1253+
_ => _internal_err!("-PI is not supported for data type: {}", datatype),
12601254
}
12611255
}
12621256

@@ -1265,7 +1259,7 @@ impl ScalarValue {
12651259
match datatype {
12661260
DataType::Float32 => Ok(ScalarValue::from(std::f32::consts::FRAC_PI_2)),
12671261
DataType::Float64 => Ok(ScalarValue::from(std::f64::consts::FRAC_PI_2)),
1268-
_ => _internal_err!("PI/2 is not supported for data type: {:?}", datatype),
1262+
_ => _internal_err!("PI/2 is not supported for data type: {}", datatype),
12691263
}
12701264
}
12711265

@@ -1274,7 +1268,7 @@ impl ScalarValue {
12741268
match datatype {
12751269
DataType::Float32 => Ok(ScalarValue::from(-std::f32::consts::FRAC_PI_2)),
12761270
DataType::Float64 => Ok(ScalarValue::from(-std::f64::consts::FRAC_PI_2)),
1277-
_ => _internal_err!("-PI/2 is not supported for data type: {:?}", datatype),
1271+
_ => _internal_err!("-PI/2 is not supported for data type: {}", datatype),
12781272
}
12791273
}
12801274

@@ -1284,7 +1278,7 @@ impl ScalarValue {
12841278
DataType::Float32 => Ok(ScalarValue::from(f32::INFINITY)),
12851279
DataType::Float64 => Ok(ScalarValue::from(f64::INFINITY)),
12861280
_ => {
1287-
_internal_err!("Infinity is not supported for data type: {:?}", datatype)
1281+
_internal_err!("Infinity is not supported for data type: {}", datatype)
12881282
}
12891283
}
12901284
}
@@ -1296,7 +1290,7 @@ impl ScalarValue {
12961290
DataType::Float64 => Ok(ScalarValue::from(f64::NEG_INFINITY)),
12971291
_ => {
12981292
_internal_err!(
1299-
"Negative Infinity is not supported for data type: {:?}",
1293+
"Negative Infinity is not supported for data type: {}",
13001294
datatype
13011295
)
13021296
}
@@ -1369,7 +1363,7 @@ impl ScalarValue {
13691363
DataType::Date64 => ScalarValue::Date64(Some(0)),
13701364
_ => {
13711365
return _not_impl_err!(
1372-
"Can't create a zero scalar from data_type \"{datatype:?}\""
1366+
"Can't create a zero scalar from data_type \"{datatype}\""
13731367
);
13741368
}
13751369
})
@@ -1507,7 +1501,7 @@ impl ScalarValue {
15071501
// Unsupported types for now
15081502
_ => {
15091503
_not_impl_err!(
1510-
"Default value for data_type \"{datatype:?}\" is not implemented yet"
1504+
"Default value for data_type \"{datatype}\" is not implemented yet"
15111505
)
15121506
}
15131507
}
@@ -1557,7 +1551,7 @@ impl ScalarValue {
15571551
}
15581552
_ => {
15591553
return _not_impl_err!(
1560-
"Can't create an one scalar from data_type \"{datatype:?}\""
1554+
"Can't create an one scalar from data_type \"{datatype}\""
15611555
);
15621556
}
15631557
})
@@ -1603,7 +1597,7 @@ impl ScalarValue {
16031597
}
16041598
_ => {
16051599
return _not_impl_err!(
1606-
"Can't create a negative one scalar from data_type \"{datatype:?}\""
1600+
"Can't create a negative one scalar from data_type \"{datatype}\""
16071601
);
16081602
}
16091603
})
@@ -1656,7 +1650,7 @@ impl ScalarValue {
16561650
}
16571651
_ => {
16581652
return _not_impl_err!(
1659-
"Can't create a ten scalar from data_type \"{datatype:?}\""
1653+
"Can't create a ten scalar from data_type \"{datatype}\""
16601654
);
16611655
}
16621656
})
@@ -2364,7 +2358,7 @@ impl ScalarValue {
23642358
DataType::UInt16 => dict_from_values::<UInt16Type>(values)?,
23652359
DataType::UInt32 => dict_from_values::<UInt32Type>(values)?,
23662360
DataType::UInt64 => dict_from_values::<UInt64Type>(values)?,
2367-
_ => unreachable!("Invalid dictionary keys type: {:?}", key_type),
2361+
_ => unreachable!("Invalid dictionary keys type: {}", key_type),
23682362
}
23692363
}
23702364
DataType::FixedSizeBinary(size) => {
@@ -2375,7 +2369,7 @@ impl ScalarValue {
23752369
} else {
23762370
_exec_err!(
23772371
"Inconsistent types in ScalarValue::iter_to_array. \
2378-
Expected {data_type:?}, got {sv:?}"
2372+
Expected {data_type}, got {sv:?}"
23792373
)
23802374
}
23812375
})
@@ -2937,7 +2931,7 @@ impl ScalarValue {
29372931
DataType::UInt16 => dict_from_scalar::<UInt16Type>(v, size)?,
29382932
DataType::UInt32 => dict_from_scalar::<UInt32Type>(v, size)?,
29392933
DataType::UInt64 => dict_from_scalar::<UInt64Type>(v, size)?,
2940-
_ => unreachable!("Invalid dictionary keys type: {:?}", key_type),
2934+
_ => unreachable!("Invalid dictionary keys type: {}", key_type),
29412935
}
29422936
}
29432937
ScalarValue::Null => get_or_create_cached_null_array(size),
@@ -3197,7 +3191,7 @@ impl ScalarValue {
31973191
DataType::UInt16 => get_dict_value::<UInt16Type>(array, index)?,
31983192
DataType::UInt32 => get_dict_value::<UInt32Type>(array, index)?,
31993193
DataType::UInt64 => get_dict_value::<UInt64Type>(array, index)?,
3200-
_ => unreachable!("Invalid dictionary keys type: {:?}", key_type),
3194+
_ => unreachable!("Invalid dictionary keys type: {}", key_type),
32013195
};
32023196
// look up the index in the values dictionary
32033197
let value = match values_index {
@@ -3571,7 +3565,7 @@ impl ScalarValue {
35713565
DataType::UInt16 => get_dict_value::<UInt16Type>(array, index)?,
35723566
DataType::UInt32 => get_dict_value::<UInt32Type>(array, index)?,
35733567
DataType::UInt64 => get_dict_value::<UInt64Type>(array, index)?,
3574-
_ => unreachable!("Invalid dictionary keys type: {:?}", key_type),
3568+
_ => unreachable!("Invalid dictionary keys type: {}", key_type),
35753569
};
35763570
// was the value in the array non null?
35773571
match values_index {

datafusion/common/src/types/native.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub enum NativeType {
185185

186186
impl Display for NativeType {
187187
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
188-
write!(f, "NativeType::{self:?}")
188+
write!(f, "{self:?}") // TODO: nicer formatting
189189
}
190190
}
191191

@@ -352,10 +352,10 @@ impl LogicalType for NativeType {
352352
}
353353
_ => {
354354
return _internal_err!(
355-
"Unavailable default cast for native type {:?} from physical type {:?}",
356-
self,
357-
origin
358-
)
355+
"Unavailable default cast for native type {} from physical type {}",
356+
self,
357+
origin
358+
)
359359
}
360360
})
361361
}

0 commit comments

Comments
 (0)