lukasz-antoniak commented on code in PR #110:
URL: 
https://github.com/apache/cassandra-analytics/pull/110#discussion_r2182639647


##########
cassandra-five-zero-bridge/src/main/java/org/apache/cassandra/spark/reader/CompressionMetadata.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.reader;
+
+import java.io.DataInputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cassandra.io.compress.ICompressor;
+import org.apache.cassandra.io.util.File;
+import org.apache.cassandra.io.util.Memory;
+import org.apache.cassandra.schema.CompressionParams;
+import org.apache.cassandra.spark.reader.common.AbstractCompressionMetadata;
+import org.apache.cassandra.spark.reader.common.BigLongArray;
+
+/**
+ * Holds metadata about compressed file
+ */
+// CompressionMetadata is mocked in IndexReaderTests and mockito does not 
support mocking final classes
+// CHECKSTYLE IGNORE: FinalClass
+public class CompressionMetadata extends AbstractCompressionMetadata
+{
+    private final CompressionParams parameters;
+    private final int chunkCount;
+
+    private CompressionMetadata(long dataLength, int chunkCount, BigLongArray 
chunkOffsets, CompressionParams parameters)
+    {
+        super(dataLength, chunkOffsets);
+        this.chunkCount = chunkCount;
+        this.parameters = parameters;
+    }
+
+    static CompressionMetadata fromInputStream(InputStream inStream, boolean 
hasCompressedLength) throws IOException
+    {
+        long dataLength;
+        BigLongArray chunkOffsets;
+
+        DataInputStream inData = new DataInputStream(inStream);
+
+        String compressorName = inData.readUTF();
+        int optionCount = inData.readInt();
+        Map<String, String> options = new HashMap<>(optionCount);
+        for (int option = 0; option < optionCount; ++option)
+        {
+            options.put(inData.readUTF(), inData.readUTF());
+        }
+
+        int chunkLength = inData.readInt();
+        int minCompressRatio = 2147483647;
+        if (hasCompressedLength)
+        {
+            minCompressRatio = inData.readInt();
+        }
+
+        CompressionParams params = new CompressionParams(compressorName, 
chunkLength, minCompressRatio, options);
+        // TODO(c4c5): CRC check change gone?
+        // 
params.setCrcCheckChance(AbstractCompressionMetadata.CRC_CHECK_CHANCE);
+
+        dataLength = inData.readLong();
+
+        int chunkCount = inData.readInt();
+        chunkOffsets = new BigLongArray(chunkCount);
+
+        for (int chunk = 0; chunk < chunkCount; chunk++)
+        {
+            try
+            {
+                long l = inData.readLong();
+                chunkOffsets.set(chunk, l);
+            }
+            catch (EOFException exception)
+            {
+                throw new EOFException(String.format("Corrupted compression 
index: read %d but expected %d chunks.",
+                                                     chunk, chunkCount));
+            }
+        }
+
+        return new CompressionMetadata(dataLength, chunkCount, chunkOffsets, 
params);
+    }
+
+    ICompressor compressor()
+    {
+        return parameters.getSstableCompressor();
+    }
+
+    @Override
+    protected int chunkLength()
+    {
+        return parameters.chunkLength();
+    }
+
+    @Override
+    protected double crcCheckChance()
+    {
+        // TODO(c4c5): CRC check change gone?
+        // return parameters.getCrcCheckChance();
+        return 1.0;
+    }
+
+    // TODO(c4c5): Find better way to create Cassandra CompressionMetadata.
+    public org.apache.cassandra.io.compress.CompressionMetadata 
toInternal(File file, long compressedFileLength)
+    {
+        // TODO(c4c5): Duplicated memory allocation for Memory and 
BigLongArray.
+        Memory chunkOffsetsMem = Memory.allocate(chunkCount * 8L);

Review Comment:
   Should we implement here class that extends `Memory`, but uses 
`chunkOffsets` underneath?



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