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

Benjamin Lerer commented on CASSANDRA-14286:
--------------------------------------------

I looked at the trunk patch. For queries with selection clauses having some 
processing like: {{SELECT JSON a, CAST(b AS FLOAT) FROM %s WHERE a IN (20, 100) 
ORDER BY b}}. The query will fail with an {{IndexOutOfBoundException}} during 
the {{Selection}} initialization.

I looked into the problem and pushed a correction to the patch 
[here|https://github.com/apache/cassandra/compare/trunk...blerer:14286-trunk-review].
 CI results look good.

[~fcofdezc] Could you have a look at my changes and tell me if they make sense 
to you?

> IndexOutOfBoundsException with SELECT JSON using IN and ORDER BY
> ----------------------------------------------------------------
>
>                 Key: CASSANDRA-14286
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-14286
>             Project: Cassandra
>          Issue Type: Bug
>          Components: CQL
>         Environment: Kubernetes cluster using cassandra:3.11.1 Docker image.
>            Reporter: Szymon Acedański
>            Assignee: Francisco Fernandez
>            Priority: Major
>         Attachments: orderbug-traceback.txt
>
>
> When running the following code:
> {code}
> public class CassandraJsonOrderingBug {
>     public static void main(String[] args) {
>         Session session = CassandraFactory.getSession();
>         session.execute("CREATE TABLE thebug ( PRIMARY KEY (a, b), a INT, b 
> INT)");
>         try {
>             session.execute("INSERT INTO thebug (a, b) VALUES (20, 30)");
>             session.execute("INSERT INTO thebug (a, b) VALUES (100, 200)");
>             Statement statement = new SimpleStatement("SELECT JSON a, b FROM 
> thebug WHERE a IN (20, 100) ORDER BY b");
>             statement.setFetchSize(Integer.MAX_VALUE);
>             for (Row w: session.execute(statement)) {
>                 System.out.println(w.toString());
>             }
>         } finally {
>             session.execute("DROP TABLE thebug");
>         }
>     }
> }
> {code}
> The following exception is thrown server-side:
> {noformat}
> java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
>       at java.util.Collections$SingletonList.get(Collections.java:4815) 
> ~[na:1.8.0_151]
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement$SingleColumnComparator.compare(SelectStatement.java:1297)
>  ~[apache-cassandra-3.11.1.jar:3.11.1]
>       at 
> org.apache.cassandra.cql3.statements.SelectStatement$SingleColumnComparator.compare(SelectStatement.java:1284)
>  ~[apache-cassandra-3.11.1.jar:3.11.1]
>       at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355) 
> ~[na:1.8.0_151]
>       at java.util.TimSort.sort(TimSort.java:220) ~[na:1.8.0_151]
>       at java.util.Arrays.sort(Arrays.java:1512) ~[na:1.8.0_151]
>       at java.util.ArrayList.sort(ArrayList.java:1460) ~[na:1.8.0_151]
>       at java.util.Collections.sort(Collections.java:175) ~[na:1.8.0_151]
> {noformat}
> (full traceback attached)
> The accessed index is the index of the sorted column in the SELECT JSON 
> fields list.
> Similarly, if the select clause is changed to
> SELECT JSON b, a FROM thebug WHERE a IN (20, 100) ORDER BY b
> then the query finishes, but the output is sorted incorrectly (by textual 
> JSON representation):
> {noformat}
> Row[{"b": 200, "a": 100}]
> Row[{"b": 30, "a": 20}]
> {noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to