datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

add support for casting string to decimal

Open kmitchener opened this issue 2 years ago • 1 comments

Is your feature request related to a problem or challenge? Please describe what you are trying to do. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] (This section helps Arrow developers understand the context and why for this feature, in addition to the what)

Describe the solution you'd like A clear and concise description of what you want to happen. Would like to be able to cast string to decimal as is supported by float types.

❯ select arrow_typeof('1.1'::decimal);
Internal("Unsupported CAST from Utf8 to Decimal128(38, 10)")

but should work like it does for float:

❯ select arrow_typeof('1.1'::double);
+--------------------------+
| arrowtypeof(Utf8("1.1")) |
+--------------------------+
| Float64                  |
+--------------------------+
1 row in set. Query took 0.010 seconds.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

kmitchener avatar Sep 14 '22 12:09 kmitchener

about the cast, you can refer the https://github.com/apache/arrow-rs/issues/1043 https://github.com/apache/arrow-datafusion/issues/1443

we don't support the cast/try_cast from decimal to utf8 or utf8 to decimal

you can implement this in the arrow-rs kernel about the cast. @kmitchener

liukun4515 avatar Sep 15 '22 00:09 liukun4515

Here is a PR to add the appropriate support in arrow-rs: https://github.com/apache/arrow-rs/pull/3106 👍

alamb avatar Nov 14 '22 20:11 alamb

❯ select arrow_typeof('1.1'::decimal);
+--------------------------+
| arrowtypeof(Utf8("1.1")) |
+--------------------------+
| Decimal128(38, 10)       |
+--------------------------+
1 row in set. Query took 0.030 seconds.

Dandandan avatar May 26 '23 12:05 Dandandan

❯ select arrow_typeof('1.1'::decimal);
+--------------------------+
| arrowtypeof(Utf8("1.1")) |
+--------------------------+
| Decimal128(38, 10)       |
+--------------------------+
1 row in set. Query took 0.030 seconds.

Maybe someone can help clarify...Why does this come out as Decimal128(38, 10)? Where is the 38 and 10 coming from

finlaydotb avatar Jun 01 '24 14:06 finlaydotb

The 38 is the maximum precision of Decimal128 in arrow

https://docs.rs/arrow-schema/51.0.0/src/arrow_schema/datatype.rs.html#676

The 10 is the default scale: https://docs.rs/arrow-schema/51.0.0/src/arrow_schema/datatype.rs.html#689

alamb avatar Jun 01 '24 19:06 alamb