bereng commented on code in PR #3095:
URL: https://github.com/apache/cassandra/pull/3095#discussion_r1538709767


##########
src/java/org/apache/cassandra/cql3/ColumnsExpression.java:
##########
@@ -0,0 +1,574 @@
+/*
+ * 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 java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+
+import org.apache.cassandra.cql3.functions.Function;
+import org.apache.cassandra.cql3.terms.Term;
+import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.db.marshal.CollectionType;
+import org.apache.cassandra.db.marshal.ListType;
+import org.apache.cassandra.db.marshal.MapType;
+import org.apache.cassandra.db.marshal.TupleType;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.schema.ColumnMetadata;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+import static 
org.apache.cassandra.cql3.statements.RequestValidations.checkContainsNoDuplicates;
+import static 
org.apache.cassandra.cql3.statements.RequestValidations.checkContainsOnly;
+import static 
org.apache.cassandra.cql3.statements.RequestValidations.checkFalse;
+import static 
org.apache.cassandra.cql3.statements.RequestValidations.checkTrue;
+import static 
org.apache.cassandra.cql3.statements.RequestValidations.invalidRequest;
+
+/**
+ * An expression including one or several columns.
+ */
+public final class ColumnsExpression
+{
+    /**
+     * Represent the expression kind
+     */
+    public enum Kind
+    {
+        /**
+         * Single column expression (e.g. {@code columnA})
+         */
+        SINGLE_COLUMN
+        {
+            @Override
+            void validateColumns(TableMetadata table, List<ColumnMetadata> 
columns)
+            {
+            }
+
+            @Override
+            AbstractType<?> type(TableMetadata table, List<ColumnMetadata> 
columns)
+            {
+                return columns.get(0).type;
+            }
+
+            @Override
+            String toCQLString(Stream<String> columns, String mapKey)
+            {
+                return columns.findFirst().orElseThrow();
+            }
+
+            @Override
+            public String toString()
+            {
+                return "single column";
+            }
+        },
+        /**
+         * Multi-column expression (e.g. {@code (columnA, columnB)})
+         */
+        MULTI_COLUMN
+        {
+            @Override
+            protected void validateColumns(TableMetadata table, 
List<ColumnMetadata> columns)
+            {
+                int previousPosition = -1;
+                for (int i = 0, m = columns.size(); i < m; i++)
+                {
+                    ColumnMetadata column = columns.get(i);
+                    checkTrue(column.isClusteringColumn(), "Multi-column 
relations can only be applied to clustering columns but was applied to: %s", 
column.name);
+                    checkFalse(columns.lastIndexOf(column) != i, "Column 
\"%s\" appeared twice in a relation: %s", column.name, this);
+
+                    // check that no clustering columns were skipped
+                    checkFalse(previousPosition != -1 && column.position() != 
previousPosition + 1,
+                               "Clustering columns must appear in the PRIMARY 
KEY order in multi-column relations: %s", toCQLString(columns, null));
+
+                    previousPosition = column.position();
+                }
+            }
+
+            @Override
+            AbstractType<?> type(TableMetadata table, List<ColumnMetadata> 
columns)
+            {
+                return new TupleType(columns.stream()

Review Comment:
   Don't use streams in potential hot path?



-- 
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]

Reply via email to