You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Sylvain Lebresne (JIRA)" <ji...@apache.org> on 2012/11/04 18:44:11 UTC

[jira] [Created] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Sylvain Lebresne created CASSANDRA-4909:
-------------------------------------------

             Summary: Bug when composite index is created in a table having collections
                 Key: CASSANDRA-4909
                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
             Project: Cassandra
          Issue Type: Bug
            Reporter: Sylvain Lebresne
            Assignee: Sylvain Lebresne
             Fix For: 1.2.0 beta 2


CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.

We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Posted by "Sylvain Lebresne (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CASSANDRA-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sylvain Lebresne updated CASSANDRA-4909:
----------------------------------------

    Attachment: 4909.txt
    
> Bug when composite index is created in a table having collections
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-4909
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 1.2.0 beta 1
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>             Fix For: 1.2.0 beta 2
>
>         Attachments: 4909.txt
>
>
> CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.
> We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Posted by "Henrik Ring (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13490697#comment-13490697 ] 

Henrik Ring edited comment on CASSANDRA-4909 at 11/5/12 4:09 PM:
-----------------------------------------------------------------

Working at the ApacheConEU Hackathon. Suggestions for testing the patch.
Below is my understanding of the issue and the solution as well as a suggestion for how to test it.

The patch changes the code so the exception: InvalidRequestException("Indexes on collections are no yet supported")
is raised if an attempt is made to create an index on an collection type column.

Creation of indexes on tables that have collection column values is allowed as long as 
the collection columns are NOT part of the index. 

Tests:
In CQL3 create CF with 2 collection type columns "A1" and "A2" and 2 noncollection type columns "B1" and "B2".
Create index on A1 or A2 should fail. 
Create an index on B1 or B2 should succeed.
Insert data.
Select on column with index to ensure index is in place.

-- Should succeed
CREATE KEYSPACE TEST_CASSANDRA_4909_KS;

-- Should succeed
USE TEST_CASSANDRA_4909_KS; 

-- Should succeed
CREATE TABLE TEST_CASSANDRA_4909_TLB1
   (A1 set<text>,
    A2 set<text>,
    B1 text,
    B2 text,
    PRIMARY KEY B1);

-- Should fail: InvalidRequestException("Indexes on collections are no yet supported")
CREATE INDEX TEST_CASSANDRA_4909_TLB1_INX1 ON TEST_CASSANDRA_4909_TLB1 (A1);

-- Should Succeed:
CREATE INDEX TEST_CASSANDRA_4909_TLB1_INX2 ON TEST_CASSANDRA_4909_TLB1 (B2);

-- Wait for schema agreement.

-- Should succeed:
INSERT INTO TEST_CASSANDRA_4909_TLB1 (A1, A2, B1, B2)
       VALUES({'A1-ROW1-ELM-1', 'A1-ROW1-ELM2'}, {'A2-ROW1-ELM-1', 'A2-ROW1-ELM2'}, 'B1-ROW1', 'B2-ROW1' );

-- Should succeed:
INSERT INTO TEST_CASSANDRA_4909_TLB1 (A1, A2, B1, B2)
       VALUES({'A1-ROW2-ELM-1', 'A1-ROW2-ELM2'}, {'A2-ROW2-ELM-1', 'A2-ROW2-ELM2'}, 'B1-ROW2', 'B2-ROW2' );

-- Should succeed (ensure index is in place):
SELECT * FROM TEST_CASSANDRA_4909_TLB1 WHERE B2 = 'B2-ROW2';

-- Should succeed:
DROP TABLE TEST_CASSANDRA_4909_TLB1;

                
      was (Author: henrikring):
    Working at the ApacheConEU Hackathon. Suggestions for testing the patch.
Below is my understanding of the issue and the solution and a suggestion for how to test it.

The patch changes the code so the exception: InvalidRequestException("Indexes on collections are no yet supported")
is raised if an attempt is made to create an index on an collection type column.

Creation of indexes on tables that have collection column values is allowed as long as 
the collection columns are NOT part of the index. 

Tests:
In CQL3 create CF with 2 collection type columns "A1" and "A2" and 2 noncollection type columns "B1" and "B2".
Create index on A1 or A2 should fail. 
Create an index on B1 or B2 should succeed.
Insert data.
Select on column with index to ensure index is in place.

-- Should succeed
CREATE KEYSPACE TEST_CASSANDRA_4909_KS;

-- Should succeed
USE TEST_CASSANDRA_4909_KS; 

-- Should succeed
CREATE TABLE TEST_CASSANDRA_4909_TLB1
   (A1 set<text>,
    A2 set<text>,
    B1 text,
    B2 text,
    PRIMARY KEY B1);

-- Should fail: InvalidRequestException("Indexes on collections are no yet supported")
CREATE INDEX TEST_CASSANDRA_4909_TLB1_INX1 ON TEST_CASSANDRA_4909_TLB1 (A1);

-- Should Succeed:
CREATE INDEX TEST_CASSANDRA_4909_TLB1_INX2 ON TEST_CASSANDRA_4909_TLB1 (B2);

-- Wait for schema agreement.

-- Should succeed:
INSERT INTO TEST_CASSANDRA_4909_TLB1 (A1, A2, B1, B2)
       VALUES({'A1-ROW1-ELM-1', 'A1-ROW1-ELM2'}, {'A2-ROW1-ELM-1', 'A2-ROW1-ELM2'}, 'B1-ROW1', 'B2-ROW1' );

-- Should succeed:
INSERT INTO TEST_CASSANDRA_4909_TLB1 (A1, A2, B1, B2)
       VALUES({'A1-ROW2-ELM-1', 'A1-ROW2-ELM2'}, {'A2-ROW2-ELM-1', 'A2-ROW2-ELM2'}, 'B1-ROW2', 'B2-ROW2' );

-- Should succeed (ensure index is in place):
SELECT * FROM TEST_CASSANDRA_4909_TLB1 WHERE B2 = 'B2-ROW2';

-- Should succeed:
DROP TABLE TEST_CASSANDRA_4909_TLB1;

                  
> Bug when composite index is created in a table having collections
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-4909
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 1.2.0 beta 1
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>             Fix For: 1.2.0 beta 2
>
>         Attachments: 4909.txt
>
>
> CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.
> We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Posted by "Henrik Ring (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13491002#comment-13491002 ] 

Henrik Ring edited comment on CASSANDRA-4909 at 11/5/12 10:51 PM:
------------------------------------------------------------------

Now I got it running and ran the test - it passed:

{code:title=CASSANDRA_4909.java|borderStyle=solid}
package org.apache.cassandra;

import org.apache.cassandra.thrift.*;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.sql.Connection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class CASSANDRA_4909 {
    public static final Charset charset = Charset.forName("UTF-8");
    public static final CharsetEncoder encoder = charset.newEncoder();
    public static final CharsetDecoder decoder = charset.newDecoder();

    private static final String KEYSPACE_NAME = "test_cassandra_4909_ks";
    private static final String TABLE_NAME = "test_cassandra_4909_tlb1";
    private static Connection _con = null;
    private static Cassandra.Client _client = null;


    @BeforeClass
    public static void setUp() throws Exception {
        TTransport tr = new TFramedTransport(new TSocket("localhost", 9160));
        TProtocol proto = new TBinaryProtocol(tr);
        _client = new Cassandra.Client(proto);
        tr.open();
        _client.set_cql_version("3.0.0");
        _client.set_keyspace("system");

        // Create Keyspace
        executeCQL_legacy("CREATE KEYSPACE " + KEYSPACE_NAME + " WITH strategy_class = SimpleStrategy AND strategy_options:replication_factor = 1");

        // Switch default KS
        _client.set_keyspace(KEYSPACE_NAME);
    }

    @AfterClass
    public static void tearDown() throws Exception {
        if (_client != null) {
            executeCQL3("DROP KEYSPACE " + KEYSPACE_NAME);
        }
    }

    @org.junit.Test
    public void test1() throws Exception {
        assertNotNull("Expected a connection to be defined?", _client);

        executeCQL3("CREATE TABLE " + TABLE_NAME + "\n" +
                "(A1 set<text>,\n" +
                "A2 set<text>,\n" +
                "B1 text PRIMARY KEY,\n" +
                "B2 text);");

        //Should fail: InvalidRequestException("Indexes on collections are no yet supported")
        try {
            executeCQL3("CREATE INDEX " + TABLE_NAME + "_INX1 ON " + TABLE_NAME + " (A1)");
        } catch (InvalidRequestException e) {
            assertEquals("Unexpected message in exception", "Indexes on collections are no yet supported", e.getWhy());
        }

        //Should succeed
        executeCQL3("CREATE INDEX " + TABLE_NAME + "_INX2 ON " + TABLE_NAME + " (B2)");

        executeCQL3("INSERT INTO " + TABLE_NAME + " (A1, A2, B1, B2)\n" +
                "VALUES({'A1-ROW1-ELM-1', 'A1-ROW1-ELM2'}, {'A2-ROW1-ELM-1', 'A2-ROW1-ELM2'}, 'B1-ROW1', 'B2-ROW1' );\n");

        executeCQL3("INSERT INTO " + TABLE_NAME + " (A1, A2, B1, B2)\n" +
                "VALUES({'A1-ROW2-ELM-1', 'A1-ROW2-ELM2'}, {'A2-ROW2-ELM-1', 'A2-ROW2-ELM2'}, 'B1-ROW2', 'B2-ROW2' );\n");

        // The select would fail with InvalidRequestException(why:No indexed columns present in by-columns clause with Equal operator)
        // if the index is not in effect.
        CqlResult r = executeCQL3("SELECT B1 FROM " + TABLE_NAME + " WHERE B2 = 'B2-ROW2';");
        List<CqlRow> rows = r.getRows();
        CqlRow row = rows.get(0);
        Column c_b1 = row.getColumns().get(0); // B1
        String B1_value = bb2str(c_b1.bufferForValue());
        assertEquals("Expected other value for B1", "B1-ROW2", B1_value);
        int dummy = 0;
    }

    public static String bb2str(ByteBuffer buffer) {
        String data = "";
        try {
            int old_position = buffer.position();
            data = decoder.decode(buffer).toString();
            buffer.position(old_position);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return data;
    }

    private static ByteBuffer str2bb(String str) {
        try {
            return ByteBuffer.wrap(str.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UTF-8 is unavailable?", e);
        }
    }

    private static CqlResult executeCQL_legacy(String cql) throws Exception {
        return _client.execute_cql_query(str2bb(cql), Compression.NONE);
    }

    private static CqlResult executeCQL3(String cql) throws Exception {
        return _client.execute_cql3_query(str2bb(cql), Compression.NONE, ConsistencyLevel.ALL);
    }
}
{code}
                
      was (Author: henrikring):
    Now I got it running and ran the test - it passed:

{code:title=CASSANDRA_4909.java|borderStyle=solid}
package org.apache.cassandra;

import org.apache.cassandra.thrift.*;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.sql.Connection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class CASSANDRA_4909 {
    public static final Charset charset = Charset.forName("UTF-8");
    public static final CharsetEncoder encoder = charset.newEncoder();
    public static final CharsetDecoder decoder = charset.newDecoder();

    private static final String KEYSPACE_NAME = "test_cassandra_4909_ks";
    private static final String TABLE_NAME = "test_cassandra_4909_tlb1";
    private static Connection _con = null;
    private static Cassandra.Client _client = null;


    @BeforeClass
    public static void setUp() throws Exception {
        TTransport tr = new TFramedTransport(new TSocket("localhost", 9160));
        TProtocol proto = new TBinaryProtocol(tr);
        _client = new Cassandra.Client(proto);
        tr.open();
        _client.set_cql_version("3.0.0");
        _client.set_keyspace("system");

        // Create Keyspace
        executeCQL_legacy("CREATE KEYSPACE " + KEYSPACE_NAME + " WITH strategy_class = SimpleStrategy AND strategy_options:replication_factor = 1");

        // Switch default KS
        _client.set_keyspace(KEYSPACE_NAME);
    }

    @AfterClass
    public static void tearDown() throws Exception {
        if (_client != null) {
            executeCQL3("DROP KEYSPACE " + KEYSPACE_NAME);
        }
    }

    @org.junit.Test
    public void test1() throws Exception {
        assertNotNull("Expected a connection to be defined?", _client);

        executeCQL3("CREATE TABLE " + TABLE_NAME + "\n" +
                "(A1 set<text>,\n" +
                "A2 set<text>,\n" +
                "B1 text PRIMARY KEY,\n" +
                "B2 text);");

        //Should fail: InvalidRequestException("Indexes on collections are no yet supported")
        try {
            executeCQL3("CREATE INDEX " + TABLE_NAME + "_INX1 ON " + TABLE_NAME + " (A1)");
        } catch (InvalidRequestException e) {
            assertEquals("Unexpected message in exception", "Indexes on collections are no yet supported", e.getWhy());
        }

        //Should fail: InvalidRequestException("Indexes on collections are no yet supported")
        executeCQL3("CREATE INDEX " + TABLE_NAME + "_INX2 ON " + TABLE_NAME + " (B2)");

        executeCQL3("INSERT INTO " + TABLE_NAME + " (A1, A2, B1, B2)\n" +
                "VALUES({'A1-ROW1-ELM-1', 'A1-ROW1-ELM2'}, {'A2-ROW1-ELM-1', 'A2-ROW1-ELM2'}, 'B1-ROW1', 'B2-ROW1' );\n");

        executeCQL3("INSERT INTO " + TABLE_NAME + " (A1, A2, B1, B2)\n" +
                "VALUES({'A1-ROW2-ELM-1', 'A1-ROW2-ELM2'}, {'A2-ROW2-ELM-1', 'A2-ROW2-ELM2'}, 'B1-ROW2', 'B2-ROW2' );\n");

        // The select would fail with InvalidRequestException(why:No indexed columns present in by-columns clause with Equal operator)
        // if the index is not in effect.
        CqlResult r = executeCQL3("SELECT B1 FROM " + TABLE_NAME + " WHERE B2 = 'B2-ROW2';");
        List<CqlRow> rows = r.getRows();
        CqlRow row = rows.get(0);
        Column c_b1 = row.getColumns().get(0); // B1
        String B1_value = bb2str(c_b1.bufferForValue());
        assertEquals("Expected other value for B1", "B1-ROW2", B1_value);
        int dummy = 0;
    }

    public static String bb2str(ByteBuffer buffer) {
        String data = "";
        try {
            int old_position = buffer.position();
            data = decoder.decode(buffer).toString();
            buffer.position(old_position);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return data;
    }

    private static ByteBuffer str2bb(String str) {
        try {
            return ByteBuffer.wrap(str.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UTF-8 is unavailable?", e);
        }
    }

    private static CqlResult executeCQL_legacy(String cql) throws Exception {
        return _client.execute_cql_query(str2bb(cql), Compression.NONE);
    }

    private static CqlResult executeCQL3(String cql) throws Exception {
        return _client.execute_cql3_query(str2bb(cql), Compression.NONE, ConsistencyLevel.ALL);
    }
}
{code}

                  
> Bug when composite index is created in a table having collections
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-4909
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 1.2.0 beta 1
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>             Fix For: 1.2.0 beta 2
>
>         Attachments: 4909.txt
>
>
> CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.
> We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Posted by "Henrik Ring (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13490697#comment-13490697 ] 

Henrik Ring commented on CASSANDRA-4909:
----------------------------------------

Working at the ApacheConEU Hackathon. Suggestions for testing the patch.

The patch changes the code so the exception: InvalidRequestException("Indexes on collections are no yet supported")
is raised if an attempt is made to create an index on an collection type column.

Creation of indexes on tables that have collection column values is allowed as long as 
the collection columns are NOT part of the index. 

Tests:
In CQL3 create CF with 2 collection type columns "A1" and "A2" and 2 noncollection type columns "B1" and "B2".
Create index on A1 or A2 should fail. 
Create an index on B1 or B2 should succeed.
Insert data.
Select on column with index to ensure index is in place.

-- Should succeed
CREATE KEYSPACE TEST_CASSANDRA_4909_KS;

-- Should succeed
USE TEST_CASSANDRA_4909_KS; 

-- Should succeed
CREATE TABLE TEST_CASSANDRA_4909_TLB1
   (A1 set<text>,
    A2 set<text>,
    B1 text,
    B2 text,
    PRIMARY KEY B1);

-- Should fail: InvalidRequestException("Indexes on collections are no yet supported")
CREATE INDEX TEST_CASSANDRA_4909_TLB1_INX1 ON TEST_CASSANDRA_4909_TLB1 (A1);

-- Should Succeed:
CREATE INDEX TEST_CASSANDRA_4909_TLB1_INX2 ON TEST_CASSANDRA_4909_TLB1 (B2);

-- Wait for schema agreement.

-- Should succeed:
INSERT INTO TEST_CASSANDRA_4909_TLB1 (A1, A2, B1, B2)
       VALUES({'A1-ROW1-ELM-1', 'A1-ROW1-ELM2'}, {'A2-ROW1-ELM-1', 'A2-ROW1-ELM2'}, 'B1-ROW1', 'B2-ROW1' );

-- Should succeed:
INSERT INTO TEST_CASSANDRA_4909_TLB1 (A1, A2, B1, B2)
       VALUES({'A1-ROW2-ELM-1', 'A1-ROW2-ELM2'}, {'A2-ROW2-ELM-1', 'A2-ROW2-ELM2'}, 'B1-ROW2', 'B2-ROW2' );

-- Should succeed (ensure index is in place):
SELECT * FROM TEST_CASSANDRA_4909_TLB1 WHERE B2 = 'B2-ROW2';

-- Should succeed:
DROP TABLE TEST_CASSANDRA_4909_TLB1;

                
> Bug when composite index is created in a table having collections
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-4909
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 1.2.0 beta 1
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>             Fix For: 1.2.0 beta 2
>
>         Attachments: 4909.txt
>
>
> CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.
> We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Posted by "Henrik Ring (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13490748#comment-13490748 ] 

Henrik Ring edited comment on CASSANDRA-4909 at 11/5/12 5:19 PM:
-----------------------------------------------------------------

Just to clarify: Comments above are my understanding of the issue and a suggestion for test. Since you agree I will next try and actually run the test to see if it does as expected. I have not done that yet. I need to get the development environment up and running first. I am new to all of this so it is taking a bit of time to get it all going :-). I'm not a Python developer, so I was hoping someone else with better skills that area could include the test in the automated tests as appropriate. 
                
      was (Author: henrikring):
    Just to clarify: Comments above are my understanding of the issue and a suggestion for test. Since you agree I will next try and actually run the test to see if it does as expected. I have not done that yet. I need to get the development environment up and running first. I new to all of this so it is taking a bit of time :-). I'm not a Python developer, so I was hoping someone else with better skills that area could include the test in the automated tests as appropriate. 
                  
> Bug when composite index is created in a table having collections
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-4909
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 1.2.0 beta 1
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>             Fix For: 1.2.0 beta 2
>
>         Attachments: 4909.txt
>
>
> CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.
> We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13490698#comment-13490698 ] 

Jonathan Ellis commented on CASSANDRA-4909:
-------------------------------------------

+1
                
> Bug when composite index is created in a table having collections
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-4909
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 1.2.0 beta 1
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>             Fix For: 1.2.0 beta 2
>
>         Attachments: 4909.txt
>
>
> CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.
> We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Posted by "Henrik Ring (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13491002#comment-13491002 ] 

Henrik Ring commented on CASSANDRA-4909:
----------------------------------------

Now I got it running and ran the test:

{code:title=CASSANDRA_4909.java|borderStyle=solid}
package org.apache.cassandra;

import org.apache.cassandra.thrift.*;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.sql.Connection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class CASSANDRA_4909 {
    public static final Charset charset = Charset.forName("UTF-8");
    public static final CharsetEncoder encoder = charset.newEncoder();
    public static final CharsetDecoder decoder = charset.newDecoder();

    private static final String KEYSPACE_NAME = "test_cassandra_4909_ks";
    private static final String TABLE_NAME = "test_cassandra_4909_tlb1";
    private static Connection _con = null;
    private static Cassandra.Client _client = null;


    @BeforeClass
    public static void setUp() throws Exception {
        TTransport tr = new TFramedTransport(new TSocket("localhost", 9160));
        TProtocol proto = new TBinaryProtocol(tr);
        _client = new Cassandra.Client(proto);
        tr.open();
        _client.set_cql_version("3.0.0");
        _client.set_keyspace("system");

        // Create Keyspace
        executeCQL_legacy("CREATE KEYSPACE " + KEYSPACE_NAME + " WITH strategy_class = SimpleStrategy AND strategy_options:replication_factor = 1");

        // Switch default KS
        _client.set_keyspace(KEYSPACE_NAME);
    }

    @AfterClass
    public static void tearDown() throws Exception {
        if (_client != null) {
            executeCQL3("DROP KEYSPACE " + KEYSPACE_NAME);
        }
    }

    @org.junit.Test
    public void test1() throws Exception {
        assertNotNull("Expected a connection to be defined?", _client);

        executeCQL3("CREATE TABLE " + TABLE_NAME + "\n" +
                "(A1 set<text>,\n" +
                "A2 set<text>,\n" +
                "B1 text PRIMARY KEY,\n" +
                "B2 text);");

        //Should fail: InvalidRequestException("Indexes on collections are no yet supported")
        try {
            executeCQL3("CREATE INDEX " + TABLE_NAME + "_INX1 ON " + TABLE_NAME + " (A1)");
        } catch (InvalidRequestException e) {
            assertEquals("Unexpected message in exception", "Indexes on collections are no yet supported", e.getWhy());
        }

        //Should fail: InvalidRequestException("Indexes on collections are no yet supported")
        executeCQL3("CREATE INDEX " + TABLE_NAME + "_INX2 ON " + TABLE_NAME + " (B2)");

        executeCQL3("INSERT INTO " + TABLE_NAME + " (A1, A2, B1, B2)\n" +
                "VALUES({'A1-ROW1-ELM-1', 'A1-ROW1-ELM2'}, {'A2-ROW1-ELM-1', 'A2-ROW1-ELM2'}, 'B1-ROW1', 'B2-ROW1' );\n");

        executeCQL3("INSERT INTO " + TABLE_NAME + " (A1, A2, B1, B2)\n" +
                "VALUES({'A1-ROW2-ELM-1', 'A1-ROW2-ELM2'}, {'A2-ROW2-ELM-1', 'A2-ROW2-ELM2'}, 'B1-ROW2', 'B2-ROW2' );\n");

        // The select would fail with InvalidRequestException(why:No indexed columns present in by-columns clause with Equal operator)
        // if the index is not in effect.
        CqlResult r = executeCQL3("SELECT B1 FROM " + TABLE_NAME + " WHERE B2 = 'B2-ROW2';");
        List<CqlRow> rows = r.getRows();
        CqlRow row = rows.get(0);
        Column c_b1 = row.getColumns().get(0); // B1
        String B1_value = bb2str(c_b1.bufferForValue());
        assertEquals("Expected other value for B1", "B1-ROW2", B1_value);
        int dummy = 0;
    }

    public static String bb2str(ByteBuffer buffer) {
        String data = "";
        try {
            int old_position = buffer.position();
            data = decoder.decode(buffer).toString();
            buffer.position(old_position);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return data;
    }

    private static ByteBuffer str2bb(String str) {
        try {
            return ByteBuffer.wrap(str.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UTF-8 is unavailable?", e);
        }
    }

    private static CqlResult executeCQL_legacy(String cql) throws Exception {
        return _client.execute_cql_query(str2bb(cql), Compression.NONE);
    }

    private static CqlResult executeCQL3(String cql) throws Exception {
        return _client.execute_cql3_query(str2bb(cql), Compression.NONE, ConsistencyLevel.ALL);
    }
}
{code}

                
> Bug when composite index is created in a table having collections
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-4909
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 1.2.0 beta 1
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>             Fix For: 1.2.0 beta 2
>
>         Attachments: 4909.txt
>
>
> CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.
> We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Posted by "Henrik Ring (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13490748#comment-13490748 ] 

Henrik Ring edited comment on CASSANDRA-4909 at 11/5/12 5:19 PM:
-----------------------------------------------------------------

Just to clarify: Comments above are my understanding of the issue and a suggestion for test. Since you agree I will next try and actually run the test to see if it does as expected. I have not done that yet. I need to get the development environment up and running first. I new to all of this so it is taking a bit of time :-). I'm not a Python developer, so I was hoping someone else with better skills that area could include the test in the automated tests as appropriate. 
                
      was (Author: henrikring):
    Just to clarify: Comments below are my understanding of the issue and a suggestion for test. Since you agree I will next try and actually run the test to see if it does as expected. I have not done that yet. I need to get the development environment up and running first. I new to all of this so it is taking a bit of time :-). I'm not a Python developer, so I was hoping someone else with better skills that area could include the test in the automated tests as appropriate. 
                  
> Bug when composite index is created in a table having collections
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-4909
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 1.2.0 beta 1
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>             Fix For: 1.2.0 beta 2
>
>         Attachments: 4909.txt
>
>
> CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.
> We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Posted by "Henrik Ring (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13490748#comment-13490748 ] 

Henrik Ring commented on CASSANDRA-4909:
----------------------------------------

Just to clarify: Comments below are my understanding of the issue and a suggestion for test. Since you agree I will next try and actually run the test to see if it does as expected. I have not done that yet. I need to get the development environment up and running first. I new to all of this so it is taking a bit of time :-). I'm not a Python developer, so I was hoping someone else with better skills that area could include the test in the automated tests as appropriate. 
                
> Bug when composite index is created in a table having collections
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-4909
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 1.2.0 beta 1
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>             Fix For: 1.2.0 beta 2
>
>         Attachments: 4909.txt
>
>
> CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.
> We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Posted by "Henrik Ring (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13491002#comment-13491002 ] 

Henrik Ring edited comment on CASSANDRA-4909 at 11/5/12 10:49 PM:
------------------------------------------------------------------

Now I got it running and ran the test - it passed:

{code:title=CASSANDRA_4909.java|borderStyle=solid}
package org.apache.cassandra;

import org.apache.cassandra.thrift.*;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.sql.Connection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class CASSANDRA_4909 {
    public static final Charset charset = Charset.forName("UTF-8");
    public static final CharsetEncoder encoder = charset.newEncoder();
    public static final CharsetDecoder decoder = charset.newDecoder();

    private static final String KEYSPACE_NAME = "test_cassandra_4909_ks";
    private static final String TABLE_NAME = "test_cassandra_4909_tlb1";
    private static Connection _con = null;
    private static Cassandra.Client _client = null;


    @BeforeClass
    public static void setUp() throws Exception {
        TTransport tr = new TFramedTransport(new TSocket("localhost", 9160));
        TProtocol proto = new TBinaryProtocol(tr);
        _client = new Cassandra.Client(proto);
        tr.open();
        _client.set_cql_version("3.0.0");
        _client.set_keyspace("system");

        // Create Keyspace
        executeCQL_legacy("CREATE KEYSPACE " + KEYSPACE_NAME + " WITH strategy_class = SimpleStrategy AND strategy_options:replication_factor = 1");

        // Switch default KS
        _client.set_keyspace(KEYSPACE_NAME);
    }

    @AfterClass
    public static void tearDown() throws Exception {
        if (_client != null) {
            executeCQL3("DROP KEYSPACE " + KEYSPACE_NAME);
        }
    }

    @org.junit.Test
    public void test1() throws Exception {
        assertNotNull("Expected a connection to be defined?", _client);

        executeCQL3("CREATE TABLE " + TABLE_NAME + "\n" +
                "(A1 set<text>,\n" +
                "A2 set<text>,\n" +
                "B1 text PRIMARY KEY,\n" +
                "B2 text);");

        //Should fail: InvalidRequestException("Indexes on collections are no yet supported")
        try {
            executeCQL3("CREATE INDEX " + TABLE_NAME + "_INX1 ON " + TABLE_NAME + " (A1)");
        } catch (InvalidRequestException e) {
            assertEquals("Unexpected message in exception", "Indexes on collections are no yet supported", e.getWhy());
        }

        //Should fail: InvalidRequestException("Indexes on collections are no yet supported")
        executeCQL3("CREATE INDEX " + TABLE_NAME + "_INX2 ON " + TABLE_NAME + " (B2)");

        executeCQL3("INSERT INTO " + TABLE_NAME + " (A1, A2, B1, B2)\n" +
                "VALUES({'A1-ROW1-ELM-1', 'A1-ROW1-ELM2'}, {'A2-ROW1-ELM-1', 'A2-ROW1-ELM2'}, 'B1-ROW1', 'B2-ROW1' );\n");

        executeCQL3("INSERT INTO " + TABLE_NAME + " (A1, A2, B1, B2)\n" +
                "VALUES({'A1-ROW2-ELM-1', 'A1-ROW2-ELM2'}, {'A2-ROW2-ELM-1', 'A2-ROW2-ELM2'}, 'B1-ROW2', 'B2-ROW2' );\n");

        // The select would fail with InvalidRequestException(why:No indexed columns present in by-columns clause with Equal operator)
        // if the index is not in effect.
        CqlResult r = executeCQL3("SELECT B1 FROM " + TABLE_NAME + " WHERE B2 = 'B2-ROW2';");
        List<CqlRow> rows = r.getRows();
        CqlRow row = rows.get(0);
        Column c_b1 = row.getColumns().get(0); // B1
        String B1_value = bb2str(c_b1.bufferForValue());
        assertEquals("Expected other value for B1", "B1-ROW2", B1_value);
        int dummy = 0;
    }

    public static String bb2str(ByteBuffer buffer) {
        String data = "";
        try {
            int old_position = buffer.position();
            data = decoder.decode(buffer).toString();
            buffer.position(old_position);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return data;
    }

    private static ByteBuffer str2bb(String str) {
        try {
            return ByteBuffer.wrap(str.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UTF-8 is unavailable?", e);
        }
    }

    private static CqlResult executeCQL_legacy(String cql) throws Exception {
        return _client.execute_cql_query(str2bb(cql), Compression.NONE);
    }

    private static CqlResult executeCQL3(String cql) throws Exception {
        return _client.execute_cql3_query(str2bb(cql), Compression.NONE, ConsistencyLevel.ALL);
    }
}
{code}

                
      was (Author: henrikring):
    Now I got it running and ran the test:

{code:title=CASSANDRA_4909.java|borderStyle=solid}
package org.apache.cassandra;

import org.apache.cassandra.thrift.*;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.sql.Connection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class CASSANDRA_4909 {
    public static final Charset charset = Charset.forName("UTF-8");
    public static final CharsetEncoder encoder = charset.newEncoder();
    public static final CharsetDecoder decoder = charset.newDecoder();

    private static final String KEYSPACE_NAME = "test_cassandra_4909_ks";
    private static final String TABLE_NAME = "test_cassandra_4909_tlb1";
    private static Connection _con = null;
    private static Cassandra.Client _client = null;


    @BeforeClass
    public static void setUp() throws Exception {
        TTransport tr = new TFramedTransport(new TSocket("localhost", 9160));
        TProtocol proto = new TBinaryProtocol(tr);
        _client = new Cassandra.Client(proto);
        tr.open();
        _client.set_cql_version("3.0.0");
        _client.set_keyspace("system");

        // Create Keyspace
        executeCQL_legacy("CREATE KEYSPACE " + KEYSPACE_NAME + " WITH strategy_class = SimpleStrategy AND strategy_options:replication_factor = 1");

        // Switch default KS
        _client.set_keyspace(KEYSPACE_NAME);
    }

    @AfterClass
    public static void tearDown() throws Exception {
        if (_client != null) {
            executeCQL3("DROP KEYSPACE " + KEYSPACE_NAME);
        }
    }

    @org.junit.Test
    public void test1() throws Exception {
        assertNotNull("Expected a connection to be defined?", _client);

        executeCQL3("CREATE TABLE " + TABLE_NAME + "\n" +
                "(A1 set<text>,\n" +
                "A2 set<text>,\n" +
                "B1 text PRIMARY KEY,\n" +
                "B2 text);");

        //Should fail: InvalidRequestException("Indexes on collections are no yet supported")
        try {
            executeCQL3("CREATE INDEX " + TABLE_NAME + "_INX1 ON " + TABLE_NAME + " (A1)");
        } catch (InvalidRequestException e) {
            assertEquals("Unexpected message in exception", "Indexes on collections are no yet supported", e.getWhy());
        }

        //Should fail: InvalidRequestException("Indexes on collections are no yet supported")
        executeCQL3("CREATE INDEX " + TABLE_NAME + "_INX2 ON " + TABLE_NAME + " (B2)");

        executeCQL3("INSERT INTO " + TABLE_NAME + " (A1, A2, B1, B2)\n" +
                "VALUES({'A1-ROW1-ELM-1', 'A1-ROW1-ELM2'}, {'A2-ROW1-ELM-1', 'A2-ROW1-ELM2'}, 'B1-ROW1', 'B2-ROW1' );\n");

        executeCQL3("INSERT INTO " + TABLE_NAME + " (A1, A2, B1, B2)\n" +
                "VALUES({'A1-ROW2-ELM-1', 'A1-ROW2-ELM2'}, {'A2-ROW2-ELM-1', 'A2-ROW2-ELM2'}, 'B1-ROW2', 'B2-ROW2' );\n");

        // The select would fail with InvalidRequestException(why:No indexed columns present in by-columns clause with Equal operator)
        // if the index is not in effect.
        CqlResult r = executeCQL3("SELECT B1 FROM " + TABLE_NAME + " WHERE B2 = 'B2-ROW2';");
        List<CqlRow> rows = r.getRows();
        CqlRow row = rows.get(0);
        Column c_b1 = row.getColumns().get(0); // B1
        String B1_value = bb2str(c_b1.bufferForValue());
        assertEquals("Expected other value for B1", "B1-ROW2", B1_value);
        int dummy = 0;
    }

    public static String bb2str(ByteBuffer buffer) {
        String data = "";
        try {
            int old_position = buffer.position();
            data = decoder.decode(buffer).toString();
            buffer.position(old_position);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return data;
    }

    private static ByteBuffer str2bb(String str) {
        try {
            return ByteBuffer.wrap(str.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UTF-8 is unavailable?", e);
        }
    }

    private static CqlResult executeCQL_legacy(String cql) throws Exception {
        return _client.execute_cql_query(str2bb(cql), Compression.NONE);
    }

    private static CqlResult executeCQL3(String cql) throws Exception {
        return _client.execute_cql3_query(str2bb(cql), Compression.NONE, ConsistencyLevel.ALL);
    }
}
{code}

                  
> Bug when composite index is created in a table having collections
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-4909
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 1.2.0 beta 1
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>             Fix For: 1.2.0 beta 2
>
>         Attachments: 4909.txt
>
>
> CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.
> We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Posted by "Henrik Ring (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13490697#comment-13490697 ] 

Henrik Ring edited comment on CASSANDRA-4909 at 11/5/12 4:08 PM:
-----------------------------------------------------------------

Working at the ApacheConEU Hackathon. Suggestions for testing the patch.
Below is my understanding of the issue and the solution and a suggestion for how to test it.

The patch changes the code so the exception: InvalidRequestException("Indexes on collections are no yet supported")
is raised if an attempt is made to create an index on an collection type column.

Creation of indexes on tables that have collection column values is allowed as long as 
the collection columns are NOT part of the index. 

Tests:
In CQL3 create CF with 2 collection type columns "A1" and "A2" and 2 noncollection type columns "B1" and "B2".
Create index on A1 or A2 should fail. 
Create an index on B1 or B2 should succeed.
Insert data.
Select on column with index to ensure index is in place.

-- Should succeed
CREATE KEYSPACE TEST_CASSANDRA_4909_KS;

-- Should succeed
USE TEST_CASSANDRA_4909_KS; 

-- Should succeed
CREATE TABLE TEST_CASSANDRA_4909_TLB1
   (A1 set<text>,
    A2 set<text>,
    B1 text,
    B2 text,
    PRIMARY KEY B1);

-- Should fail: InvalidRequestException("Indexes on collections are no yet supported")
CREATE INDEX TEST_CASSANDRA_4909_TLB1_INX1 ON TEST_CASSANDRA_4909_TLB1 (A1);

-- Should Succeed:
CREATE INDEX TEST_CASSANDRA_4909_TLB1_INX2 ON TEST_CASSANDRA_4909_TLB1 (B2);

-- Wait for schema agreement.

-- Should succeed:
INSERT INTO TEST_CASSANDRA_4909_TLB1 (A1, A2, B1, B2)
       VALUES({'A1-ROW1-ELM-1', 'A1-ROW1-ELM2'}, {'A2-ROW1-ELM-1', 'A2-ROW1-ELM2'}, 'B1-ROW1', 'B2-ROW1' );

-- Should succeed:
INSERT INTO TEST_CASSANDRA_4909_TLB1 (A1, A2, B1, B2)
       VALUES({'A1-ROW2-ELM-1', 'A1-ROW2-ELM2'}, {'A2-ROW2-ELM-1', 'A2-ROW2-ELM2'}, 'B1-ROW2', 'B2-ROW2' );

-- Should succeed (ensure index is in place):
SELECT * FROM TEST_CASSANDRA_4909_TLB1 WHERE B2 = 'B2-ROW2';

-- Should succeed:
DROP TABLE TEST_CASSANDRA_4909_TLB1;

                
      was (Author: henrikring):
    Working at the ApacheConEU Hackathon. Suggestions for testing the patch.

The patch changes the code so the exception: InvalidRequestException("Indexes on collections are no yet supported")
is raised if an attempt is made to create an index on an collection type column.

Creation of indexes on tables that have collection column values is allowed as long as 
the collection columns are NOT part of the index. 

Tests:
In CQL3 create CF with 2 collection type columns "A1" and "A2" and 2 noncollection type columns "B1" and "B2".
Create index on A1 or A2 should fail. 
Create an index on B1 or B2 should succeed.
Insert data.
Select on column with index to ensure index is in place.

-- Should succeed
CREATE KEYSPACE TEST_CASSANDRA_4909_KS;

-- Should succeed
USE TEST_CASSANDRA_4909_KS; 

-- Should succeed
CREATE TABLE TEST_CASSANDRA_4909_TLB1
   (A1 set<text>,
    A2 set<text>,
    B1 text,
    B2 text,
    PRIMARY KEY B1);

-- Should fail: InvalidRequestException("Indexes on collections are no yet supported")
CREATE INDEX TEST_CASSANDRA_4909_TLB1_INX1 ON TEST_CASSANDRA_4909_TLB1 (A1);

-- Should Succeed:
CREATE INDEX TEST_CASSANDRA_4909_TLB1_INX2 ON TEST_CASSANDRA_4909_TLB1 (B2);

-- Wait for schema agreement.

-- Should succeed:
INSERT INTO TEST_CASSANDRA_4909_TLB1 (A1, A2, B1, B2)
       VALUES({'A1-ROW1-ELM-1', 'A1-ROW1-ELM2'}, {'A2-ROW1-ELM-1', 'A2-ROW1-ELM2'}, 'B1-ROW1', 'B2-ROW1' );

-- Should succeed:
INSERT INTO TEST_CASSANDRA_4909_TLB1 (A1, A2, B1, B2)
       VALUES({'A1-ROW2-ELM-1', 'A1-ROW2-ELM2'}, {'A2-ROW2-ELM-1', 'A2-ROW2-ELM2'}, 'B1-ROW2', 'B2-ROW2' );

-- Should succeed (ensure index is in place):
SELECT * FROM TEST_CASSANDRA_4909_TLB1 WHERE B2 = 'B2-ROW2';

-- Should succeed:
DROP TABLE TEST_CASSANDRA_4909_TLB1;

                  
> Bug when composite index is created in a table having collections
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-4909
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 1.2.0 beta 1
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>             Fix For: 1.2.0 beta 2
>
>         Attachments: 4909.txt
>
>
> CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.
> We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CASSANDRA-4909) Bug when composite index is created in a table having collections

Posted by "Sylvain Lebresne (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13490713#comment-13490713 ] 

Sylvain Lebresne commented on CASSANDRA-4909:
---------------------------------------------

bq. Working at the ApacheConEU Hackathon

I'm not sure what that means, but let me recall that there is a fair amount of tests here: https://github.com/riptano/cassandra-dtest/blob/master/cql_tests.py, including a test for this ticket. It's not necessarily perfect, but in any case it would be nice to avoid duplication of efforts.
                
> Bug when composite index is created in a table having collections
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-4909
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4909
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 1.2.0 beta 1
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>             Fix For: 1.2.0 beta 2
>
>         Attachments: 4909.txt
>
>
> CASSANDRA-4511 is open to add proper indexing of collection, but currently indexing doesn't work correctly if we index a value in a table having collection, even if that value is not a collection itself.
> We also don't refuse creating index on collections, even though we don't support it. Attaching patch to fix both.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira