Szymon Acedański created CASSANDRA-14286: --------------------------------------------
Summary: 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 Environment: Kubernetes cluster using cassandra:3.11.1 Docker image. Reporter: Szymon Acedański 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