trino: Proper truncation missing in casts to varchar(x)
presto:default> select cast(bigint '12345678' as varchar(2));
_col0
-------
12
but …
presto:default> select cast(bigint '12345678' as varchar(2)) = '12';
_col0
-------
false
This is because https://github.com/prestosql/presto/blob/c74b775e103a7a239aafef1b7ca15fe6370495fe/presto-main/src/main/java/io/prestosql/type/BigintOperators.java#L270-L276
should consider x (@LiteralParameter("x") long x) and truncate the result to make sure no more than x characters are returned.
Same probably applies to casts from other types to varchar.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 16 (15 by maintainers)
Is someone already working on this? I would like to give it a try…
Is this https://github.com/trinodb/trino/issues/5015 a duplicate of this?
I think you can think of any floating point as having infinite number of trailing zeros. In this context you won’t lose any precision.
@ankitdixit each case needs to be looked at separately.
If you want to work on this, I would propose to raise a separate PR for each case being fixed. (all integer types {{tinyint,smallint,integer,bigint}} should be considered as one case; same for floating point: {{real,double}})