You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2021/09/28 16:50:47 UTC

[GitHub] [drill] dzamo commented on a change in pull request #2321: DRILL-7969: Read and write Parquet with brotli, lzo, lz4, zstd codecs

dzamo commented on a change in pull request #2321:
URL: https://github.com/apache/drill/pull/2321#discussion_r717769319



##########
File path: exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet/compression/AirliftBytesInputCompressor.java
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.drill.exec.store.parquet.compression;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Stack;
+
+import org.apache.parquet.bytes.ByteBufferAllocator;
+import org.apache.parquet.bytes.BytesInput;
+import org.apache.parquet.compression.CompressionCodecFactory;
+import org.apache.parquet.hadoop.metadata.CompressionCodecName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.airlift.compress.Compressor;
+import io.airlift.compress.Decompressor;
+import io.airlift.compress.lz4.Lz4Compressor;
+import io.airlift.compress.lz4.Lz4Decompressor;
+import io.airlift.compress.lzo.LzoCompressor;
+import io.airlift.compress.lzo.LzoDecompressor;
+import io.airlift.compress.snappy.SnappyCompressor;
+import io.airlift.compress.snappy.SnappyDecompressor;
+import io.airlift.compress.zstd.ZstdCompressor;
+import io.airlift.compress.zstd.ZstdDecompressor;
+
+/**
+ * A shim making an aircompressor (de)compressor available through the BytesInputCompressor
+ * and BytesInputDecompressor interfaces.
+ */
+public class AirliftBytesInputCompressor implements CompressionCodecFactory.BytesInputCompressor, CompressionCodecFactory.BytesInputDecompressor {
+  private static final Logger logger = LoggerFactory.getLogger(AirliftBytesInputCompressor.class);
+
+  // name of the codec provided by this compressor
+  private CompressionCodecName codecName;
+
+  // backing aircompressor compressor
+  private Compressor airComp = null;
+
+  // backing aircompressor decompressor
+  private Decompressor airDecomp = null;
+
+  // the direct memory allocator to be used for (de)compression outputs
+  private ByteBufferAllocator allocator;
+
+  // all the direct memory buffers we've allocated, and must release
+  private Stack<ByteBuffer> allocatedBuffers;
+
+  public AirliftBytesInputCompressor(CompressionCodecName codecName, ByteBufferAllocator allocator) {
+    this.codecName = codecName;
+
+    switch (codecName) {
+    case LZ4:
+      airComp = new Lz4Compressor();
+      airDecomp = new Lz4Decompressor();
+      break;
+    case LZO:
+      airComp = new LzoCompressor();
+      airDecomp = new LzoDecompressor();
+      break;
+    case SNAPPY:
+      airComp = new SnappyCompressor();
+      airDecomp = new SnappyDecompressor();
+      break;
+    case ZSTD:
+      airComp = new ZstdCompressor();
+      airDecomp = new ZstdDecompressor();
+      break;
+    default:
+      throw new UnsupportedOperationException("Parquet compression codec is not supported: " + codecName);
+    }
+
+    this.allocator = allocator;
+    this.allocatedBuffers = new Stack<>();
+
+    logger.debug(String.format(
+        "constructed a %s using a backing compressor of %s",
+        getClass().getName(),
+        airComp.getClass().getName()
+    ));

Review comment:
       Clever!




-- 
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: dev-unsubscribe@drill.apache.org

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