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


##########
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<?>)

Review Comment:
   In this case, it feels that being able to use the `instanceof` pattern 
matching would be better as it would remove the need for the cast. If we start 
using  an `AbstractType#isMultiElement` when 17 become our bottom level it will 
make the use of the pattern matching harder. What do you think?



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