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

Sylvain Lebresne commented on CASSANDRA-4612:
---------------------------------------------

I believe that removing the "Order by currently only support the ordering of 
columns following their declared order in the PRIMARY KEY" is buggy because it 
still doesn't work in the case where the key restriction is an EQ (i.e. not an 
IN). That is, we can remove it but in that case we must change the condition at 
the top of orderResults() so that we go through the 'CompositeComparator' path 
if the keyRestriction is an EQ and the requested orderings are not in the same 
order that in the PK definition. Not a bad idea though.

Some minor nits:
* We can provide the size when allocating the typesWithPositions list. I would 
have split typesWithPositions in two lists as this reduce the number of 
allocation needed (because you avoid all the Pair but also because you can use 
int[] for the positions) and in that case wouldn't really complicate the code 
anyway. 
* In getColumnPositionInSelect, we could use a by-index for loop and directly 
return the current index when we find the name. That way we can throw an 
assertion if we didn't find the name at all since that shouldn't happen anyway 
(tiny bonus: iteration by index on ArrayList is slightly cheaper as it avoids 
the iterator allocation).

                
> cql error with ORDER BY when using IN
> -------------------------------------
>
>                 Key: CASSANDRA-4612
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4612
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.1.4
>         Environment: ubuntu, cassandra trunk (commit 
> 769fe895a36868c47101f681f5fdd721bee1ad62 )
>            Reporter: Tyler Patterson
>            Assignee: Pavel Yaskevich
>             Fix For: 1.1.6
>
>         Attachments: CASSANDRA-4612.patch
>
>
> {code}
>             CREATE TABLE test(
>                 my_id varchar, 
>                 col1 int, 
>                 value varchar, 
>                 PRIMARY KEY (my_id, col1)
>             );
> INSERT INTO test(my_id, col1, value) VALUES ( 'key1', 1, 'a');
> INSERT INTO test(my_id, col1, value) VALUES ( 'key2', 3, 'c');
> INSERT INTO test(my_id, col1, value) VALUES ( 'key3', 2, 'b');
> INSERT INTO test(my_id, col1, value) VALUES ( 'key4', 4, 'd');
> SELECT col1 FROM test WHERE my_id in('key1', 'key2', 'key3') ORDER BY col1;
> {code}
> The following error results: TSocket read 0 bytes
> The log gives a traceback:
> {code}
> ERROR [Thrift:8] 2012-09-04 12:02:15,894 CustomTThreadPoolServer.java (line 
> 202) Error occurred during processing of message.
> java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
>       at java.util.ArrayList.RangeCheck(ArrayList.java:547)
>       at java.util.ArrayList.get(ArrayList.java:322)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement$SingleColumnComparator.compare(SelectStatement.java:1356)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement$SingleColumnComparator.compare(SelectStatement.java:1343)
>       at java.util.Arrays.mergeSort(Arrays.java:1270)
>       at java.util.Arrays.sort(Arrays.java:1210)
>       at java.util.Collections.sort(Collections.java:159)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.orderResults(SelectStatement.java:821)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.process(SelectStatement.java:793)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.executeInternal(SelectStatement.java:136)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.execute(SelectStatement.java:118)
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement.execute(SelectStatement.java:62)
>       at 
> org.apache.cassandra.cql3.QueryProcessor.processStatement(QueryProcessor.java:107)
>       at 
> org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:115)
>       at 
> org.apache.cassandra.thrift.CassandraServer.execute_cql_query(CassandraServer.java:1521)
>       at 
> org.apache.cassandra.thrift.Cassandra$Processor$execute_cql_query.getResult(Cassandra.java:3618)
>       at 
> org.apache.cassandra.thrift.Cassandra$Processor$execute_cql_query.getResult(Cassandra.java:3606)
>       at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:32)
>       at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:34)
>       at 
> org.apache.cassandra.thrift.CustomTThreadPoolServer$WorkerProcess.run(CustomTThreadPoolServer.java:184)
>       at 
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>       at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>       at java.lang.Thread.run(Thread.java:662)
> {code}

--
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

Reply via email to