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


##########
src/java/org/apache/cassandra/cql3/terms/Maps.java:
##########
@@ -189,7 +181,10 @@ public Term prepare(String keyspace, ColumnSpecification 
receiver) throws Invali
 
             ColumnSpecification keySpec = Maps.keySpecOf(receiver);
             ColumnSpecification valueSpec = Maps.valueSpecOf(receiver);
-            Map<Term, Term> values = new HashMap<>(entries.size());
+            // In CQL maps are represented as a list of key value pairs (e.g. 
{k1 : v1, k2 : v2, ...}).
+            // Whereas, internally maps are serialized as a lists where each 
key is followed by its value (e.g. [k1, v1, k2, v2, ...])
+            // Therefore, we need to from one format to the other.

Review Comment:
   ```suggestion
               // In CQL maps are represented as a list of key-value pairs 
(e.g. {k1 : v1, k2 : v2, ...}).
               // Whereas, internally, maps are serialized as lists where each 
key is followed by its value (e.g. [k1, v1, k2, v2, ...])
               // Therefore, we must go from one format to another.
   ```



##########
src/java/org/apache/cassandra/cql3/Tuples.java:
##########
@@ -51,11 +44,30 @@ public static ColumnSpecification 
componentSpecOf(ColumnSpecification column, in
                                        
(getTupleType(column.type)).type(component));
     }
 
+    public static ColumnSpecification makeReceiver(List<? extends 
ColumnSpecification> receivers)

Review Comment:
   Check Tuples class in current 5.0 for example,
   
   ```
   /**
       * A raw placeholder for a tuple of values for different multiple 
columns, each of which may have a different type.
       * {@code
       * For example, "SELECT ... WHERE (col1, col2) > ?".
       * }
       */
      public static class Raw extends AbstractMarker.MultiColumnRaw
      {
   ```
   
   `different multiple columns, each of which may have a different type.`, 
stressing on "different"



##########
src/java/org/apache/cassandra/db/marshal/MultiElementType.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.db.marshal;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+
+/**
+ * Base type for the types being composed of multi-elements like Collections, 
Tuples, UDTs or Vectors.
+ * This class unifies the methods used by the CQL layer to work with those 
types.
+ */
+public abstract class MultiElementType<T> extends AbstractType<T>
+{
+    protected MultiElementType(ComparisonType comparisonType)
+    {
+        super(comparisonType);
+    }
+
+    /**
+     * Returns the serialized representation of the value composed of the 
specified elements.
+     *
+     * @param elements the serialized values of the elements
+     * @return the serialized representation of the value composed of the 
specified elements.
+     */
+    public abstract ByteBuffer pack(List<ByteBuffer> elements);
+
+    /**
+     * Returns the serialized representation of the elements composing the 
specified value.
+     *
+     * @param value a serialized value of this type
+     * @return the serialized representation of the elements composing the 
specified value.
+     */
+    public abstract List<ByteBuffer> unpack(ByteBuffer value);

Review Comment:
   Good point, how about `returnPacked` and `returnUnpacked`? Still not 
insisting, but as you mentioned you understand what I mean, just an idea. Feel 
free to ignore it :-) Just they do not really unpack exactly :D 



##########
src/java/org/apache/cassandra/cql3/InMarker.java:
##########
@@ -0,0 +1,163 @@
+/*
+ * 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.List;
+
+import org.apache.cassandra.cql3.functions.Function;
+import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.db.marshal.ByteBufferAccessor;
+import org.apache.cassandra.db.marshal.ListType;
+import org.apache.cassandra.db.marshal.MultiElementType;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+/**
+ * A CQL named or unnamed bind marker for an {@code IN} restriction.
+ * For example, 'SELECT ... WHERE pk IN ?' or 'SELECT ... WHERE pk IN :myKey '.
+ */
+public final class InMarker extends Terms.NonTerminals
+{
+    private final int bindIndex;
+    private final ColumnSpecification receiver;
+
+    private InMarker(int bindIndex, ColumnSpecification receiver)
+    {
+        this.bindIndex = bindIndex;
+        this.receiver = receiver;
+    }
+
+    @Override
+    public void addFunctionsTo(List<Function> functions) {}
+
+    @Override
+    public void collectMarkerSpecification(VariableSpecifications boundNames)
+    {
+        boundNames.add(bindIndex, receiver);
+    }
+
+    @Override
+    public Terminals bind(QueryOptions options)
+    {
+        ByteBuffer values = options.getValues().get(bindIndex);
+        if (values == null)
+            return null;
+
+        if (values == ByteBufferUtil.UNSET_BYTE_BUFFER)
+            return UNSET_TERMINALS;
+
+        ListType<?> type = (ListType) receiver.type;
+        return toTerminals(values, type, 
terminalConverter(type.getElementsType()));
+    }
+
+    private <T> Terminals toTerminals(ByteBuffer value,
+                                      ListType<T> type,
+                                      java.util.function.Function<ByteBuffer, 
Term.Terminal> terminalConverter)
+    {
+        List<T> elements = type.getSerializer().deserialize(value, 
ByteBufferAccessor.instance);
+        List<Term.Terminal> terminals = new ArrayList<>(elements.size());
+        for (T element : elements)
+        {
+            terminals.add(element == null ? null : 
terminalConverter.apply(type.getElementsType().decompose(element)));
+        }
+        return Terminals.of(terminals);
+    }
+
+    public static java.util.function.Function<ByteBuffer, Term.Terminal> 
terminalConverter(AbstractType<?> type)
+    {
+        if (type instanceof MultiElementType<?>)
+            return e -> MultiElements.Value.fromSerialized(e, 
(MultiElementType<?>) type);
+
+        return Constants.Value::new;
+    }
+
+    @Override
+    public List<ByteBuffer> bindAndGet(QueryOptions options)
+    {
+        Terminals terminals = bind(options);
+        return terminals == null ? null : terminals.get();
+    }
+
+    @Override
+    public List<List<ByteBuffer>> bindAndGetElements(QueryOptions options)
+    {
+        Terminals terminals = bind(options);
+        return terminals == null ? null : terminals.getElements();
+    }
+
+    @Override
+    public boolean containsSingleTerm()
+    {
+        return false;
+    }
+
+    @Override
+    public Term asSingleTerm()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * A raw placeholder for multiple values of the same type for a single 
column.
+     * For example, 'SELECT ... WHERE user_id IN ?'.
+     * <p>
+     * Because a single type is used, a List is used to represent the values.
+     */
+    public static final class Raw extends Terms.Raw

Review Comment:
   NM, I got confused with this one



##########
src/java/org/apache/cassandra/cql3/restrictions/SingleColumnRestriction.java:
##########
@@ -218,7 +235,10 @@ public final SingleRestriction 
doMergeWith(SingleRestriction otherRestriction)
         @Override
         public MultiCBuilder appendTo(MultiCBuilder builder, QueryOptions 
options)
         {
-            builder.addEachElementToAll(getValues(options));
+            List<ByteBuffer> buffers = values.bindAndGet(options);
+            checkNotNull(buffers, "Invalid null value for column %s", 
columnDef.name);
+            checkFalse(buffers == Terms.UNSET_LIST, "Invalid unset value for 
column %s", columnDef.name);

Review Comment:
   I see them in `InRestrictionWithMarker#getValues`



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