This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f583531
commit 605ba4c
Showing
7 changed files
with
97 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! APIs to read from Avro format to arrow. | ||
use crate::error::Result; | ||
|
||
use super::Compression; | ||
use super::{Block, CompressedBlock}; | ||
|
||
/// Compresses a [`Block`] to a [`CompressedBlock`]. | ||
pub fn compress( | ||
block: &mut Block, | ||
compressed: &mut CompressedBlock, | ||
compression: Option<Compression>, | ||
) -> Result<bool> { | ||
compressed.number_of_rows = block.number_of_rows; | ||
let block = &mut block.data; | ||
let compressed = &mut compressed.data; | ||
|
||
match compression { | ||
None => { | ||
std::mem::swap(block, compressed); | ||
Ok(true) | ||
} | ||
#[cfg(feature = "io_avro_compression")] | ||
Some(Compression::Deflate) => { | ||
use std::io::Write; | ||
compressed.clear(); | ||
let mut encoder = libflate::deflate::Encoder::new(compressed); | ||
encoder.write_all(block)?; | ||
encoder.finish(); | ||
Ok(false) | ||
} | ||
#[cfg(feature = "io_avro_compression")] | ||
Some(Compression::Snappy) => { | ||
use snap::raw::{max_compress_len, Encoder}; | ||
|
||
compressed.clear(); | ||
|
||
let required_len = max_compress_len(block.len()); | ||
compressed.resize(required_len, 0); | ||
let compressed_bytes = Encoder::new() | ||
.compress(block, compressed) | ||
.map_err(|e| crate::error::ArrowError::ExternalFormat(e.to_string()))?; | ||
compressed.truncate(compressed_bytes); | ||
|
||
let crc = crc::crc32::checksum_ieee(block); | ||
compressed.extend(crc.to_be_bytes()); | ||
Ok(false) | ||
} | ||
#[cfg(not(feature = "io_avro_compression"))] | ||
Some(Compression::Deflate) => Err(crate::error::ArrowError::InvalidArgumentError( | ||
"Trying to compress Avro with deflate but feature 'io_avro_compression' is not active." | ||
.to_string(), | ||
)), | ||
#[cfg(not(feature = "io_avro_compression"))] | ||
Some(Compression::Snappy) => Err(crate::error::ArrowError::InvalidArgumentError( | ||
"Trying to compress Avro with snappy but feature 'io_avro_compression' is not active." | ||
.to_string(), | ||
)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters