-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: The inconsistency between scalar and array on the cast decimal to timestamp #16539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
327530b
1810f7d
92f26f1
d89f0f9
0b084f3
51ba6e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -530,12 +530,12 @@ SELECT to_timestamp(123456789.123456789) as c1, cast(123456789.123456789 as time | |
| query PPP | ||
| SELECT to_timestamp(arrow_cast(1.1, 'Decimal128(2,1)')) as c1, cast(arrow_cast(1.1, 'Decimal128(2,1)') as timestamp) as c2, arrow_cast(1.1, 'Decimal128(2,1)')::timestamp as c3; | ||
| ---- | ||
| 1970-01-01T00:00:01.100 1970-01-01T00:00:01.100 1970-01-01T00:00:01.100 | ||
| 1970-01-01T00:00:01.100 1970-01-01T00:00:00.000000001 1970-01-01T00:00:00.000000001 | ||
|
|
||
| query PPP | ||
| SELECT to_timestamp(arrow_cast(-1.1, 'Decimal128(2,1)')) as c1, cast(arrow_cast(-1.1, 'Decimal128(2,1)') as timestamp) as c2, arrow_cast(-1.1, 'Decimal128(2,1)')::timestamp as c3; | ||
| ---- | ||
| 1969-12-31T23:59:58.900 1969-12-31T23:59:58.900 1969-12-31T23:59:58.900 | ||
| 1969-12-31T23:59:58.900 1969-12-31T23:59:59.999999999 1969-12-31T23:59:59.999999999 | ||
|
|
||
| query PPP | ||
| SELECT to_timestamp(arrow_cast(0.0, 'Decimal128(2,1)')) as c1, cast(arrow_cast(0.0, 'Decimal128(2,1)') as timestamp) as c2, arrow_cast(0.0, 'Decimal128(2,1)')::timestamp as c3; | ||
|
|
@@ -545,12 +545,12 @@ SELECT to_timestamp(arrow_cast(0.0, 'Decimal128(2,1)')) as c1, cast(arrow_cast(0 | |
| query PPP | ||
| SELECT to_timestamp(arrow_cast(1.23456789, 'Decimal128(9,8)')) as c1, cast(arrow_cast(1.23456789, 'Decimal128(9,8)') as timestamp) as c2, arrow_cast(1.23456789, 'Decimal128(9,8)')::timestamp as c3; | ||
| ---- | ||
| 1970-01-01T00:00:01.234567890 1970-01-01T00:00:01.234567890 1970-01-01T00:00:01.234567890 | ||
| 1970-01-01T00:00:01.234567890 1970-01-01T00:00:00.000000001 1970-01-01T00:00:00.000000001 | ||
|
|
||
| query PPP | ||
| SELECT to_timestamp(arrow_cast(123456789.123456789, 'Decimal128(18,9)')) as c1, cast(arrow_cast(123456789.123456789, 'Decimal128(18,9)') as timestamp) as c2, arrow_cast(123456789.123456789, 'Decimal128(18,9)')::timestamp as c3; | ||
| ---- | ||
| 1973-11-29T21:33:09.123456784 1973-11-29T21:33:09.123456784 1973-11-29T21:33:09.123456784 | ||
| 1973-11-29T21:33:09.123456784 1970-01-01T00:00:00.123456789 1970-01-01T00:00:00.123456789 | ||
|
|
||
|
|
||
| # from_unixtime | ||
|
|
@@ -3529,3 +3529,67 @@ select to_timestamp('-1'); | |
|
|
||
| query error DataFusion error: Arrow error: Parser error: Error parsing timestamp from '\-1': timestamp must contain at least 10 characters | ||
| select to_timestamp(arrow_cast('-1', 'Utf8')); | ||
|
|
||
| query P | ||
| SELECT CAST(CAST(1 AS decimal(17,2)) AS timestamp(3)) AS a UNION ALL | ||
| SELECT CAST(CAST(one AS decimal(17,2)) AS timestamp(3)) AS a FROM (VALUES (1)) t(one); | ||
| ---- | ||
| 1970-01-01T00:00:00.001 | ||
| 1970-01-01T00:00:00.001 | ||
|
Comment on lines
+3534
to
+3538
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the desired semantics when casting from decimal(p,s) to timestamp(q)? For example, when casting from With the current implementation, the decimal's fraction seems to be discarded.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what the semantics should be when casting from decimal --> timestamp. I recommend that we add the tests @findepi suggests and file a follow on ticket to clarify this point |
||
|
|
||
| query P | ||
| SELECT arrow_cast(CAST(1 AS decimal(17,2)), 'Timestamp(Nanosecond, None)') AS a UNION ALL | ||
| SELECT arrow_cast(CAST(one AS decimal(17,2)), 'Timestamp(Nanosecond, None)') AS a FROM (VALUES (1)) t(one); | ||
| ---- | ||
| 1970-01-01T00:00:00.000000001 | ||
| 1970-01-01T00:00:00.000000001 | ||
|
|
||
| query P | ||
| SELECT arrow_cast(CAST(1 AS decimal(17,2)), 'Timestamp(Microsecond, None)') AS a UNION ALL | ||
| SELECT arrow_cast(CAST(one AS decimal(17,2)), 'Timestamp(Microsecond, None)') AS a FROM (VALUES (1)) t(one); | ||
| ---- | ||
| 1970-01-01T00:00:00.000001 | ||
| 1970-01-01T00:00:00.000001 | ||
|
|
||
| query P | ||
| SELECT arrow_cast(CAST(1 AS decimal(17,2)), 'Timestamp(Millisecond, None)') AS a UNION ALL | ||
| SELECT arrow_cast(CAST(one AS decimal(17,2)), 'Timestamp(Millisecond, None)') AS a FROM (VALUES (1)) t(one); | ||
| ---- | ||
| 1970-01-01T00:00:00.001 | ||
| 1970-01-01T00:00:00.001 | ||
|
|
||
| query P | ||
| SELECT arrow_cast(CAST(1 AS decimal(17,2)), 'Timestamp(Second, None)') AS a UNION ALL | ||
| SELECT arrow_cast(CAST(one AS decimal(17,2)), 'Timestamp(Second, None)') AS a FROM (VALUES (1)) t(one); | ||
| ---- | ||
| 1970-01-01T00:00:01 | ||
| 1970-01-01T00:00:01 | ||
|
|
||
|
|
||
| query P | ||
| SELECT arrow_cast(CAST(1.123 AS decimal(17,3)), 'Timestamp(Nanosecond, None)') AS a UNION ALL | ||
| SELECT arrow_cast(CAST(one AS decimal(17,3)), 'Timestamp(Nanosecond, None)') AS a FROM (VALUES (1.123)) t(one); | ||
| ---- | ||
| 1970-01-01T00:00:00.000000001 | ||
| 1970-01-01T00:00:00.000000001 | ||
|
|
||
| query P | ||
| SELECT arrow_cast(CAST(1.123 AS decimal(17,3)), 'Timestamp(Microsecond, None)') AS a UNION ALL | ||
| SELECT arrow_cast(CAST(one AS decimal(17,3)), 'Timestamp(Microsecond, None)') AS a FROM (VALUES (1.123)) t(one); | ||
| ---- | ||
| 1970-01-01T00:00:00.000001 | ||
| 1970-01-01T00:00:00.000001 | ||
|
|
||
| query P | ||
| SELECT arrow_cast(CAST(1.123 AS decimal(17,3)), 'Timestamp(Millisecond, None)') AS a UNION ALL | ||
| SELECT arrow_cast(CAST(one AS decimal(17,3)), 'Timestamp(Millisecond, None)') AS a FROM (VALUES (1.123)) t(one); | ||
| ---- | ||
| 1970-01-01T00:00:00.001 | ||
| 1970-01-01T00:00:00.001 | ||
|
|
||
| query P | ||
| SELECT arrow_cast(CAST(1.123 AS decimal(17,3)), 'Timestamp(Second, None)') AS a UNION ALL | ||
| SELECT arrow_cast(CAST(one AS decimal(17,3)), 'Timestamp(Second, None)') AS a FROM (VALUES (1.123)) t(one); | ||
| ---- | ||
| 1970-01-01T00:00:01 | ||
| 1970-01-01T00:00:01 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is pretty nice fixing bugs by deleting code 🏆