You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "ROCHETEAU Antoine (Jira)" <ji...@apache.org> on 2022/01/07 08:37:00 UTC

[jira] [Comment Edited] (CASSANDRA-10537) CONTAINS and CONTAINS KEY support for Lightweight Transactions

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

ROCHETEAU Antoine edited comment on CASSANDRA-10537 at 1/7/22, 8:36 AM:
------------------------------------------------------------------------

Hello, 

I just take a look into this improvement and so far this is the current state of my working branch:

Use of *CONTAINS* operator is allowed on collection (evaluation of the condition is performed on lists, sets and maps values)
Use of *CONTAINS KEY* operator is allowed on map only (evaluation is performed on map keyset)

So these conditions are now valid and working:

{{IF list_column CONTAINS 'bar'}}
{{IF set_column CONTAINS 'bar'}}
{{IF map_column CONTAINS 'bar'}}
{{IF map_column CONTAINS KEY 'foo'}}

These are not and will throw an {_}InvalidRequestException{_}:

{{IF list_column CONTAINS KEY 'bar'}}
{{IF set_column CONTAINS KEY 'bar'}}
{{IF text_column CONTAINS 'bar'}}

Finally, these are still throwing a {_}SyntaxException{_}:

{{IF list_column[1] CONTAINS 'bar'}}
{{IF map_column['foo'] CONTAINS 'bar'}}
{{IF udt_column.a CONTAINS 'bar' }}

Modifications are quite light so i haven't started the refactoring of _ColumnCondition_ mentioned by [~ifesdjeen] (even if i'm agree on its benefits).

-Should I submit a pull request in this current state or did i miss something ?- 

[PR 1380|https://github.com/apache/cassandra/pull/1380]

Best regards,

Antoine


was (Author: antoine rocheteau):
Hello, 

I just take a look into this improvement and so far this is the current state of my working branch:

Use of *CONTAINS* operator is allowed on collection (evaluation of the condition is performed on lists, sets and maps values)
Use of *CONTAINS KEY* operator is allowed on map only (evaluation is performed on map keyset)

So these conditions are now valid and working:

{{IF list_column CONTAINS 'bar'}}
{{IF set_column CONTAINS 'bar'}}
{{IF map_column CONTAINS 'bar'}}
{{IF map_column CONTAINS KEY 'foo'}}

These are not and will throw an {_}InvalidRequestException{_}:

{{IF list_column CONTAINS KEY 'bar'}}
{{IF set_column CONTAINS KEY 'bar'}}
{{IF text_column CONTAINS 'bar'}}

Finally, these are still throwing a {_}SyntaxException{_}:

{{IF list_column[1] CONTAINS 'bar'}}
{{IF map_column['foo'] CONTAINS 'bar'}}
{{IF udt_column.a CONTAINS 'bar' }}

Modifications are quite light so i haven't started the refactoring of _ColumnCondition_ mentioned by [~ifesdjeen] (even if i'm agree on its benefits).

Should I submit a pull request in this current state or did i miss something ? 

Best regards,

Antoine

> CONTAINS and CONTAINS KEY support for Lightweight Transactions
> --------------------------------------------------------------
>
>                 Key: CASSANDRA-10537
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-10537
>             Project: Cassandra
>          Issue Type: Improvement
>          Components: Legacy/CQL
>            Reporter: Nimi Wariboko Jr.
>            Priority: Normal
>              Labels: AdventCalendar2021, CQL, lhf
>             Fix For: 4.x
>
>
> Conditional updates currently do not support CONTAINS and CONTAINS KEY conditions. Queries such as 
> {{UPDATE mytable SET somefield = 4 WHERE pk = 'pkv' IF set_column CONTAINS 5;}}
> are not possible.
> Would it also be possible to support the negation of these (ex. testing that a value does not exist inside a set)?
> +Additional Information for newcomers:+
> Negation should not be supported as for the moment we do not support it within restrictions either.
> One way to approch this bug is to use test driven development. You can modify {{InsertUpdateIfConditionCollectionsTest}} to allow CONTAINS and CONTAINS KEY operators and go through the different failures.
> The following changes will need to be done.
> * The {{columnCondition}} rule from the ANTLR {{Parser.g}} file should be updated to accept {{containsOperator}}.
> * {{ColumnCondition.Raw#prepareTerms}} should be modified in the case where the operator is a CONTAINS or CONTAINS KEY as the {{receiver}} is not the collection but keys or values of the collection. Look at {{SingleColumnRelation#makeCollectionReceiver}}.
> * {{ColumnCollection.MultiCellCollectionBound#valueAppliesTo}} will need to be changed for {{Map}} and {{Set}} to process CONTAINS operators.  
>  



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

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