You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Benjamin Lerer (JIRA)" <ji...@apache.org> on 2019/01/22 14:27:00 UTC

[jira] [Commented] (CASSANDRA-14344) Support filtering using IN restrictions

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

Benjamin Lerer commented on CASSANDRA-14344:
--------------------------------------------

Sorry, for the delay in my response.

What I had in mind was simply to have the {{isSatisfiedBy}} method using {{AbstractType.compareForCQL}} to perform the contains check on instead of deserializing the complete list each time.

If you add the following method to {{ListSerializer}}:
{code}
    public boolean anyMatch(ByteBuffer serializedList, Predicate<ByteBuffer> predicate)
    {
        try
        {
            ByteBuffer input = serializedList.duplicate();
            int limit = input.limit();
            int size = readCollectionSize(input, ProtocolVersion.V3);

            for (int i = 0; i < size; i++)
            {
                int elementSize = input.getInt();
                if (elementSize < 0)
                    continue;

                input.limit(input.position() + elementSize);
                if (predicate.test(input))
                    return true;

                input.limit(limit);
                input.position(input.position() + elementSize);
            }
            return false;
        }
        catch (BufferUnderflowException e)
        {
            throw new MarshalException("Not enough bytes to read a list");
        }
    }
{code} 

Then you can implements {{isSatisfied}} as :
{code}
        public boolean isSatisfiedBy(AbstractType<?> type, ByteBuffer leftOperand, ByteBuffer rightOperand)
        {
            ListSerializer<?> serializer = ListType.getInstance(type, false).getSerializer();
            return serializer.anyMatch(rightOperand, r -> type.compareForCQL(leftOperand, r) == 0);
        }
{code}

The problem with {{null}} can simply be handled by adding a check in the {{addRowFilterTo}} method. 



> Support filtering using IN restrictions
> ---------------------------------------
>
>                 Key: CASSANDRA-14344
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-14344
>             Project: Cassandra
>          Issue Type: New Feature
>          Components: Legacy/CQL
>            Reporter: Dikang Gu
>            Assignee: Venkata Harikrishna Nukala
>            Priority: Major
>             Fix For: 4.x
>
>         Attachments: 14344-trunk-2.txt, 14344-trunk-inexpression-approach-2.txt, 14344-trunk-inexpression-approach.txt, 14344-trunk.txt
>
>
> Support IN filter query like this:
>  
> CREATE TABLE ks1.t1 (
>     key int,
>     col1 int,
>     col2 int,
>     value int,
>     PRIMARY KEY (key, col1, col2)
> ) WITH CLUSTERING ORDER BY (col1 ASC, col2 ASC)
>  
> cqlsh:ks1> select * from t1 where key = 1 and col2 in (1) allow filtering;
>  
>  key | col1 | col2 | value
> -----+------+------+-------
>    1 |    1 |    1 |     1
>    1 |    2 |    1 |     3
>  
> (2 rows)
> cqlsh:ks1> select * from t1 where key = 1 and col2 in (1, 2) allow filtering;
> *{color:#ff0000}InvalidRequest: Error from server: code=2200 [Invalid query] message="IN restrictions are not supported on indexed columns"{color}*
> cqlsh:ks1>



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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