[
https://issues.apache.org/jira/browse/CASSANDRA-10271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15770315#comment-15770315
]
Benjamin Lerer commented on CASSANDRA-10271:
--------------------------------------------
Thanks for the patch and sorry for the delay.
Based on your unit tests, I think there is some misunderstanding in what should
be allowed or not.
Basically, we want to allow to skip a column in the {{ORDER BY}} clause if the
clustering column is restricted by an {{=}} or an {{IN}} with only one
restriction.
So the following tests:
{code}
assertRows(execute("SELECT * FROM %s WHERE a=? AND b<? ORDER BY c
DESC", 0, 1),
row(0, 0, 2, 2),
row(0, 0, 1, 1),
row(0, 0, 0, 0));
{code}
and
{code}
assertRows(execute("SELECT * FROM %s WHERE a=? AND b IN (?, ?) ORDER BY
c ASC", 0, 1, 3),
row(0, 1, 0, 3),
row(0, 1, 1, 4),
row(0, 1, 2, 5));
{code}
are in fact invalid. In both cases an {{InvalidRequestException}} should be
thrown.
If a clustering column is restricted by an {{=}} or an {{IN}} with only one
restriction {{StatementRestrictions::isColumnRestrictedByEq}} will return
{{true}}.
By consequence,
{code}
if (!restrictions.clusteringColumnsFollowOrderByRestrictions(def.position()))
checkTrue(i++ == def.position(),
"Order by currently only support the ordering of columns
following their declared order in the PRIMARY KEY");
{code}
could simply be replaced by:
{code}
while (i != def.position())
{
checkTrue(restrictions.isColumnRestrictedByEq(clusteringColumns.get(i++)),
"Order by currently only support the ordering of columns
following their declared order in the PRIMARY KEY");
}
i++;
{code}
if I am not mistaken.
It will also be great if you could check the error messages using
{{assertInvalidMessage}} instead of {{assertInvalid}} (we had bad surprises in
the past) and add the following test for completeness:
{code}
assertRows(execute("SELECT * FROM %s WHERE a=? AND b IN (?, ?) AND c
= ? ORDER BY b ASC", 0, 1, 3, 1),
row(0, 1, 1, 4));
{code}
> ORDER BY should allow skipping equality-restricted clustering columns
> ---------------------------------------------------------------------
>
> Key: CASSANDRA-10271
> URL: https://issues.apache.org/jira/browse/CASSANDRA-10271
> Project: Cassandra
> Issue Type: Improvement
> Components: CQL
> Reporter: Tyler Hobbs
> Assignee: Brett Snyder
> Priority: Minor
> Fix For: 3.x
>
> Attachments: 10271-3.x.txt, cassandra-2.2-10271.txt
>
>
> Given a table like the following:
> {noformat}
> CREATE TABLE foo (a int, b int, c int, d int, PRIMARY KEY (a, b, c));
> {noformat}
> We should support a query like this:
> {noformat}
> SELECT * FROM foo WHERE a = 0 AND b = 0 ORDER BY c ASC;
> {noformat}
> Currently, this results in the following error:
> {noformat}
> [Invalid query] message="Order by currently only support the ordering of
> columns following their declared order in the PRIMARY KEY"
> {noformat}
> However, since {{b}} is restricted by an equality restriction, we shouldn't
> require it to be present in the {{ORDER BY}} clause.
> As a workaround, you can use this query instead:
> {noformat}
> SELECT * FROM foo WHERE a = 0 AND b = 0 ORDER BY b ASC, c ASC;
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)