skoppu22 commented on code in PR #183:
URL: 
https://github.com/apache/cassandra-analytics/pull/183#discussion_r2981588831


##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/BulkWriteComplexTypeTtlTest.java:
##########
@@ -0,0 +1,201 @@
+/*
+ * 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.analytics;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import org.junit.jupiter.api.Test;
+
+import org.apache.cassandra.distributed.shared.Uninterruptibles;
+import org.apache.cassandra.sidecar.testing.QualifiedName;
+import org.apache.cassandra.spark.bulkwriter.TTLOption;
+import org.apache.cassandra.spark.bulkwriter.WriterOptions;
+import org.apache.cassandra.testing.ClusterBuilderConfiguration;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.RowFactory;
+import org.apache.spark.sql.SparkSession;
+import org.apache.spark.sql.types.Metadata;
+import org.apache.spark.sql.types.StructField;
+import org.apache.spark.sql.types.StructType;
+
+import static org.apache.cassandra.testing.TestUtils.DC1_RF3;
+import static org.apache.cassandra.testing.TestUtils.TEST_KEYSPACE;
+import static org.apache.spark.sql.types.DataTypes.IntegerType;
+import static org.apache.spark.sql.types.DataTypes.StringType;
+import static org.apache.spark.sql.types.DataTypes.createArrayType;
+import static org.apache.spark.sql.types.DataTypes.createMapType;
+import static org.apache.spark.sql.types.DataTypes.createStructType;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests that bulk writes with TTL work correctly for complex types (list, 
set, map, UDT).
+ * This ensures the expiring cell path is invoked correctly for collection and 
composite types.
+ * TODO: add tuple ttl test after adding support for writing tuples
+ */
+class BulkWriteComplexTypeTtlTest extends SharedClusterSparkIntegrationTestBase
+{
+    static final int ROW_COUNT = 100;
+
+    static final QualifiedName LIST_TTL_TABLE = new 
QualifiedName(TEST_KEYSPACE, "test_list_ttl");
+    static final QualifiedName SET_TTL_TABLE = new 
QualifiedName(TEST_KEYSPACE, "test_set_ttl");
+    static final QualifiedName MAP_TTL_TABLE = new 
QualifiedName(TEST_KEYSPACE, "test_map_ttl");
+    static final QualifiedName UDT_TTL_TABLE = new 
QualifiedName(TEST_KEYSPACE, "test_udt_ttl");
+
+    static final String SIMPLE_UDT_NAME = "simple_udt";
+
+    @Test
+    void testListWithTtl()
+    {
+        SparkSession spark = getOrCreateSparkSession();
+        StructType schema = new StructType()
+                            .add("id", IntegerType, false)
+                            .add("listdata", createArrayType(IntegerType), 
false);
+
+        List<Row> rows = IntStream.range(0, ROW_COUNT)
+                                  .mapToObj(i -> RowFactory.create(i, 
Arrays.asList(i, i + 1)))
+                                  .collect(Collectors.toList());
+        Dataset<Row> df = spark.createDataFrame(rows, schema);
+
+        bulkWriterDataFrameWriter(df, 
LIST_TTL_TABLE).option(WriterOptions.TTL.name(), TTLOption.constant(80))
+                                                     .save();
+
+        Dataset<Row> preExpiry = bulkReaderDataFrame(LIST_TTL_TABLE).load();
+        assertThat(preExpiry.collectAsList()).hasSize(ROW_COUNT);
+
+        Uninterruptibles.sleepUninterruptibly(80, TimeUnit.SECONDS);
+        Dataset<Row> postExpiry = bulkReaderDataFrame(LIST_TTL_TABLE).load();
+        assertThat(postExpiry.collectAsList()).isEmpty();
+    }
+
+    @Test
+    void testSetWithTtl()
+    {
+        SparkSession spark = getOrCreateSparkSession();
+        StructType schema = new StructType()
+                            .add("id", IntegerType, false)
+                            .add("setdata", createArrayType(StringType), 
false);
+
+        List<Row> rows = IntStream.range(0, ROW_COUNT)
+                                  .mapToObj(i -> RowFactory.create(i, 
ImmutableSet.of("item" + i)))
+                                  .collect(Collectors.toList());
+        Dataset<Row> df = spark.createDataFrame(rows, schema);
+
+        bulkWriterDataFrameWriter(df, 
SET_TTL_TABLE).option(WriterOptions.TTL.name(), TTLOption.constant(80))
+                                                    .save();
+
+        Dataset<Row> preExpiry = bulkReaderDataFrame(SET_TTL_TABLE).load();
+        assertThat(preExpiry.collectAsList()).hasSize(ROW_COUNT);
+
+        Uninterruptibles.sleepUninterruptibly(80, TimeUnit.SECONDS);
+        Dataset<Row> postExpiry = bulkReaderDataFrame(SET_TTL_TABLE).load();
+        assertThat(postExpiry.collectAsList()).isEmpty();
+    }
+
+    @Test
+    void testMapWithTtl()
+    {
+        SparkSession spark = getOrCreateSparkSession();
+        StructType schema = new StructType()
+                            .add("id", IntegerType, false)
+                            .add("mapdata", createMapType(StringType, 
IntegerType), false);
+
+        List<Row> rows = IntStream.range(0, ROW_COUNT)
+                                  .mapToObj(i -> RowFactory.create(i, 
ImmutableMap.of("key" + i, i)))
+                                  .collect(Collectors.toList());
+        Dataset<Row> df = spark.createDataFrame(rows, schema);
+
+        bulkWriterDataFrameWriter(df, 
MAP_TTL_TABLE).option(WriterOptions.TTL.name(), TTLOption.constant(80))
+                                                    .save();
+
+        Dataset<Row> preExpiry = bulkReaderDataFrame(MAP_TTL_TABLE).load();
+        assertThat(preExpiry.collectAsList()).hasSize(ROW_COUNT);
+
+        Uninterruptibles.sleepUninterruptibly(80, TimeUnit.SECONDS);
+        Dataset<Row> postExpiry = bulkReaderDataFrame(MAP_TTL_TABLE).load();
+        assertThat(postExpiry.collectAsList()).isEmpty();
+    }
+
+    @Test
+    void testUdtWithTtl()
+    {
+        SparkSession spark = getOrCreateSparkSession();
+        StructType udtType = createStructType(new StructField[]{
+            new StructField("f1", StringType, true, Metadata.empty()),
+            new StructField("f2", IntegerType, true, Metadata.empty())
+        });
+        StructType schema = new StructType()
+                            .add("id", IntegerType, false)
+                            .add("udtfield", udtType, false);
+
+        List<Row> rows = IntStream.range(0, ROW_COUNT)
+                                  .mapToObj(i -> RowFactory.create(i, 
RowFactory.create("course" + i, i)))
+                                  .collect(Collectors.toList());
+        Dataset<Row> df = spark.createDataFrame(rows, schema);
+
+        bulkWriterDataFrameWriter(df, 
UDT_TTL_TABLE).option(WriterOptions.TTL.name(), TTLOption.constant(80))
+                                                    .save();
+
+        Dataset<Row> preExpiry = bulkReaderDataFrame(UDT_TTL_TABLE).load();
+        assertThat(preExpiry.collectAsList()).hasSize(ROW_COUNT);
+
+        Uninterruptibles.sleepUninterruptibly(80, TimeUnit.SECONDS);

Review Comment:
   I have merged all 4 tests into one and reduced the sleep to 5 seconds. That 
way entire test file sleeps for max 5 seconds.



##########
cassandra-four-zero-bridge/src/main/java/org/apache/cassandra/spark/reader/CompactionStreamScanner.java:
##########
@@ -117,15 +118,16 @@ protected void handleCellTombstoneInComplex(BigInteger 
token, Cell<?> cell)
     @Override
     UnfilteredPartitionIterator initializePartitions()
     {
-        int nowInSec = timeProvider.referenceEpochInSeconds();
+        long nowInSec = timeProvider.referenceEpochInSeconds();
         Keyspace keyspace = Keyspace.openWithoutSSTables(metadata.keyspace);
         ColumnFamilyStore cfStore = 
keyspace.getColumnFamilyStore(metadata.name);
         controller = new PurgingCompactionController(cfStore, 
CompactionParams.TombstoneOption.NONE);
         List<ISSTableScanner> scannerList = toCompact.stream()
                                                      .map(Scannable::scanner)
                                                      
.collect(Collectors.toList());
         scanners = new AbstractCompactionStrategy.ScannerList(scannerList);
-        ci = new CompactionIterator(OperationType.COMPACTION, 
scanners.scanners, controller, nowInSec, taskId);
+        // C* 4.0 CompactionIterator requires int for nowInSec; checked cast 
will throw after Y2038
+        ci = new CompactionIterator(OperationType.COMPACTION, 
scanners.scanners, controller, Ints.checkedCast(nowInSec), taskId);

Review Comment:
   I understand if analytics 4.0 bridge is used with C* 4.0, then the value is 
always guaranteed to fit in int. But with sstable version dependent bridge 
determination feature (we have a open PR for this), there is a possibility of 
using 4.0 bridge with C* 5.0 if the cluster is running in 4_0 compatibility 
mode and doesn't have 5.0 sstables. Having checkedCast gives us freedom from 
worrying about such cases, not only now, later as well with upcoming C* 
releases. checkedCast has just one more check on top of a simple conversion, 
and CPUs can predict branching well, so there is no considerable performance 
impact of using checkedCast. Hence I like to keep checkedCast to feel 
comfortable with such special cases.



##########
cassandra-four-zero-bridge/src/main/java/org/apache/cassandra/db/DbUtils.java:
##########
@@ -33,23 +33,27 @@ private DbUtils()
         throw new IllegalStateException(getClass() + " is static utility class 
and shall not be instantiated");
     }
 
-    public static DeletionTime deletionTime(long markedForDeleteAt, int 
localDeletionTime)
+    // C* 4.0 DeletionTime constructor requires int for localDeletionTime; 
checked cast will throw after Y2038
+    public static DeletionTime deletionTime(long markedForDeleteAt, long 
localDeletionTime)

Review Comment:
   I see caller's caller is always test code. Marked them as @VisibleForTesting 
in both 4.0 and 5.0 bridge



##########
cassandra-four-zero-bridge/src/test/java/org/apache/cassandra/spark/data/CqlTypeY2038Test.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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;
+
+import java.nio.ByteBuffer;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.Test;
+
+import org.apache.cassandra.db.rows.BufferCell;
+import org.apache.cassandra.schema.ColumnMetadata;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.spark.data.partitioner.Partitioner;
+import org.apache.cassandra.spark.reader.SchemaBuilder;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * Tests verifying Y2038 boundary behavior for {@link CqlType#tombstone} and 
{@link CqlType#expiring}
+ * in Cassandra 4.0.
+ */
+class CqlTypeY2038Test

Review Comment:
   This one was removed in the previous commit



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