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

Benjamin Lerer commented on CASSANDRA-12127:
--------------------------------------------

While working on this patch I ran into 2 other issues:
# in all the versions, for non-compact tables or compact tables with more than 
one clustering column, if the table was created with descending clustering 
order the ordering was not working properly when an empty ByteBuffer was used 
for a clustering column value. The problem was due to 
{{ReversedType::compareCustom()}}
# in 3.9, queries with desending {{ORDER BY}} and {{IN}} restrictions on the 
clustering column were not returning the proper results. The regression has 
been introduced in CASSANDRA-9986 and was affecting {{SSTableReversedIterator}}.

||Branch||utests||dtests||
|[2.1|https://github.com/apache/cassandra/compare/trunk...blerer:12127-2.1]|[2.1|http://cassci.datastax.com/view/Dev/view/blerer/job/blerer-12127-2.1-testall/]|[2.1|http://cassci.datastax.com/view/Dev/view/blerer/job/blerer-12127-2.1-dtest/]|
|[2.2|https://github.com/apache/cassandra/compare/trunk...blerer:12127-2.2]|[2.2|http://cassci.datastax.com/view/Dev/view/blerer/job/blerer-12127-2.2-testall/]|[2.2|http://cassci.datastax.com/view/Dev/view/blerer/job/blerer-12127-2.2-dtest/]|
|[3.0|https://github.com/apache/cassandra/compare/trunk...blerer:12127-3.0]|[3.0|http://cassci.datastax.com/view/Dev/view/blerer/job/blerer-12127-3.0-testall/]|[3.0|http://cassci.datastax.com/view/Dev/view/blerer/job/blerer-12127-3.0-dtest/]|
|[3.9|https://github.com/apache/cassandra/compare/trunk...blerer:12127-3.9]|[3.9|http://cassci.datastax.com/view/Dev/view/blerer/job/blerer-12127-3.9-testall/]|[3.9|http://cassci.datastax.com/view/Dev/view/blerer/job/blerer-12127-3.9-dtest/]|

The 2.1 and 2.2 patches:
* add support for queries on compact tables with EQ restrictions with empty 
value or slice restrictions with an empty value for end bound by returning no 
results
* add support for queries on compact tables with IN restrictions with an empty 
value by ignoring that value
* fix the handling of slice restrictions with an empty start bound on compact 
table with 1 clustering column
* fix the {{ReversedType::compareCustom()}} problem

The 3.0 patch:
* fix the {{ReversedType::compareCustom()}} problem

The 3.9 patch:
* fix the {{ReversedType::compareCustom()}} problem
* fix the {{SSTableReversedIterator}} problem

In the 2.2, 3.0 and 3.9 patches the {{SelectOrderByTest}} test have been modify 
to check the ordering behavior when the data are stored within the memtables 
and the SSTables.
   

> Queries with empty ByteBuffer values in clustering column restrictions fail 
> for non-composite compact tables
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-12127
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-12127
>             Project: Cassandra
>          Issue Type: Bug
>          Components: CQL
>            Reporter: Benjamin Lerer
>            Assignee: Benjamin Lerer
>             Fix For: 2.1.x, 2.2.x, 3.0.x, 3.x
>
>         Attachments: 12127.txt
>
>
> For the following table:
> {code}
> CREATE TABLE myTable (pk int,
>                       c blob,
>                       value int,
>                       PRIMARY KEY (pk, c)) WITH COMPACT STORAGE;
> INSERT INTO myTable (pk, c, value) VALUES (1, textAsBlob('1'), 1);
> INSERT INTO myTable (pk, c, value) VALUES (1, textAsBlob('2'), 2);
> {code}
> The query: {{SELECT * FROM myTable WHERE pk = 1 AND c > textAsBlob('');}}
> Will result in the following Exception:
> {code}
> java.lang.ClassCastException: 
> org.apache.cassandra.db.composites.Composites$EmptyComposite cannot be cast 
> to org.apache.cassandra.db.composites.CellName
>       at 
> org.apache.cassandra.db.composites.AbstractCellNameType.cellFromByteBuffer(AbstractCellNameType.java:188)
>       at 
> org.apache.cassandra.db.composites.AbstractSimpleCellNameType.makeCellName(AbstractSimpleCellNameType.java:125)
>       at 
> org.apache.cassandra.db.composites.AbstractCellNameType.makeCellName(AbstractCellNameType.java:254)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.makeExclusiveSliceBound(SelectStatement.java:1206)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.applySliceRestriction(SelectStatement.java:1214)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.processColumnFamily(SelectStatement.java:1292)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.process(SelectStatement.java:1259)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.processResults(SelectStatement.java:299)
>       [...]
> {code}
> The query: {{SELECT * FROM myTable WHERE pk = 1 AND c < textAsBlob('');}}
> Will return 2 rows instead of 0.
> The query: {{SELECT * FROM myTable WHERE pk = 1 AND c = textAsBlob('');}}
> {code}
> java.lang.AssertionError
>       at 
> org.apache.cassandra.db.composites.SimpleDenseCellNameType.create(SimpleDenseCellNameType.java:60)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.addSelectedColumns(SelectStatement.java:853)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.getRequestedColumns(SelectStatement.java:846)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.makeFilter(SelectStatement.java:583)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.getSliceCommands(SelectStatement.java:383)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.getPageableCommand(SelectStatement.java:253)
>       [...]
> {code}
> I checked 2.0 and {{SELECT * FROM myTable  WHERE pk = 1 AND c > 
> textAsBlob('');}} works properly but {{SELECT * FROM myTable WHERE pk = 1 AND 
> c < textAsBlob('');}} return the same wrong results than in 2.1.
> The {{SELECT * FROM myTable WHERE pk = 1 AND c = textAsBlob('');}} is 
> rejected if a clear error message: {{Invalid empty value for clustering 
> column of COMPACT TABLE}}.
> As it is not possible to insert an empty ByteBuffer value within the 
> clustering column of a non-composite compact tables those queries do not
> have a lot of meaning. {{SELECT * FROM myTable WHERE pk = 1 AND c < 
> textAsBlob('');}} and {{SELECT * FROM myTable WHERE pk = 1 AND c = 
> textAsBlob('');}} will return nothing
> and {{SELECT * FROM myTable WHERE pk = 1 AND c > textAsBlob('');}} will 
> return the entire partition (pk = 1).
> In my opinion those queries should probably all be rejected as it seems that 
> the fact that {{SELECT * FROM myTable  WHERE pk = 1 AND c > textAsBlob('');}} 
> was accepted in {{2.0}} was due to a bug.
> I am of course open to discussion.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to