You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/28 13:57:26 UTC

[GitHub] [arrow-rs] pitrou commented on a diff in pull request #1855: support compression for IPC

pitrou commented on code in PR #1855:
URL: https://github.com/apache/arrow-rs/pull/1855#discussion_r908515907


##########
arrow/src/ipc/compression/ipc_compression.rs:
##########
@@ -0,0 +1,124 @@
+// 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.
+
+use crate::ipc::CompressionType;
+
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub enum CompressionCodecType {
+    NoCompression,
+    Lz4Frame,
+    Zstd,
+}
+
+impl From<CompressionType> for CompressionCodecType {
+    fn from(compression_type: CompressionType) -> Self {
+        match compression_type {
+            CompressionType::ZSTD => CompressionCodecType::Zstd,
+            CompressionType::LZ4_FRAME => CompressionCodecType::Lz4Frame,
+            _ => CompressionCodecType::NoCompression,
+        }
+    }
+}
+
+impl From<CompressionCodecType> for Option<CompressionType> {
+    fn from(codec: CompressionCodecType) -> Self {
+        match codec {
+            CompressionCodecType::NoCompression => None,
+            CompressionCodecType::Lz4Frame => Some(CompressionType::LZ4_FRAME),
+            CompressionCodecType::Zstd => Some(CompressionType::ZSTD),
+        }
+    }
+}
+
+#[cfg(any(feature = "zstd,lz4", test))]
+mod compression_function {
+    use crate::error::Result;
+    use crate::ipc::compression::ipc_compression::CompressionCodecType;
+    use std::io::{Read, Write};
+
+    impl CompressionCodecType {
+        pub fn compress(&self, input: &[u8], output: &mut Vec<u8>) -> Result<()> {
+            match self {
+                CompressionCodecType::Lz4Frame => {
+                    let mut encoder = lz4::EncoderBuilder::new().build(output).unwrap();

Review Comment:
   As [the doc](https://docs.rs/lz4/1.23.3/lz4/) seems to say, "This module provides access to the block mode functions of the lz4 C library".
   LZ4_FRAME compression requires the frame functions of the lz4 C library. Apparently you can use https://docs.rs/lz4_flex/latest/lz4_flex/ instead.



-- 
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: github-unsubscribe@arrow.apache.org

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