Skip to content

Commit

Permalink
Minor: improve error message for interval subtraction
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed May 4, 2023
1 parent 4fbcc6d commit 1b3a4cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions datafusion/core/tests/sqllogictests/test_files/interval.slt
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ select '1 month'::interval + '1980-01-01T12:00:00'::timestamp;

# Exected error: interval (scalar) - date / timestamp (scalar)

query error DataFusion error: Error during planning: interval can't subtract timestamp/date
query error DataFusion error: Error during planning: Invalid interval subtraction: Interval\(MonthDayNano\) \- Date32
select '1 month'::interval - '1980-01-01'::date;

query error DataFusion error: Error during planning: interval can't subtract timestamp/date
query error DataFusion error: Error during planning: Invalid interval subtraction: Interval\(MonthDayNano\) \- Timestamp\(Nanosecond, None\)
select '1 month'::interval - '1980-01-01T12:00:00'::timestamp;

# interval (array) + date / timestamp (array)
Expand All @@ -349,10 +349,10 @@ select i + ts from t;
2000-02-01T00:01:00

# expected error interval (array) - date / timestamp (array)
query error DataFusion error: Error during planning: interval can't subtract timestamp/date
query error DataFusion error: Error during planning: Invalid interval subtraction: Interval\(MonthDayNano\) \- Date32
select i - d from t;

query error DataFusion error: Error during planning: interval can't subtract timestamp/date
query error DataFusion error: Error during planning: Invalid interval subtraction: Interval\(MonthDayNano\) \- Timestamp\(Nanosecond, None\)
select i - ts from t;


Expand All @@ -372,10 +372,10 @@ select '1 month'::interval + ts from t;
2000-03-01T00:00:00

# expected error interval (scalar) - date / timestamp (array)
query error DataFusion error: Error during planning: interval can't subtract timestamp/date
query error DataFusion error: Error during planning: Invalid interval subtraction: Interval\(MonthDayNano\) \- Date32
select '1 month'::interval - d from t;

query error DataFusion error: Error during planning: interval can't subtract timestamp/date
query error DataFusion error: Error during planning: Invalid interval subtraction: Interval\(MonthDayNano\) \- Timestamp\(Nanosecond, None\)
select '1 month'::interval - ts from t;

statement ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ SELECT '2000-01-01T00:00:00'::timestamp - '2010-01-01T00:00:00'::timestamp;
0 years 0 mons -3653 days 0 hours 0 mins 0.000000000 secs

# Interval - Timestamp => error
statement error DataFusion error: Error during planning: interval can't subtract timestamp/date
statement error DataFusion error: Error during planning: Invalid interval subtraction: Interval\(MonthDayNano\) \- Timestamp\(Nanosecond, None\)

SELECT i - ts1 from FOO;

Expand Down
6 changes: 3 additions & 3 deletions datafusion/expr/src/type_coercion/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ pub fn coerce_types(
|| is_interval(rhs_type) =>
{
if is_interval(lhs_type) && is_datetime(rhs_type) && *op == Operator::Minus {
return Err(DataFusionError::Plan(
"interval can't subtract timestamp/date".to_string(),
));
return Err(DataFusionError::Plan(format!(
"Invalid interval subtraction: {lhs_type} - {rhs_type}"
)));
}
temporal_add_sub_coercion(lhs_type, rhs_type, op)
}
Expand Down

0 comments on commit 1b3a4cf

Please sign in to comment.