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

Aleksey Yeschenko commented on CASSANDRA-6276:
----------------------------------------------

Unfortunately, we can't allow dropping a component from the comparator, 
including dropping individual collection columns from ColumnToCollectionType.

If we do allow that, and have pre-existing data of that type, C* simply 
wouldn't know how to compare those:

{code:title=ColumnToCollectionType.java}
    public int compareCollectionMembers(ByteBuffer o1, ByteBuffer o2, 
ByteBuffer collectionName)
    {
        CollectionType t = defined.get(collectionName);
        if (t == null)
            throw new 
RuntimeException(ByteBufferUtil.bytesToHex(collectionName) + " is not defined 
as a collection");

        return t.nameComparator().compare(o1, o2);
    }
{code}

A simple algorithm to hit the RTE:
1. create table test (id int primary key, col1 map<int, int>, col2 set<int>);
2. insert into test (id, col1, col2) VALUES ( 0, \{0:0, 1:1\}, \{0,1\});
3. flush
4. update test set col1 = col1 + \{2:2\}, col2 = col2 + \{2\} where id = 0;
5. flush
6. select * from test;

{noformat}
java.lang.RuntimeException: 636f6c31 is not defined as a collection
        at 
org.apache.cassandra.db.marshal.ColumnToCollectionType.compareCollectionMembers(ColumnToCollectionType.java:79)
 ~[main/:na]
        at 
org.apache.cassandra.db.composites.CompoundSparseCellNameType$WithCollection.compare(CompoundSparseCellNameType.java:296)
 ~[main/:na]
        at 
org.apache.cassandra.db.composites.AbstractCellNameType$1.compare(AbstractCellNameType.java:61)
 ~[main/:na]
        at 
org.apache.cassandra.db.composites.AbstractCellNameType$1.compare(AbstractCellNameType.java:58)
 ~[main/:na]
        at 
org.apache.cassandra.utils.MergeIterator$Candidate.compareTo(MergeIterator.java:154)
 ~[main/:na]
        at 
org.apache.cassandra.utils.MergeIterator$Candidate.compareTo(MergeIterator.java:131)
 ~[main/:na]
{noformat}

For this reason alone we can't allow getting rid of a comparator component.

However, even if we did, and allowed to create a different collection with the 
same name, we'd hit a different issue: the new collection's comparator would be 
used to compare potentially incompatible types. Now, your unit tests aren't 
failing b/c most of our comparators assume valid values and don't perform extra 
validation, then use something like ByteBufferUtil.compareUnsigned() to compare 
the values, which doesn't fail and will just stop once the shortest BB gets 
exhausted. One exception is tuples/usertypes - they *do* expect at least length 
to be there, and will throw an exception.

Example:
1. create table test (id int primary key, col set<boolean>);
2. insert into test (id, col) values (0, \{true,false\});
3. alter table test drop col;
4. create type test (f1 int);
5. alter table test add col set<test>;
6. update test set col = col + \{ \{f1 : 0 \} \} where id = 0;
7. select * from test;

{noformat}
java.nio.BufferUnderflowException: null
        at java.nio.Buffer.nextGetIndex(Buffer.java:498) ~[na:1.7.0_65]
        at java.nio.HeapByteBuffer.getInt(HeapByteBuffer.java:355) 
~[na:1.7.0_65]
        at org.apache.cassandra.db.marshal.TupleType.compare(TupleType.java:80) 
~[main/:na]
        at org.apache.cassandra.db.marshal.TupleType.compare(TupleType.java:38) 
~[main/:na]
        at 
org.apache.cassandra.db.marshal.ColumnToCollectionType.compareCollectionMembers(ColumnToCollectionType.java:81)
 ~[main/:na]
        at 
org.apache.cassandra.db.composites.CompoundSparseCellNameType$WithCollection.compare(CompoundSparseCellNameType.java:296)
 ~[main/:na]
        at 
org.apache.cassandra.db.composites.AbstractCellNameType$1.compare(AbstractCellNameType.java:61)
 ~[main/:na]
        at 
org.apache.cassandra.db.composites.AbstractCellNameType$1.compare(AbstractCellNameType.java:58)
 ~[main/:na]
        at 
org.apache.cassandra.utils.MergeIterator$Candidate.compareTo(MergeIterator.java:154)
 ~[main/:na]
{noformat}

> CQL: Map can not be created with the same name as a previously dropped list
> ---------------------------------------------------------------------------
>
>                 Key: CASSANDRA-6276
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-6276
>             Project: Cassandra
>          Issue Type: Bug
>         Environment:  Cassandra 2.0.2 | CQL spec 3.1.0
> centos 64 bit
> Java(TM) SE Runtime Environment (build 1.7.0-b147)
>            Reporter: Oli Schacher
>            Assignee: Benjamin Lerer
>            Priority: Minor
>              Labels: cql
>             Fix For: 2.1.1
>
>         Attachments: CASSANDRA-6276.txt
>
>
> If create a list, drop it and create a map with the same name, i get "Bad 
> Request: comparators do not match or are not compatible."
> {quote}
> cqlsh:os_test1> create table thetable(id timeuuid primary key, somevalue 
> text);
> cqlsh:os_test1> alter table thetable add mycollection list<text>;  
> cqlsh:os_test1> alter table thetable drop mycollection;
> cqlsh:os_test1> alter table thetable add mycollection map<text,text>;  
> Bad Request: comparators do not match or are not compatible.
> {quote}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to