michaelsembwever commented on code in PR #236:
URL: 
https://github.com/apache/cassandra-analytics/pull/236#discussion_r3943791792


##########
cassandra-six-zero-types/src/main/java/org/apache/cassandra/spark/data/complex/AbstractCqlList.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.spark.data.complex;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import org.apache.cassandra.bridge.CassandraVersion;
+import org.apache.cassandra.cql3.functions.types.SettableByIndexData;
+import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.db.marshal.ListType;
+import org.apache.cassandra.db.rows.BufferCell;
+import org.apache.cassandra.db.rows.CellPath;
+import org.apache.cassandra.schema.ColumnMetadata;
+import org.apache.cassandra.serializers.ListSerializer;
+import org.apache.cassandra.serializers.TypeSerializer;
+import org.apache.cassandra.spark.data.CqlField;
+import org.apache.cassandra.spark.data.CqlType;
+import org.apache.cassandra.spark.utils.RandomUtils;
+import org.apache.cassandra.utils.TimeUUID;
+
+import static org.apache.cassandra.spark.data.CqlField.NO_TTL;
+
+/**
+ * A copy of the four-zero class. Cassandra 5.0 removed {@code 
UUIDGen.getTimeUUIDBytes()}, so the inherited
+ * four-zero class throws {@code NoSuchMethodError} for every list cell that 
carries a time to live;
+ * {@link TimeUUID.Generator} plus {@code TimeUUID.toBytes()} returns the same 
16 bytes.
+ */
+public abstract class AbstractCqlList extends CqlCollection implements 
CqlField.CqlList
+{
+    public AbstractCqlList(CqlField.CqlType type)
+    {
+        super(type);
+    }
+
+    @Override
+    public AbstractType<?> dataType(boolean isMultiCell)
+    {
+        return ListType.getInstance(((CqlType) type()).dataType(), 
isMultiCell);
+    }
+
+    @Override
+    public InternalType internalType()
+    {
+        return InternalType.List;
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public <T> TypeSerializer<T> serializer()
+    {
+        return (TypeSerializer<T>) ListSerializer.getInstance(((CqlType) 
type()).serializer());
+    }
+
+    @Override
+    public String name()
+    {
+        return "list";
+    }
+
+    @Override
+    protected void setInnerValueInternal(SettableByIndexData<?> udtValue, int 
position, Object value)
+    {
+        udtValue.setList(position, (List<?>) value);
+    }
+
+    @Override
+    public Object randomValue(int minCollectionSize)
+    {
+        return IntStream.range(0, RandomUtils.RANDOM.nextInt(16) + 
minCollectionSize)
+                        .mapToObj(element -> 
type().randomValue(minCollectionSize))
+                        .collect(Collectors.toList());
+    }
+
+    @Override
+    public org.apache.cassandra.cql3.functions.types.DataType 
driverDataType(boolean isFrozen)
+    {
+        return 
org.apache.cassandra.cql3.functions.types.DataType.list(((CqlType) 
type()).driverDataType(isFrozen));
+    }
+
+    @Override
+    public Object convertForCqlWriter(Object value, CassandraVersion version, 
boolean isCollectionElement)
+    {
+        return ((List<?>) value).stream()
+                                .map(element -> 
type().convertForCqlWriter(element, version, true))
+                                .collect(Collectors.toList());
+    }
+
+    @Override
+    public void addCell(final org.apache.cassandra.db.rows.Row.Builder 
rowBuilder,
+                        ColumnMetadata cd,
+                        long timestamp,
+                        int ttl,
+                        long now,
+                        Object value)
+    {
+        for (Object o : (List<?>) value)
+        {
+            if (ttl != NO_TTL)
+            {
+                rowBuilder.addCell(CqlType.expiring(cd, timestamp, ttl, now, 
type().serialize(o),
+                                                    
CellPath.create(TimeUUID.Generator.nextTimeUUID().toBytes())));

Review Comment:
   yes, and fixes a 5.0 defect



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