datafusion
datafusion copied to clipboard
add support for casting string to decimal
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.
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
Here is a PR to add the appropriate support in arrow-rs: https://github.com/apache/arrow-rs/pull/3106 👍
❯ select arrow_typeof('1.1'::decimal);
+--------------------------+
| arrowtypeof(Utf8("1.1")) |
+--------------------------+
| Decimal128(38, 10) |
+--------------------------+
1 row in set. Query took 0.030 seconds.
❯ 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
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