lukasz-antoniak commented on code in PR #110: URL: https://github.com/apache/cassandra-analytics/pull/110#discussion_r2194142263
########## cassandra-five-zero-bridge/src/main/java/org/apache/cassandra/spark/reader/CompressionMetadata.java: ########## @@ -0,0 +1,134 @@ +/* + * 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 Memory chunkOffsetsMem; + + private CompressionMetadata(long dataLength, Memory chunkOffsetsMem, BigLongArray chunkOffsets, CompressionParams parameters) + { + super(dataLength, chunkOffsets); + this.chunkOffsetsMem = chunkOffsetsMem; + 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); Review Comment: I have moved around handing of CRC check chance parameter in v5 bridge. -- 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]
