You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Adam Holmberg (Jira)" <ji...@apache.org> on 2020/08/11 21:15:00 UTC

[jira] [Commented] (CASSANDRA-15976) Incorrect parsing of the timestamp with less than 3 digits in the milliseconds

    [ https://issues.apache.org/jira/browse/CASSANDRA-15976?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17175843#comment-17175843 ] 

Adam Holmberg commented on CASSANDRA-15976:
-------------------------------------------

The the bug seems to be with DateUtils.parseStrictly [here|[https://github.com/apache/cassandra/blob/54ebb19720225e176bc93e6dbc9e8943fa5e3bfc/src/java/org/apache/cassandra/serializers/TimestampSerializer.java#L159]].

There is no format pattern for single digit precision, which is why parsing fails. Confusingly there is also no pattern for two digits, but parsing succeeds with the [three digit pattern|[https://github.com/apache/cassandra/blob/54ebb19720225e176bc93e6dbc9e8943fa5e3bfc/src/java/org/apache/cassandra/serializers/TimestampSerializer.java#L79]]

Even with one- and two-digit patterns added, the parsing "succeeds" but comes back with the incorrect value as shown in the description.

> Incorrect parsing of the timestamp with less than 3 digits in the milliseconds
> ------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-15976
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-15976
>             Project: Cassandra
>          Issue Type: Bug
>          Components: CQL/Interpreter
>            Reporter: Alex Ott
>            Assignee: Adam Holmberg
>            Priority: Normal
>             Fix For: 4.0-beta2
>
>
> (tested on 4.0-beta1, but should be in all versions)
> Right now, Cassandra incorrectly handles timestamps with less than 3 digits in the milliseconds part.  Timestamps (valid from the Java point of view (see below output in Scala) are either rejected (if we have 1 digit only), or incorrectly parsed when 2 digits are specified:
> {noformat}
> cqlsh> create table test.tm (id int primary key, tm timestamp);
> cqlsh> insert into test.tm(id, tm) values (2, '2020-07-24T10:00:01.2Z');
> InvalidRequest: Error from server: code=2200 [Invalid query] message="Unable to coerce '2020-07-24T10:00:01.2Z' to a formatted date (long)"
> cqlsh> insert into test.tm(id, tm) values (1, '2020-07-24T10:00:01.12Z');
> cqlsh> select * from test.tm;
>  id | tm
> ----+---------------------------------
>   1 | 2020-07-24 10:00:01.012000+0000
> (1 rows)
> {noformat}
> Checking with Instant:
> {noformat}
> scala> java.time.Instant.parse("2020-07-24T10:00:01.12Z")
> res0: java.time.Instant = 2020-07-24T10:00:01.120Z
> scala> java.time.Instant.parse("2020-07-24T10:00:01.2Z")
> res1: java.time.Instant = 2020-07-24T10:00:01.200Z
> {noformat}
> Imho it should be fixed (Cc: [~aholmber])



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org