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

Tyler Hobbs commented on CASSANDRA-11873:
-----------------------------------------

In {{CQL.textile}}, the {{jsonEncoding}} section needs to be updated for 
{{duration}} type.

In {{formatting.py}}, instead of using {{int64_unpack(val) + 
0x8000000000000000L}}, I believe we want {{uint64_unpack(val) - (2 ** 63)}}.

{{DurationTypeSerializer.serialize()}} needs a comment indicating that it's 
relying on overflow behavior.  This took me a while to figure out :)

On a related note, a few test cases which explicitly show the expected 
serializations for values could be useful.  I wrote this test while convincing 
myself the patch was correct, if you want to add it when committing:

{code}
    @Test
    public void testSerialization()
    {
        ByteBuffer serialized = 
DurationSerializer.instance.serialize(Long.MAX_VALUE);
        assertEquals(ByteBuffer.wrap(new byte[]{ (byte)0xff, (byte)0xff, 
(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff}),
                     serialized);

        serialized = DurationSerializer.instance.serialize(Long.MIN_VALUE);
        assertEquals(ByteBuffer.wrap(new byte[]{ (byte)0x00, (byte)0x00, 
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00}),
                serialized);

        serialized = DurationSerializer.instance.serialize(0L);
        assertEquals(ByteBuffer.wrap(new byte[]{ (byte)0x80, (byte)0x00, 
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00}),
                     serialized);

        serialized = DurationSerializer.instance.serialize(1L);
        assertEquals(ByteBuffer.wrap(new byte[]{ (byte)0x80, (byte)0x00, 
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01}),
                     serialized);

        serialized = DurationSerializer.instance.serialize(-1L);
        assertEquals(ByteBuffer.wrap(new byte[]{ (byte)0x7f, (byte)0xff, 
(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff}),
                     serialized);

        serialized = DurationSerializer.instance.serialize(Long.MIN_VALUE + 1L);
        assertEquals(ByteBuffer.wrap(new byte[]{ (byte)0x00, (byte)0x00, 
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01}),
                     serialized);
    }
{code}

These examples might be useful to put in the native protocol spec as well, just 
to ensure that driver authors implement the serialization correctly.  See 
section 6.23 (varint encoding) for an existing example.

Last, it looks like {{COPY FROM}} doesn't handle duration values when prepared 
statements are used, but I suppose we need {{duration}} support in the python 
driver for that to be supported.

> Add duration type
> -----------------
>
>                 Key: CASSANDRA-11873
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-11873
>             Project: Cassandra
>          Issue Type: Improvement
>          Components: CQL
>            Reporter: Benjamin Lerer
>            Assignee: Benjamin Lerer
>              Labels: client-impacting, doc-impacting
>             Fix For: 3.x
>
>
> For CASSANDRA-11871 or to allow queries with {{WHERE}} clause like:
> {{... WHERE reading_time < now() - 2h}}, we need to support some duration 
> type.
> In my opinion, it should be represented internally as a number of 
> microseconds.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to