[jira] [Commented] (CASSANDRA-12149) NullPointerException on SELECT using index with token restrictions fully overriden by other PK restrictions
[ https://issues.apache.org/jira/browse/CASSANDRA-12149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15605572#comment-15605572 ] Benjamin Lerer commented on CASSANDRA-12149: Thanks for the new patch. +1 > NullPointerException on SELECT using index with token restrictions fully > overriden by other PK restrictions > > > Key: CASSANDRA-12149 > URL: https://issues.apache.org/jira/browse/CASSANDRA-12149 > Project: Cassandra > Issue Type: Bug >Reporter: Andrey Konstantinov >Assignee: Alex Petrov > Attachments: CASSANDRA-12149.txt > > > If I execute the sequence of queries (see the attached file), Cassandra > aborts a connection reporting NPE on server side. SELECT query without token > range filter works, but does not work when token range filter is specified. > My intent was to issue multiple SELECT queries targeting the same single > partition, filtered by a column indexed by SASI, partitioning results by > different token ranges. > Output from cqlsh on SELECT is the following: > {code} > cqlsh> SELECT namespace, entity, timestamp, feature1, feature2 FROM > mykeyspace.myrecordtable WHERE namespace = 'ns2' AND entity = 'entity2' AND > feature1 > 11 AND feature1 < 31 AND token(namespace, entity) <= > 9223372036854775807; > ServerError: message="java.lang.NullPointerException"> > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (CASSANDRA-12149) NullPointerException on SELECT using index with token restrictions fully overriden by other PK restrictions
[ https://issues.apache.org/jira/browse/CASSANDRA-12149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15605164#comment-15605164 ] Alex Petrov commented on CASSANDRA-12149: - Thank you for the review. Great find! I've added one more test, which would actually yield the results between token and non-token restriction. I've fixed it by not falling back to non-token restrictions when filtering, since because of token restriction we already know the ring part that should be queried. |[12149-trunk|https://github.com/ifesdjeen/cassandra/tree/12149-trunk]|[dtest|http://cassci.datastax.com/job/ifesdjeen-12149-trunk-dtest/]|[utest|http://cassci.datastax.com/job/ifesdjeen-12149-trunk-testall/]| |[12149-3.X|https://github.com/ifesdjeen/cassandra/tree/12149-3.X]|[dtest|http://cassci.datastax.com/job/ifesdjeen-12149-3.X-dtest/]|[utest|http://cassci.datastax.com/job/ifesdjeen-12149-3.X-testall/]| > NullPointerException on SELECT using index with token restrictions fully > overriden by other PK restrictions > > > Key: CASSANDRA-12149 > URL: https://issues.apache.org/jira/browse/CASSANDRA-12149 > Project: Cassandra > Issue Type: Bug >Reporter: Andrey Konstantinov >Assignee: Alex Petrov > Attachments: CASSANDRA-12149.txt > > > If I execute the sequence of queries (see the attached file), Cassandra > aborts a connection reporting NPE on server side. SELECT query without token > range filter works, but does not work when token range filter is specified. > My intent was to issue multiple SELECT queries targeting the same single > partition, filtered by a column indexed by SASI, partitioning results by > different token ranges. > Output from cqlsh on SELECT is the following: > {code} > cqlsh> SELECT namespace, entity, timestamp, feature1, feature2 FROM > mykeyspace.myrecordtable WHERE namespace = 'ns2' AND entity = 'entity2' AND > feature1 > 11 AND feature1 < 31 AND token(namespace, entity) <= > 9223372036854775807; > ServerError: message="java.lang.NullPointerException"> > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (CASSANDRA-12149) NullPointerException on SELECT using index with token restrictions fully overriden by other PK restrictions
[ https://issues.apache.org/jira/browse/CASSANDRA-12149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15603000#comment-15603000 ] Benjamin Lerer commented on CASSANDRA-12149: While thinking about it, I realized that the {{TokenFilter::isOnToken}} method might not return the correct result. If we have a query like {{SELECT * FROM %s WHERE token(a, b) > token(10, 10) AND a < 8 AND b < 8 ALLOW FILTERING}}, as {{a}} and {{b}} have a non token restriction the {{TokenFilter::isOnToken}} method will return {{false}}. Due to that, Cassandra will believe that the query is not a range query and as the call to {{TokenFilter::needFiltering}} will return {{true}} in {{StatementRestrictions:getPartitionKeyBound}} the token restriction will be completely ignored. The problem can be reproduced with the following test: {code} @Test public void testFilteringOnAllPartitionKeysWithTokenRestriction() throws Throwable { createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY ((a, b), c))"); for (int i = 0; i < 10; i++) { execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", i, i, i, i); execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", i, i + 10, i + 10, i + 10); } assertEmpty(execute("SELECT * FROM %s WHERE token(a, b) > token(10, 10)")); assertEmpty(execute("SELECT * FROM %s WHERE token(a, b) > token(10, 10) AND a < 8 AND b < 8 ALLOW FILTERING")); } {code} Sorry for not noticing the problem sooner. > NullPointerException on SELECT using index with token restrictions fully > overriden by other PK restrictions > > > Key: CASSANDRA-12149 > URL: https://issues.apache.org/jira/browse/CASSANDRA-12149 > Project: Cassandra > Issue Type: Bug >Reporter: Andrey Konstantinov >Assignee: Alex Petrov > Attachments: CASSANDRA-12149.txt > > > If I execute the sequence of queries (see the attached file), Cassandra > aborts a connection reporting NPE on server side. SELECT query without token > range filter works, but does not work when token range filter is specified. > My intent was to issue multiple SELECT queries targeting the same single > partition, filtered by a column indexed by SASI, partitioning results by > different token ranges. > Output from cqlsh on SELECT is the following: > {code} > cqlsh> SELECT namespace, entity, timestamp, feature1, feature2 FROM > mykeyspace.myrecordtable WHERE namespace = 'ns2' AND entity = 'entity2' AND > feature1 > 11 AND feature1 < 31 AND token(namespace, entity) <= > 9223372036854775807; > ServerError: message="java.lang.NullPointerException"> > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (CASSANDRA-12149) NullPointerException on SELECT using index with token restrictions fully overriden by other PK restrictions
[ https://issues.apache.org/jira/browse/CASSANDRA-12149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15595502#comment-15595502 ] Alex Petrov commented on CASSANDRA-12149: - Thanks for the review. Sure, I can't see how adding this check may hurt. I've also updated comment on the class to make it clearer that we "fall back" to non-token restrictions when possible and re-triggered CI. > NullPointerException on SELECT using index with token restrictions fully > overriden by other PK restrictions > > > Key: CASSANDRA-12149 > URL: https://issues.apache.org/jira/browse/CASSANDRA-12149 > Project: Cassandra > Issue Type: Bug >Reporter: Andrey Konstantinov >Assignee: Alex Petrov > Attachments: CASSANDRA-12149.txt > > > If I execute the sequence of queries (see the attached file), Cassandra > aborts a connection reporting NPE on server side. SELECT query without token > range filter works, but does not work when token range filter is specified. > My intent was to issue multiple SELECT queries targeting the same single > partition, filtered by a column indexed by SASI, partitioning results by > different token ranges. > Output from cqlsh on SELECT is the following: > {code} > cqlsh> SELECT namespace, entity, timestamp, feature1, feature2 FROM > mykeyspace.myrecordtable WHERE namespace = 'ns2' AND entity = 'entity2' AND > feature1 > 11 AND feature1 < 31 AND token(namespace, entity) <= > 9223372036854775807; > ServerError: message="java.lang.NullPointerException"> > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (CASSANDRA-12149) NullPointerException on SELECT using index with token restrictions fully overriden by other PK restrictions
[ https://issues.apache.org/jira/browse/CASSANDRA-12149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15592089#comment-15592089 ] Benjamin Lerer commented on CASSANDRA-12149: Thanks for the patch. I wonder if the {{TokenFilter::hasBound}} and {{TokenFilter::isInclusive}} methods should not be updated in a similar way. They are not called if {{isOnToken}} is {{false}} but I believe that it will make the code more bullet proof. The {{TokenFilter::bound}} method can be simplified to: {code} return isOnToken() ? tokenRestriction.bounds(bound, options) : restrictions.bounds(bound, options); {code} > NullPointerException on SELECT using index with token restrictions fully > overriden by other PK restrictions > > > Key: CASSANDRA-12149 > URL: https://issues.apache.org/jira/browse/CASSANDRA-12149 > Project: Cassandra > Issue Type: Bug >Reporter: Andrey Konstantinov >Assignee: Alex Petrov > Attachments: CASSANDRA-12149.txt > > > If I execute the sequence of queries (see the attached file), Cassandra > aborts a connection reporting NPE on server side. SELECT query without token > range filter works, but does not work when token range filter is specified. > My intent was to issue multiple SELECT queries targeting the same single > partition, filtered by a column indexed by SASI, partitioning results by > different token ranges. > Output from cqlsh on SELECT is the following: > {code} > cqlsh> SELECT namespace, entity, timestamp, feature1, feature2 FROM > mykeyspace.myrecordtable WHERE namespace = 'ns2' AND entity = 'entity2' AND > feature1 > 11 AND feature1 < 31 AND token(namespace, entity) <= > 9223372036854775807; > ServerError: message="java.lang.NullPointerException"> > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (CASSANDRA-12149) NullPointerException on SELECT using index with token restrictions fully overriden by other PK restrictions
[ https://issues.apache.org/jira/browse/CASSANDRA-12149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15545436#comment-15545436 ] Alex Petrov commented on CASSANDRA-12149: - This problem was not related strictly to SASI, so I have adjusted the title accordingly. Example code that'd fail: {code} @Test public void testTokenAndIndex() throws Throwable { createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))"); createIndex("CREATE INDEX ON %s(c)"); for (int i = 0; i < 10; i++) { execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", i, i, i, i); execute("INSERT INTO %s (a,b,c,d) VALUES (?, ?, ?, ?)", i, i + 10, i + 10, i + 10); } beforeAndAfterFlush(() -> { assertRows(execute("SELECT * FROM %s WHERE token(a) > token(8) AND a = 9 AND c = 9 ALLOW FILTERING"), row(9, 9, 9, 9)); assertRows(execute("SELECT * FROM %s WHERE token(a) > token(8) AND a > 8 ALLOW FILTERING"), row(9, 9, 9, 9), row(9, 19, 19, 19)); }); } {code} We could use non-token restrictions when token restrictions are fully overriden by other results. |[12419-trunk|https://github.com/ifesdjeen/cassandra/tree/12419-trunk]|[dtest|http://cassci.datastax.com/job/ifesdjeen-12419-trunk-dtest/]|[utest|http://cassci.datastax.com/job/ifesdjeen-12419-trunk-testall/]| |[12419-3.0|https://github.com/ifesdjeen/cassandra/tree/12419-3.0]|[dtest|http://cassci.datastax.com/job/ifesdjeen-12419-3.0-dtest/]|[utest|http://cassci.datastax.com/job/ifesdjeen-12419-3.0-testall/]| |[12419-3.X|https://github.com/ifesdjeen/cassandra/tree/12419-3.X]|[dtest|http://cassci.datastax.com/job/ifesdjeen-12419-3.X-dtest/]|[utest|http://cassci.datastax.com/job/ifesdjeen-12419-3.X-testall/]| > NullPointerException on SELECT using index with token restrictions fully > overriden by other PK restrictions > > > Key: CASSANDRA-12149 > URL: https://issues.apache.org/jira/browse/CASSANDRA-12149 > Project: Cassandra > Issue Type: Bug >Reporter: Andrey Konstantinov >Assignee: Alex Petrov > Attachments: CASSANDRA-12149.txt > > > If I execute the sequence of queries (see the attached file), Cassandra > aborts a connection reporting NPE on server side. SELECT query without token > range filter works, but does not work when token range filter is specified. > My intent was to issue multiple SELECT queries targeting the same single > partition, filtered by a column indexed by SASI, partitioning results by > different token ranges. > Output from cqlsh on SELECT is the following: > {code} > cqlsh> SELECT namespace, entity, timestamp, feature1, feature2 FROM > mykeyspace.myrecordtable WHERE namespace = 'ns2' AND entity = 'entity2' AND > feature1 > 11 AND feature1 < 31 AND token(namespace, entity) <= > 9223372036854775807; > ServerError: message="java.lang.NullPointerException"> > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)