Closed grantatspothero closed 1 year ago
There is lack of rounding in the default column mapping being returned here
The code went in 342. In 346 we probably added validation (didn't check exact), but the behavior in 342-345 was silently incorrect leading to incorrect query results.
@findepi when you say "silently leading to incorrect query results" do you mean "silently rounding the precision of the timestamp" or do you mean "completely wrong timestamp values". Just trying to grasp the severity of the bug.
@grantatspothero for just SELECT queries it was returning correct results but if the value was compared with something, or aggregated, it could return incorrect ones. Of course, i am not saying this is the common case for timestamps, i am just pointing out https://github.com/trinodb/trino/pull/5742 is not to the root cause.
Closing as #15365
Querying columns of type
timestamp
fails in trino versions >v345.with the stacktrace:
I think this is because the redshift connector uses the basejdbc connector, which maps the
timestamp
redshift type to theTIMESTAMP_MILLIS
trino timestamp type. However, the redshifttimestamp
type has 6 digits of precision (not the 3 trino is expecting).https://github.com/trinodb/trino/blob/2bcf5d9e2d2642c5411e02c67e16f453fdff423a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/StandardColumnMappings.java#L575-L577
https://docs.aws.amazon.com/redshift/latest/dg/r_Datetime_types.html#r_Datetime_types-timestamp
This started causing queries to fail in v346 when this PR was introduced: https://github.com/trinodb/trino/pull/5742 Previously
SqlTimestamp. newInstance
would round the timestamp when the precision did not match the expected precision, now it explicitly fails.I think the fix should just be overriding
toColumnMapping
in the redshift client to handle timestamps with 6 digits of precision.See this thread for context: https://trinodb.slack.com/archives/CGB0QHWSW/p1610645172011400