You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "adelapena (via GitHub)" <gi...@apache.org> on 2023/06/08 11:08:47 UTC

[GitHub] [cassandra] adelapena commented on a diff in pull request #2386: CASSANDRA-18566: Avoid unnecessary deserialization of terminal arguments when executing CQL functions

adelapena commented on code in PR #2386:
URL: https://github.com/apache/cassandra/pull/2386#discussion_r1222888226


##########
src/java/org/apache/cassandra/cql3/functions/ToJsonFct.java:
##########
@@ -54,14 +54,28 @@ private ToJsonFct(String name, AbstractType<?> argType)
         super(name, UTF8Type.instance, argType);
     }
 
-    public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters) throws InvalidRequestException
+    @Override
+    public Arguments newArguments(ProtocolVersion version)
     {
-        assert parameters.size() == 1 : format("Expected 1 argument for %s(), but got %d", name.name, parameters.size());
-        ByteBuffer parameter = parameters.get(0);
-        if (parameter == null)
+        return new FunctionArguments(version, (protocolVersion, buffer) -> {
+            AbstractType<?> argType = argTypes.get(0);
+
+            if (buffer == null || (!buffer.hasRemaining() && argType.isEmptyValueMeaningless()))
+                return null;
+
+            return argTypes.get(0).toJSONString(buffer, protocolVersion);
+        });
+    }
+
+    @Override
+    public ByteBuffer execute(Arguments arguments) throws InvalidRequestException
+    {
+        assert arguments.size() == 1 : "Expected 1 argument for toJson(), but got " + arguments.size();

Review Comment:
   It isn't, the factory should have caught it before. Removed.



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