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/13 18:44:00 UTC

[jira] [Commented] (CASSANDRA-14853) Change default timestamp format to output only milliseconds, not microseconds

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

Adam Holmberg commented on CASSANDRA-14853:
-------------------------------------------

I looked at the code for this briefly and there's not a great way to do it with the way that formatting is parameterized right now.

By default it will use [this format|https://github.com/apache/cassandra/blob/54ebb19720225e176bc93e6dbc9e8943fa5e3bfc/pylib/cqlshlib/formatting.py#L115] to format `datetime`.

[strptime|https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes] does not provide a way of specifying precision in the pattern.

Because of the way the [format function|https://github.com/apache/cassandra/blob/54ebb19720225e176bc93e6dbc9e8943fa5e3bfc/pylib/cqlshlib/formatting.py#L115] is parameterized, we can't simply pick the returned string apart and remove digits.

Separately from this, the parsing I've introduced in CASSANDRA-15976 actually does parse the format output by cqlsh, so wrapping a value back works. 

I suggest we leave this formatting alone for now and let the better parsing on the server take care of this problem. 

{noformat}
cqlsh:test> create table t1(tm timestamp primary key, t text);
cqlsh:test> insert into t1(tm, t) values(toTimestamp(now()), 't');
cqlsh:test> insert into t1(tm, t) values(toTimestamp(now()), 't2');
cqlsh:test> select * from t1;

 tm                          | t
-----------------------------+----
 2020-08-13 18:38:34.3f+0000 | t2
 2020-08-13 18:38:27.3f+0000 |  t

(2 rows)
cqlsh:test> select * from t1 where tm = '2020-08-13 18:38:34.598000+0000';

 tm                              | t
---------------------------------+----
 2020-08-13 18:38:34.598000+0000 | t2

(1 rows)
cqlsh:test>
{noformat}

wdyt?

> Change default timestamp format to output only milliseconds, not microseconds
> -----------------------------------------------------------------------------
>
>                 Key: CASSANDRA-14853
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-14853
>             Project: Cassandra
>          Issue Type: Improvement
>          Components: Tool/cqlsh
>         Environment: Reproduced in trunk
>            Reporter: Alex Ott
>            Priority: Normal
>              Labels: cqlsh
>
> By default cqlsh outputs the timestamp column with microseconds precision, like this:
> {noformat}
> cqlsh:test> create table t1(tm timestamp primary key, t text);
> cqlsh:test> insert into t1(tm, t) values(toTimestamp(now()), 't');
> cqlsh:test> insert into t1(tm, t) values(toTimestamp(now()), 't2');
> cqlsh:test> SELECT * from t1;
>  tm                              | t
> ---------------------------------+----
>  2018-10-27 18:01:54.738000+0000 | t2
>  2018-10-27 18:01:52.599000+0000 |  t
> (2 rows)
> {noformat}
> But if I want to use the value that is output on the screen in my query, I get an error:
> {noformat}
> cqlsh:test> select * from t1 where tm = '2018-10-27 18:01:54.738000+0000';
> InvalidRequest: Error from server: code=2200 [Invalid query] message="Unable to coerce '2018-10-27 18:01:54.738000+0000' to a formatted date (long)"
> {noformat}
> But if I manually round it to milliseconds, then everything works:
> {noformat}
> cqlsh:test> select * from t1 where tm = '2018-10-27 18:01:54.738+0000';
>  tm                              | t
> ---------------------------------+----
>  2018-10-27 18:01:54.738000+0000 | t2
> (1 rows)
> {noformat}
> It would be much easier user's experience if we use the same format for output & input data, because right now this leads to errors, that often not really understandable by novice users.
> P.S. I know about cqlshrc, but not every user has it configured.



--
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