yifan-c commented on code in PR #11:
URL: 
https://github.com/apache/cassandra-analytics/pull/11#discussion_r1291816343


##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/sparksql/SparkCellIterator.java:
##########
@@ -339,21 +337,28 @@ private void maybeRebuildPartition()
         }
 
         // Or new partition, so deserialize partition keys and update 'values' 
array
-        ByteBuffer partitionKey = rid.getPartitionKey();
-        if (numPartitionKeys == 1)
+        readPartitionKey(rid.getPartitionKey(), cqlTable, this.values, stats);
+    }
+
+    public static void readPartitionKey(final ByteBuffer partitionKey,
+                                        final CqlTable table,
+                                        final Object[] values,
+                                        final Stats stats)
+    {
+        if (table.numPartitionKeys() == 1)
         {
             // Not a composite partition key
-            CqlField field = cqlTable.partitionKeys().get(0);
-            values[field.position()] = deserialize(field, partitionKey);
+            final CqlField field = table.partitionKeys().get(0);

Review Comment:
   nit: avoid using the unnecessary `final`. The project use the same code 
style as in https://cassandra.apache.org/_/development/code_style.html



##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/sparksql/PartitionSizeIterator.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.sparksql;
+
+import java.io.IOException;
+
+import org.apache.cassandra.spark.data.CqlTable;
+import org.apache.cassandra.spark.data.DataLayer;
+import org.apache.cassandra.spark.reader.IndexEntry;
+import org.apache.cassandra.spark.reader.StreamScanner;
+import org.apache.cassandra.spark.stats.Stats;
+import org.apache.spark.sql.catalyst.InternalRow;
+import org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
+import org.apache.spark.sql.connector.read.PartitionReader;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Wrapper iterator around IndexIterator to read all Index.db files and return 
SparkSQL
+ * rows containing all partition keys and the associated on-disk uncompressed 
and compressed sizes.
+ */
+public class PartitionSizeIterator implements PartitionReader<InternalRow>
+{
+    private final StreamScanner<IndexEntry> it;
+    private final CqlTable cqlTable;
+    private final int numPartitionKeys;
+    private final Stats stats;
+    private final long startTimeNanos;
+    private GenericInternalRow curr = null;
+
+    public PartitionSizeIterator(final int partitionId, @NotNull final 
DataLayer dataLayer)
+    {
+        this.cqlTable = dataLayer.cqlTable();
+        this.numPartitionKeys = cqlTable.numPartitionKeys();
+        this.stats = dataLayer.stats();
+        this.startTimeNanos = System.nanoTime();
+        this.it = dataLayer.openPartitionSizeIterator(partitionId);
+        stats.openedPartitionSizeIterator(System.nanoTime() - startTimeNanos);
+    }
+
+    public boolean next() throws IOException
+    {
+        if (it.hasNext())
+        {
+            it.advanceToNextColumn();
+
+            final IndexEntry entry = it.rid();
+            final Object[] values = new Object[numPartitionKeys + 2];
+
+            SparkCellIterator.readPartitionKey(entry.getPartitionKey(), 
cqlTable, values, stats);
+            values[numPartitionKeys] = entry.getUncompressed();
+            values[numPartitionKeys + 1] = entry.getCompressed();

Review Comment:
   nit: add a comment to associate the data population with the schema defined 
at `partitionSizeStructType` in `DataLayer`. 



-- 
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: commits-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to