mike-tr-adamson commented on code in PR #2673: URL: https://github.com/apache/cassandra/pull/2673#discussion_r1335937452
########## src/java/org/apache/cassandra/cql3/Ordering.java: ########## @@ -0,0 +1,187 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.cql3; + +import org.apache.cassandra.cql3.restrictions.SingleColumnRestriction; +import org.apache.cassandra.cql3.restrictions.SingleRestriction; +import org.apache.cassandra.schema.ColumnMetadata; +import org.apache.cassandra.schema.TableMetadata; + +/** + * A single element of an ORDER BY clause. + * <code>ORDER BY ordering1 [, ordering2 [, ...]] </code> + * <p> + * An ordering comprises an expression that produces the values to compare against each other + * and a sorting direction (ASC, DESC). + */ +public class Ordering +{ + public final Expression expression; + public final Direction direction; + + public Ordering(Expression expression, Direction direction) + { + this.expression = expression; + this.direction = direction; + } + + public interface Expression + { + default boolean hasNonClusteredOrdering() + { + return false; + } + + default SingleRestriction toRestriction() + { + throw new UnsupportedOperationException(); + } + + ColumnMetadata getColumn(); + } + + /** + * Represents a single column in + * <code>ORDER BY column</code> + */ + public static class SingleColumn implements Expression + { + public final ColumnMetadata column; + + public SingleColumn(ColumnMetadata column) + { + this.column = column; + } + + @Override + public ColumnMetadata getColumn() + { + return column; + } + } + + /** + * An expression used in Approximate Nearest Neighbor ordering. + * <code>ORDER BY column ANN OF value</code> + */ + public static class Ann implements Expression + { + final ColumnMetadata column; + final Term vectorValue; + + public Ann(ColumnMetadata column, Term vectorValue) + { + this.column = column; + this.vectorValue = vectorValue; + } + + @Override + public boolean hasNonClusteredOrdering() + { + return true; + } + + @Override + public SingleRestriction toRestriction() + { + return new SingleColumnRestriction.AnnRestriction(column, vectorValue); + } + + @Override + public ColumnMetadata getColumn() + { + return column; + } + } + + public enum Direction + {ASC, DESC} + + + /** + * Represents the AST of a single element in the ORDER BY clause. Review Comment: It stands for abstract syntax tree, and I've changed it to that. I realise it's not obvious but it is a term that is used in relation to antlr, maybe not by us but in their documentation. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

