Skip to content
Merged
52 changes: 51 additions & 1 deletion datafusion/common/src/types/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,57 @@ pub enum NativeType {

impl Display for NativeType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}") // TODO: nicer formatting
// Match the format used by arrow::datatypes::DataType's Display impl
match self {
Self::Null => write!(f, "Null"),
Self::Boolean => write!(f, "Boolean"),
Self::Int8 => write!(f, "Int8"),
Self::Int16 => write!(f, "Int16"),
Self::Int32 => write!(f, "Int32"),
Self::Int64 => write!(f, "Int64"),
Self::UInt8 => write!(f, "UInt8"),
Self::UInt16 => write!(f, "UInt16"),
Self::UInt32 => write!(f, "UInt32"),
Self::UInt64 => write!(f, "UInt64"),
Self::Float16 => write!(f, "Float16"),
Self::Float32 => write!(f, "Float32"),
Self::Float64 => write!(f, "Float64"),
Self::Timestamp(unit, Some(tz)) => write!(f, "Timestamp({unit}, {tz:?})"),
Self::Timestamp(unit, None) => write!(f, "Timestamp({unit})"),
Self::Date => write!(f, "Date"),
Self::Time(unit) => write!(f, "Time({unit})"),
Self::Duration(unit) => write!(f, "Duration({unit})"),
Self::Interval(unit) => write!(f, "Interval({unit:?})"),
Self::Binary => write!(f, "Binary"),
Self::FixedSizeBinary(size) => write!(f, "FixedSizeBinary({size})"),
Self::String => write!(f, "String"),
Self::List(field) => write!(f, "List({})", field.logical_type),
Self::FixedSizeList(field, size) => {
write!(f, "FixedSizeList({size} x {})", field.logical_type)
}
Self::Struct(fields) => {
write!(f, "Struct(")?;
for (i, field) in fields.iter().enumerate() {
if i > 0 {
write!(f, ", ")?;
}
write!(f, "{:?}: {}", field.name, field.logical_type)?;
}
write!(f, ")")
}
Self::Union(fields) => {
write!(f, "Union(")?;
for (i, (type_id, field)) in fields.iter().enumerate() {
if i > 0 {
write!(f, ", ")?;
}
write!(f, "{type_id}: ({:?}: {})", field.name, field.logical_type)?;
}
write!(f, ")")
}
Self::Decimal(precision, scale) => write!(f, "Decimal({precision}, {scale})"),
Self::Map(field) => write!(f, "Map({})", field.logical_type),
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions datafusion/core/src/datasource/file_format/avro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ mod tests {
.schema()
.fields()
.iter()
.map(|f| format!("{}: {:?}", f.name(), f.data_type()))
.map(|f| format!("{}: {}", f.name(), f.data_type()))
.collect();
assert_eq!(
vec![
Expand All @@ -109,7 +109,7 @@ mod tests {
"double_col: Float64",
"date_string_col: Binary",
"string_col: Binary",
"timestamp_col: Timestamp(Microsecond, None)",
"timestamp_col: Timestamp(µs)",
],
x
);
Expand Down
6 changes: 3 additions & 3 deletions datafusion/core/src/datasource/file_format/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ mod tests {
.schema()
.fields()
.iter()
.map(|f| format!("{}: {:?}", f.name(), f.data_type()))
.map(|f| format!("{}: {}", f.name(), f.data_type()))
.collect();
let y = x.join("\n");
assert_eq!(expected, y);
Expand All @@ -841,7 +841,7 @@ mod tests {
double_col: Float64\n\
date_string_col: Binary\n\
string_col: Binary\n\
timestamp_col: Timestamp(Nanosecond, None)";
timestamp_col: Timestamp(ns)";
_run_read_alltypes_plain_parquet(ForceViews::No, no_views).await?;

let with_views = "id: Int32\n\
Expand All @@ -854,7 +854,7 @@ mod tests {
double_col: Float64\n\
date_string_col: BinaryView\n\
string_col: BinaryView\n\
timestamp_col: Timestamp(Nanosecond, None)";
timestamp_col: Timestamp(ns)";
_run_read_alltypes_plain_parquet(ForceViews::Yes, with_views).await?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/src/physical_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2753,7 +2753,7 @@ impl<'a> OptimizationInvariantChecker<'a> {
&& !is_allowed_schema_change(previous_schema.as_ref(), plan.schema().as_ref())
{
internal_err!(
"PhysicalOptimizer rule '{}' failed. Schema mismatch. Expected original schema: {:?}, got new schema: {:?}",
"PhysicalOptimizer rule '{}' failed. Schema mismatch. Expected original schema: {}, got new schema: {}",
self.rule.name(),
previous_schema,
plan.schema()
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/dataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4801,7 +4801,7 @@ async fn unnest_with_redundant_columns() -> Result<()> {
@r"
Projection: shapes.shape_id [shape_id:UInt32]
Unnest: lists[shape_id2|depth=1] structs[] [shape_id:UInt32, shape_id2:UInt32;N]
Aggregate: groupBy=[[shapes.shape_id]], aggr=[[array_agg(shapes.shape_id) AS shape_id2]] [shape_id:UInt32, shape_id2:List(Field { data_type: UInt32, nullable: true });N]
Aggregate: groupBy=[[shapes.shape_id]], aggr=[[array_agg(shapes.shape_id) AS shape_id2]] [shape_id:UInt32, shape_id2:List(UInt32);N]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

TableScan: shapes projection=[shape_id] [shape_id:UInt32]
"
);
Expand Down
2 changes: 1 addition & 1 deletion datafusion/datasource/src/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct DataSinkExec {

impl Debug for DataSinkExec {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "DataSinkExec schema: {:?}", self.count_schema)
write!(f, "DataSinkExec schema: {}", self.count_schema)
}
}

Expand Down
8 changes: 1 addition & 7 deletions datafusion/expr/src/logical_plan/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,7 @@ pub fn display_schema(schema: &Schema) -> impl fmt::Display + '_ {
write!(f, ", ")?;
}
let nullable_str = if field.is_nullable() { ";N" } else { "" };
write!(
f,
"{}:{:?}{}",
field.name(),
field.data_type(),
nullable_str
)?;
write!(f, "{}:{}{}", field.name(), field.data_type(), nullable_str)?;
}
write!(f, "]")
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/expr/src/type_coercion/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ mod tests {
.unwrap_err();
assert_contains!(
got.to_string(),
"Function 'test' expects NativeType::Numeric but received NativeType::Timestamp(Second, None)"
"Function 'test' expects NativeType::Numeric but received NativeType::Timestamp(s)"
);

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion datafusion/functions-nested/src/array_has.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl<'a> TryFrom<&'a dyn Array> for ArrayWrapper<'a> {
DataType::FixedSizeList(_, _) => Ok(ArrayWrapper::FixedSizeList(
as_fixed_size_list_array(value)?,
)),
_ => exec_err!("array_has does not support type '{:?}'.", value.data_type()),
_ => exec_err!("array_has does not support type '{}'.", value.data_type()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/functions-nested/src/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fn flatten_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
}
Null => Ok(Arc::clone(array)),
_ => {
exec_err!("flatten does not support type '{:?}'", array.data_type())
exec_err!("flatten does not support type '{}'", array.data_type())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/functions-nested/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn get_first_array_ref(columnar_value: &ColumnarValue) -> Result<ArrayRef> {
ScalarValue::List(array) => Ok(array.value(0)),
ScalarValue::LargeList(array) => Ok(array.value(0)),
ScalarValue::FixedSizeList(array) => Ok(array.value(0)),
_ => exec_err!("Expected array, got {:?}", value),
_ => exec_err!("Expected array, got {}", value),
},
ColumnarValue::Array(array) => Ok(array.to_owned()),
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/functions-nested/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pub(crate) fn get_map_entry_field(data_type: &DataType) -> Result<&Fields> {
match field_data_type {
DataType::Struct(fields) => Ok(fields),
_ => {
internal_err!("Expected a Struct type, got {:?}", field_data_type)
internal_err!("Expected a Struct type, got {}", field_data_type)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/functions/src/core/union_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl ScalarUDFImpl for UnionTagFunc {
args.return_field.data_type(),
)?)),
},
v => exec_err!("union_tag only support unions, got {:?}", v.data_type()),
v => exec_err!("union_tag only support unions, got {}", v.data_type()),
}
}

Expand Down
4 changes: 2 additions & 2 deletions datafusion/functions/src/datetime/to_char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl ScalarUDFImpl for ToCharFunc {
ColumnarValue::Array(_) => to_char_array(&args),
_ => {
exec_err!(
"Format for `to_char` must be non-null Utf8, received {:?}",
"Format for `to_char` must be non-null Utf8, received {}",
format.data_type()
)
}
Expand Down Expand Up @@ -814,7 +814,7 @@ mod tests {
let result = ToCharFunc::new().invoke_with_args(args);
assert_eq!(
result.err().unwrap().strip_backtrace(),
"Execution error: Format for `to_char` must be non-null Utf8, received Timestamp(Nanosecond, None)"
"Execution error: Format for `to_char` must be non-null Utf8, received Timestamp(ns)"
);
}
}
4 changes: 2 additions & 2 deletions datafusion/optimizer/src/decorrelate_predicate_subquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@ mod tests {
TableScan: test [a:UInt32, b:UInt32, c:UInt32]
SubqueryAlias: __correlated_sq_1 [arr:Int32;N]
Unnest: lists[sq.arr|depth=1] structs[] [arr:Int32;N]
TableScan: sq [arr:List(Field { data_type: Int32, nullable: true });N]
TableScan: sq [arr:List(Int32);N]
"
)
}
Expand Down Expand Up @@ -2076,7 +2076,7 @@ mod tests {
TableScan: test [a:UInt32, b:UInt32, c:UInt32]
SubqueryAlias: __correlated_sq_1 [a:UInt32;N]
Unnest: lists[sq.a|depth=1] structs[] [a:UInt32;N]
TableScan: sq [a:List(Field { data_type: UInt32, nullable: true });N]
TableScan: sq [a:List(UInt32);N]
"
)
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/physical-expr/src/equivalence/properties/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ impl EquivalenceProperties {
// Rewriting equivalence properties in terms of new schema is not
// safe when schemas are not aligned:
return plan_err!(
"Schemas have to be aligned to rewrite equivalences:\n Old schema: {:?}\n New schema: {:?}",
"Schemas have to be aligned to rewrite equivalences:\n Old schema: {}\n New schema: {}",
self.schema,
schema
);
Expand Down
12 changes: 3 additions & 9 deletions datafusion/physical-expr/src/expressions/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl CastExpr {

impl fmt::Display for CastExpr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "CAST({} AS {:?})", self.expr, self.cast_type)
write!(f, "CAST({} AS {})", self.expr, self.cast_type)
}
}

Expand Down Expand Up @@ -312,10 +312,7 @@ mod tests {
cast_with_options(col("a", &schema)?, &schema, $TYPE, $CAST_OPTIONS)?;

// verify that its display is correct
assert_eq!(
format!("CAST(a@0 AS {:?})", $TYPE),
format!("{}", expression)
);
assert_eq!(format!("CAST(a@0 AS {})", $TYPE), format!("{}", expression));

// verify that the expression's type is correct
assert_eq!(expression.data_type(&schema)?, $TYPE);
Expand Down Expand Up @@ -364,10 +361,7 @@ mod tests {
cast_with_options(col("a", &schema)?, &schema, $TYPE, $CAST_OPTIONS)?;

// verify that its display is correct
assert_eq!(
format!("CAST(a@0 AS {:?})", $TYPE),
format!("{}", expression)
);
assert_eq!(format!("CAST(a@0 AS {})", $TYPE), format!("{}", expression));

// verify that the expression's type is correct
assert_eq!(expression.data_type(&schema)?, $TYPE);
Expand Down
2 changes: 1 addition & 1 deletion datafusion/physical-expr/src/expressions/cast_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Display for CastColumnExpr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"CAST_COLUMN({} AS {:?})",
"CAST_COLUMN({} AS {})",
self.expr,
self.target_field.data_type()
)
Expand Down
6 changes: 3 additions & 3 deletions datafusion/physical-expr/src/expressions/try_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl TryCastExpr {

impl fmt::Display for TryCastExpr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "TRY_CAST({} AS {:?})", self.expr, self.cast_type)
write!(f, "TRY_CAST({} AS {})", self.expr, self.cast_type)
}
}

Expand Down Expand Up @@ -180,7 +180,7 @@ mod tests {

// verify that its display is correct
assert_eq!(
format!("TRY_CAST(a@0 AS {:?})", $TYPE),
format!("TRY_CAST(a@0 AS {})", $TYPE),
format!("{}", expression)
);

Expand Down Expand Up @@ -231,7 +231,7 @@ mod tests {

// verify that its display is correct
assert_eq!(
format!("TRY_CAST(a@0 AS {:?})", $TYPE),
format!("TRY_CAST(a@0 AS {})", $TYPE),
format!("{}", expression)
);

Expand Down
2 changes: 1 addition & 1 deletion datafusion/spark/src/function/string/format_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ impl ConversionSpecifier {
let value = "null".to_string();
self.format_string(string, &value)
}
_ => exec_err!("Invalid scalar value: {:?}", value),
_ => exec_err!("Invalid scalar value: {value}"),
}
}

Expand Down
13 changes: 11 additions & 2 deletions datafusion/spark/src/function/url/parse_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ pub fn spark_handled_parse_url(
handler_err,
)
}
_ => exec_err!("{} expects STRING arguments, got {:?}", "`parse_url`", args),
_ => exec_err!(
"`parse_url` expects STRING arguments, got ({}, {}, {})",
url.data_type(),
part.data_type(),
key.data_type()
),
}
} else {
// The 'key' argument is omitted, assume all values are null
Expand Down Expand Up @@ -253,7 +258,11 @@ pub fn spark_handled_parse_url(
handler_err,
)
}
_ => exec_err!("{} expects STRING arguments, got {:?}", "`parse_url`", args),
_ => exec_err!(
"`parse_url` expects STRING arguments, got ({}, {})",
url.data_type(),
part.data_type()
),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -5501,10 +5501,10 @@ as values
statement ok
create table t as
select
arrow_cast(column1, 'Timestamp(Nanosecond, None)') as nanos,
arrow_cast(column1, 'Timestamp(Microsecond, None)') as micros,
arrow_cast(column1, 'Timestamp(Millisecond, None)') as millis,
arrow_cast(column1, 'Timestamp(Second, None)') as secs,
arrow_cast(column1, 'Timestamp(ns)') as nanos,
arrow_cast(column1, 'Timestamp(µs)') as micros,
arrow_cast(column1, 'Timestamp(ms)') as millis,
arrow_cast(column1, 'Timestamp(s)') as secs,
arrow_cast(column1, 'Timestamp(Nanosecond, Some("UTC"))') as nanos_utc,
arrow_cast(column1, 'Timestamp(Microsecond, Some("UTC"))') as micros_utc,
arrow_cast(column1, 'Timestamp(Millisecond, Some("UTC"))') as millis_utc,
Expand Down Expand Up @@ -5587,7 +5587,7 @@ SELECT tag, avg(nanos), avg(micros), avg(millis), avg(secs) FROM t GROUP BY tag

# aggregate_duration_array_agg
query T?
SELECT tag, array_agg(millis - arrow_cast(secs, 'Timestamp(Millisecond, None)')) FROM t GROUP BY tag ORDER BY tag;
SELECT tag, array_agg(millis - arrow_cast(secs, 'Timestamp(ms)')) FROM t GROUP BY tag ORDER BY tag;
----
X [0 days 0 hours 0 mins 0.011 secs, 0 days 0 hours 0 mins 0.123 secs]
Y [NULL, 0 days 0 hours 0 mins 0.432 secs]
Expand Down
4 changes: 2 additions & 2 deletions datafusion/sqllogictest/test_files/array.slt
Original file line number Diff line number Diff line change
Expand Up @@ -7220,12 +7220,12 @@ select generate_series('2021-01-01'::timestamp, '2021-01-01T15:00:00'::timestamp

# Other timestamp types are coerced to nanosecond
query ?
select generate_series(arrow_cast('2021-01-01'::timestamp, 'Timestamp(Second, None)'), '2021-01-01T15:00:00'::timestamp, INTERVAL '1' HOUR);
select generate_series(arrow_cast('2021-01-01'::timestamp, 'Timestamp(s)'), '2021-01-01T15:00:00'::timestamp, INTERVAL '1' HOUR);
----
[2021-01-01T00:00:00, 2021-01-01T01:00:00, 2021-01-01T02:00:00, 2021-01-01T03:00:00, 2021-01-01T04:00:00, 2021-01-01T05:00:00, 2021-01-01T06:00:00, 2021-01-01T07:00:00, 2021-01-01T08:00:00, 2021-01-01T09:00:00, 2021-01-01T10:00:00, 2021-01-01T11:00:00, 2021-01-01T12:00:00, 2021-01-01T13:00:00, 2021-01-01T14:00:00, 2021-01-01T15:00:00]

query ?
select generate_series('2021-01-01'::timestamp, arrow_cast('2021-01-01T15:00:00'::timestamp, 'Timestamp(Microsecond, None)'), INTERVAL '1' HOUR);
select generate_series('2021-01-01'::timestamp, arrow_cast('2021-01-01T15:00:00'::timestamp, 'Timestamp(µs)'), INTERVAL '1' HOUR);
----
[2021-01-01T00:00:00, 2021-01-01T01:00:00, 2021-01-01T02:00:00, 2021-01-01T03:00:00, 2021-01-01T04:00:00, 2021-01-01T05:00:00, 2021-01-01T06:00:00, 2021-01-01T07:00:00, 2021-01-01T08:00:00, 2021-01-01T09:00:00, 2021-01-01T10:00:00, 2021-01-01T11:00:00, 2021-01-01T12:00:00, 2021-01-01T13:00:00, 2021-01-01T14:00:00, 2021-01-01T15:00:00]

Expand Down
Loading