You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2021/10/18 01:33:13 UTC

[GitHub] [cassandra] subkanthi opened a new pull request #1275: [CASSANDRA- 17029] Added function toDate to convert from toDate

subkanthi opened a new pull request #1275:
URL: https://github.com/apache/cassandra/pull/1275


   - Added toDate(bigint)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [cassandra] subkanthi commented on a change in pull request #1275: [CASSANDRA- 17029] Added function toDate to convert from toDate

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #1275:
URL: https://github.com/apache/cassandra/pull/1275#discussion_r731726127



##########
File path: test/unit/org/apache/cassandra/cql3/functions/TimeFctsTest.java
##########
@@ -141,6 +142,16 @@ public void testTimestampToDate()
         assertEquals(DATE.toInstant().toEpochMilli(), SimpleDateType.instance.toTimeInMillis(output));
     }
 
+    @Test
+    public void testBigIntegerToDate()
+    {
+        long milliSeconds = DATE_TIME.toInstant().toEpochMilli();
+
+        ByteBuffer input = IntegerType.instance.fromString(Long.toString(milliSeconds));

Review comment:
       Made the change thanks again for reviewing.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [cassandra] subkanthi commented on a change in pull request #1275: [CASSANDRA- 17029] Added function toDate to convert from toDate

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #1275:
URL: https://github.com/apache/cassandra/pull/1275#discussion_r733043711



##########
File path: src/java/org/apache/cassandra/cql3/functions/TimeFcts.java
##########
@@ -162,6 +164,28 @@ public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> para
        };
    }
 
+    /**
+     * Creates a function that convert a value of the specified type into a <code>DATE</code>.
+     * @param type the temporal type
+     * @return a function that convert a value of the specified type into a <code>DATE</code>.
+     */
+    public static final NativeScalarFunction toDate(LongType type)
+    {
+        return new NativeScalarFunction("todate", SimpleDateType.instance, type)
+        {
+            public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters)
+            {
+                ByteBuffer bb = parameters.get(0);
+                if (bb == null || !bb.hasRemaining())
+                    return null;
+
+                long milliSeconds = new BigInteger(bb.array()).longValue();

Review comment:
       Thanks changed to public.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [cassandra] subkanthi closed pull request #1275: [CASSANDRA- 17029] Added function toDate to convert from toDate

Posted by GitBox <gi...@apache.org>.
subkanthi closed pull request #1275:
URL: https://github.com/apache/cassandra/pull/1275


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [cassandra] blerer commented on a change in pull request #1275: [CASSANDRA- 17029] Added function toDate to convert from toDate

Posted by GitBox <gi...@apache.org>.
blerer commented on a change in pull request #1275:
URL: https://github.com/apache/cassandra/pull/1275#discussion_r730930303



##########
File path: src/java/org/apache/cassandra/cql3/functions/TimeFcts.java
##########
@@ -162,6 +164,28 @@ public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> para
        };
    }
 
+    /**
+     * Creates a function that convert a value of the specified type into a <code>DATE</code>.
+     * @param type the temporal type
+     * @return a function that convert a value of the specified type into a <code>DATE</code>.
+     */
+    public static final NativeScalarFunction toDate(LongType type)
+    {
+        return new NativeScalarFunction("todate", SimpleDateType.instance, type)
+        {
+            public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters)
+            {
+                ByteBuffer bb = parameters.get(0);
+                if (bb == null || !bb.hasRemaining())
+                    return null;
+
+                long milliSeconds = new BigInteger(bb.array()).longValue();

Review comment:
       You should use `LongType.instance.toLong(bb)`. There is no guaranty that the `ByteBuffer `has an array and you should rely on the C* type to avoid bad surprises.  

##########
File path: test/unit/org/apache/cassandra/cql3/functions/TimeFctsTest.java
##########
@@ -141,6 +142,16 @@ public void testTimestampToDate()
         assertEquals(DATE.toInstant().toEpochMilli(), SimpleDateType.instance.toTimeInMillis(output));
     }
 
+    @Test
+    public void testBigIntegerToDate()
+    {
+        long milliSeconds = DATE_TIME.toInstant().toEpochMilli();
+
+        ByteBuffer input = IntegerType.instance.fromString(Long.toString(milliSeconds));

Review comment:
       You shouls use `LongType.instance.decompose(milliseconds)`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [cassandra] subkanthi commented on a change in pull request #1275: [CASSANDRA- 17029] Added function toDate to convert from toDate

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #1275:
URL: https://github.com/apache/cassandra/pull/1275#discussion_r731724117



##########
File path: src/java/org/apache/cassandra/cql3/functions/TimeFcts.java
##########
@@ -162,6 +164,28 @@ public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> para
        };
    }
 
+    /**
+     * Creates a function that convert a value of the specified type into a <code>DATE</code>.
+     * @param type the temporal type
+     * @return a function that convert a value of the specified type into a <code>DATE</code>.
+     */
+    public static final NativeScalarFunction toDate(LongType type)
+    {
+        return new NativeScalarFunction("todate", SimpleDateType.instance, type)
+        {
+            public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters)
+            {
+                ByteBuffer bb = parameters.get(0);
+                if (bb == null || !bb.hasRemaining())
+                    return null;
+
+                long milliSeconds = new BigInteger(bb.array()).longValue();

Review comment:
       Thanks @blerer , it looks like toLong() is protected, ended up changing to use `ByteBufferUtil.toLong`, hopefully thats fine




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [cassandra] blerer commented on a change in pull request #1275: [CASSANDRA- 17029] Added function toDate to convert from toDate

Posted by GitBox <gi...@apache.org>.
blerer commented on a change in pull request #1275:
URL: https://github.com/apache/cassandra/pull/1275#discussion_r731776347



##########
File path: src/java/org/apache/cassandra/cql3/functions/TimeFcts.java
##########
@@ -162,6 +164,28 @@ public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> para
        };
    }
 
+    /**
+     * Creates a function that convert a value of the specified type into a <code>DATE</code>.
+     * @param type the temporal type
+     * @return a function that convert a value of the specified type into a <code>DATE</code>.
+     */
+    public static final NativeScalarFunction toDate(LongType type)
+    {
+        return new NativeScalarFunction("todate", SimpleDateType.instance, type)
+        {
+            public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters)
+            {
+                ByteBuffer bb = parameters.get(0);
+                if (bb == null || !bb.hasRemaining())
+                    return null;
+
+                long milliSeconds = new BigInteger(bb.array()).longValue();

Review comment:
       Feel free to change the `protected` to `public` :-)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [cassandra] subkanthi closed pull request #1275: [CASSANDRA- 17029] Added function toDate to convert from toDate

Posted by GitBox <gi...@apache.org>.
subkanthi closed pull request #1275:
URL: https://github.com/apache/cassandra/pull/1275


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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