adelapena commented on code in PR #2655:
URL: https://github.com/apache/cassandra/pull/2655#discussion_r1450511112


##########
src/java/org/apache/cassandra/cql3/terms/Tuples.java:
##########
@@ -0,0 +1,251 @@
+/*
+ * 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.terms;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+import org.apache.cassandra.cql3.AssignmentTestable;
+import org.apache.cassandra.cql3.ColumnIdentifier;
+import org.apache.cassandra.cql3.ColumnSpecification;
+import org.apache.cassandra.cql3.QueryOptions;
+import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.db.marshal.ReversedType;
+import org.apache.cassandra.db.marshal.TupleType;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+
+import static 
org.apache.cassandra.cql3.statements.RequestValidations.invalidRequest;
+
+/**
+ * Static helper methods and classes for tuples.
+ */
+public final class Tuples
+{
+    private Tuples() {}
+
+    public static ColumnSpecification componentSpecOf(ColumnSpecification 
column, int component)
+    {
+        return new ColumnSpecification(column.ksName,
+                                       column.cfName,
+                                       new 
ColumnIdentifier(String.format("%s[%d]", column.name, component), true),
+                                       
(getTupleType(column.type)).type(component));
+    }
+
+    public static ColumnSpecification makeReceiver(List<? extends 
ColumnSpecification> receivers)
+    {
+        List<AbstractType<?>> types = new ArrayList<>(receivers.size());
+        StringBuilder inName = new StringBuilder("(");
+        for (int i = 0; i < receivers.size(); i++)
+        {
+            ColumnSpecification receiver = receivers.get(i);
+            inName.append(receiver.name);
+            if (i < receivers.size() - 1)
+                inName.append(',');
+            types.add(receiver.type);
+        }
+        inName.append(')');
+
+        ColumnIdentifier identifier = new ColumnIdentifier(inName.toString(), 
true);
+        TupleType type = new TupleType(types);
+        return new ColumnSpecification(receivers.get(0).ksName, 
receivers.get(0).cfName, identifier, type);
+    }
+
+    /**
+     * A raw, literal tuple.  When prepared, this will become a Tuples.Value 
or Tuples.DelayedValue, depending
+     * on whether the tuple holds NonTerminals.
+     */
+    public static class Literal extends Term.Raw
+    {
+        private final List<Term.Raw> elements;
+
+        public Literal(List<Term.Raw> elements)
+        {
+            this.elements = elements;
+        }
+
+        public Term prepare(String keyspace, ColumnSpecification receiver) 
throws InvalidRequestException
+        {
+            // The parser cannot differentiate between a tuple with one 
element and a term between parenthesis.
+            // By consequence, we need to wait until we know the target type 
to determine which one it is.
+            if (elements.size() == 1 && !checkIfTupleType(receiver.type))
+                return elements.get(0).prepare(keyspace, receiver);
+
+            TupleType tupleType = getTupleType(receiver.type);
+
+            if (elements.size() != tupleType.size())
+                throw invalidRequest("Expected %d elements in value tuple %s, 
but got %d: %s",

Review Comment:
   It might be better with:
   ```suggestion
                   throw invalidRequest("Expected %d elements in value for 
tuple %s, but got %d: %s",
   ```
   This would require updating the expected error messages in `TupleTypeTest` 
and `SelectMultiColumnRelationTest`.



##########
src/java/org/apache/cassandra/cql3/SingleColumnRelation.java:
##########
@@ -38,127 +37,105 @@
 import static 
org.apache.cassandra.cql3.statements.RequestValidations.invalidRequest;
 
 /**
- * Relations encapsulate the relationship between an entity of some kind, and
- * a value (term). For example, {@code <key> > "start" or "colname1" = 
"somevalue"}.
- *
+ * A filter on a column values.
  */
 public final class SingleColumnRelation extends Relation
 {
-    private final ColumnIdentifier entity;
+    private final ColumnIdentifier column;
     private final Term.Raw mapKey;
     private final Term.Raw value;
-    private final List<Term.Raw> inValues;
+    private final Terms.Raw inValues;
 
-    private SingleColumnRelation(ColumnIdentifier entity, Term.Raw mapKey, 
Operator type, Term.Raw value, List<Term.Raw> inValues)
+    private SingleColumnRelation(ColumnIdentifier column, Term.Raw mapKey, 
Operator operator, Term.Raw value, Terms.Raw inValues)

Review Comment:
   Nit: I'd add `@Nullable` in the optional arguments, and maybe also in the 
class attributes:
   ```suggestion
       private SingleColumnRelation(ColumnIdentifier column,
                                    @Nullable Term.Raw mapKey,
                                    Operator operator,
                                    @Nullable Term.Raw value,
                                    @Nullable Terms.Raw inValues)
   ```



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