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/12/20 07:54:19 UTC

[GitHub] [cassandra] blerer commented on a change in pull request #1368: WIP: CASSANDRA-17190:Changes to add support for string concatenations through the + operator

blerer commented on a change in pull request #1368:
URL: https://github.com/apache/cassandra/pull/1368#discussion_r772140067



##########
File path: src/java/org/apache/cassandra/cql3/functions/OperationFcts.java
##########
@@ -105,6 +106,22 @@ protected ByteBuffer executeOnNumerics(NumberType<?> resultType,
             {
                 return resultType.mod(leftType, left, rightType, right);
             }
+        },
+        CONCATENATION('+', "_concat")

Review comment:
       There is no need to add a new enum. You should simply implemente the  `excuteOnStrings` method in `ADD`. The internal name is hidden and does not play any important role.

##########
File path: src/java/org/apache/cassandra/db/marshal/StringType.java
##########
@@ -18,10 +18,29 @@
 
 package org.apache.cassandra.db.marshal;
 
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
 public abstract class StringType extends AbstractType<String>
 {
     protected StringType(ComparisonType comparisonType)
     {
         super(comparisonType);
     }
+
+    public abstract String charsetName();
+
+    public ByteBuffer concat(StringType leftType,
+                             ByteBuffer left,
+                             StringType rightType,
+                             ByteBuffer right) throws UnsupportedEncodingException
+    {
+        String leftS = new String(left.array(), leftType.charsetName());
+        String rightS = new String(right.array(), rightType.charsetName());
+
+        return ByteBufferUtil.bytes(leftS + rightS);
+    }

Review comment:
       {{ByteBuffer}} do not necessarily have array. If they direct buffer that code will not work. To get the `String`  value from the `ByteBuffer` you should use: `leftType.compose(left)` to convert a `String` back into a `ByteBuffer` you should use the `decompose` method.   ` return decompose(leftS + rightS);` 




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