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

Manish Ghildiyal commented on CASSANDRA-17190:
----------------------------------------------

I have added a method to StringType

 
{code:java}
public abstract String charsetName();{code}
Different specific types of StringType would return the value accordingly, like 
ASCIIType returns "US-ASCII". This way I don't need to add function for each 
combination (ascii/ascii, ascii/text, text/ascii and text/text) in 
OperationFcts. I just added:
{code:java}
protected ByteBuffer excuteOnStrings(StringType resultType,
StringType leftType,
ByteBuffer left,
StringType rightType,
ByteBuffer right) throws UnsupportedEncodingException
{
throw new UnsupportedOperationException();
}{code}
..and corresponding OPERATION
{code:java}
CONCATENATION('+', "_concat")
{
@Override
protected ByteBuffer executeOnNumerics(NumberType<?> resultType, NumberType<?> 
leftType, ByteBuffer left, NumberType<?> rightType, ByteBuffer right) {
//TODO: not sure what goes here
}

@Override
protected ByteBuffer excuteOnStrings(StringType resultType,
StringType leftType,
ByteBuffer left,
StringType rightType,
ByteBuffer right) throws UnsupportedEncodingException {
return resultType.concat(leftType, left, rightType, right);
}
};{code}
If this is correct approach, would add another OPERATION for '-' too.

An example of CSQL query would also help.

 

> Add support for String contatenation through the "+" operator
> -------------------------------------------------------------
>
>                 Key: CASSANDRA-17190
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-17190
>             Project: Cassandra
>          Issue Type: Improvement
>          Components: CQL/Interpreter
>            Reporter: Benjamin Lerer
>            Assignee: Manish Ghildiyal
>            Priority: Normal
>              Labels: AdventCalendar2021, lhf
>             Fix For: 4.x
>
>
> Since 4.0, Cassandra support operations on numeric types and on some temporal 
> types.
> We should add support for string concatenations through the {{+}} operator.
> +Additional information for newcomers:+
> Cassandra has 2 string types: {{Text}} ({{UTF8Type}})  and ascii 
> ({{AsciiType}}) both are sub-classes of ({{StringType}}). In order to add 
> support for string concatenation you will need to add a new method to 
> {{StringType}} and modify {{OperationFcts}} to add the new functions (one for 
> each combination of types: ascii/ascii, ascii/text, text/ascii and text/text).
> The unit test should be added to {{OperationFctsTest}}.
> To allow for concatenating constants (eg: SELECT v1 + ' ' + v2 FROM ...) you 
> will need to add a {{getPreferedTypeFor}} method to 
> {{org.apache.cassandra.Constants.Type.STRING}} that determine the constant 
> type based on its content (ascii or not).      



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to