-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 1 commit
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 |
|---|---|---|
|
|
@@ -3069,7 +3069,7 @@ impl ScalarValue { | |
| ScalarValue::Decimal128(Some(decimal_value), _, scale), | ||
| DataType::Timestamp(time_unit, None), | ||
| ) => { | ||
| let scale_factor = 10_i128.pow(*scale as u32); | ||
| let scale_factor = 10_i128.pow(*scale as u32 + 3); | ||
|
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. Does this depend on the timestamp precision (time unit)? Can you please add tests for other units? Do we need this special casing at all for casting decimal to timestamp?
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 think the underlying arrow kernel may not support casting decimal --> timestamp (I bet this is something spark related) 🤔
Contributor
Author
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.
Contributor
Author
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.
@findepi you are right, it's time unit related. I updated code.
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.
Can be! So how does this work when the value is not constant-folded? Can the same code be executed also in constant-folding case? |
||
| let seconds = decimal_value / scale_factor; | ||
| let fraction = decimal_value % scale_factor; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -421,12 +421,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.001100 1970-01-01T00:00:00.001100 | ||
|
|
||
| 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.998900 1969-12-31T23:59:59.998900 | ||
|
|
||
| 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; | ||
|
|
@@ -436,12 +436,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.001234567 1970-01-01T00:00:00.001234567 | ||
|
|
||
| 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-02T10:17:36.789123456 1970-01-02T10:17:36.789123456 | ||
|
|
||
|
|
||
| # from_unixtime | ||
|
|
@@ -3420,3 +3420,8 @@ 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 B | ||
| SELECT CAST(CAST(x AS decimal(17,2)) AS timestamp(3)) = CAST(CAST(1 AS decimal(17,2)) AS timestamp(3)) from (values (1)) t(x); | ||
| ---- | ||
|
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. Formatting like this will help see why these should be equal. Also it's enough to project the values. (They should be equal, but also they should be particular values). |
||
| true | ||
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.
In #16639 i tried to clear the path for more changes here.
If and once that one merged, we should be able to remove this whole code block.
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.
#16639 is now merged.
please remove the whole
let scalar_array = match (self, target_type) { ... }block, replacing it with justself.to_array()?.