From 56a6e0f0109ee5981a59ae791506f365347e87d0 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Fri, 6 Dec 2024 16:22:32 -0600 Subject: [PATCH] re-disallow DESC with ORDER BY ANN --- .../cassandra/cql3/restrictions/StatementRestrictions.java | 3 ++- .../apache/cassandra/cql3/statements/SelectStatement.java | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java index d28e16fa399f..7e92d3273077 100644 --- a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java +++ b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java @@ -682,7 +682,8 @@ else if (indexOrderings.size() == 1) if (orderings.size() > 1) throw new InvalidRequestException("Cannot combine clustering column ordering with non-clustering column ordering"); Ordering ordering = indexOrderings.get(0); - if (ordering.direction != Ordering.Direction.ASC && ordering.expression.isScored()) + // TODO remove the instanceof with SelectStatement.ANN_USE_SYNTHETIC_SCORE. + if (ordering.direction != Ordering.Direction.ASC && (ordering.expression.isScored() || ordering.expression instanceof Ordering.Ann)) throw new InvalidRequestException("Descending ANN ordering is not supported"); if (!ENABLE_SAI_GENERAL_ORDER_BY && ordering.expression instanceof Ordering.SingleColumn) throw new InvalidRequestException("SAI based ORDER BY on non-vector column is not supported"); diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java index e7d5cf5874a6..96e992fe876f 100644 --- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java @@ -101,8 +101,11 @@ */ public class SelectStatement implements CQLStatement.SingleKeyspaceCqlStatement { - // TODO remove this when we no longer need to downgrade to replicas that don't know about synthetic columns - // (And don't forget to remove the related hacks in Columns.Serializer.encodeBitmap and UnfilteredSerializer.serializeRowBody) + // TODO remove this when we no longer need to downgrade to replicas that don't know about synthetic columns, + // and the related code in + // - Columns.Serializer.encodeBitmap + // - UnfilteredSerializer.serializeRowBody) + // - StatementRestrictions.addOrderingRestrictions public static final boolean ANN_USE_SYNTHETIC_SCORE = Boolean.parseBoolean(System.getProperty("cassandra.sai.ann_use_synthetic_score", "false")); private static final Logger logger = LoggerFactory.getLogger(SelectStatement.class);