[
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