Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support all decompression types #20

Merged
merged 2 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ flate2 = "1"
futures = { version = "0.3", default-features = false, features = ["std"] }
futures-util = "0.3"
lazy_static = "1.4"
lz4_flex = "0.11"
lzokay-native = "0.1"
paste = "1.0"
prost = { version = "0.11" }
snafu = "0.7"
snap = "1.1"
tokio = { version = "1.28", features = [
"io-util",
"sync",
Expand Down
6 changes: 5 additions & 1 deletion src/arrow_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::arrow_reader::column::timestamp::new_timestamp_iter;
use crate::arrow_reader::column::NullableIterator;
use crate::error::{self, Result};
use crate::proto::{StripeFooter, StripeInformation};
use crate::reader::decompress::Compression;
use crate::reader::schema::{create_field, TypeDescription};
use crate::reader::Reader;

Expand Down Expand Up @@ -427,7 +428,10 @@ impl Stripe {
) -> Result<Self> {
let footer = Arc::new(r.stripe_footer(stripe).clone());

let compression = r.metadata().postscript.compression();
let compression = Compression::from_proto(
r.metadata().postscript.compression(),
r.metadata().postscript.compression_block_size,
);
Comment on lines +431 to +434
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe eventually can store Compression directly as field in FileMetadata so don't need to derive each time

//TODO(weny): add tz
let columns = columns
.iter()
Expand Down
10 changes: 5 additions & 5 deletions src/arrow_reader/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use tokio::io::{AsyncRead, AsyncReadExt, AsyncSeek, AsyncSeekExt};

use crate::error::{self, Result};
use crate::proto::stream::Kind;
use crate::proto::{ColumnEncoding, CompressionKind, StripeFooter, StripeInformation};
use crate::reader::decompress::Decompressor;
use crate::proto::{ColumnEncoding, StripeFooter, StripeInformation};
use crate::reader::decompress::{Compression, Decompressor};
use crate::reader::schema::TypeDescription;
use crate::reader::Reader;

Expand All @@ -25,7 +25,7 @@ pub mod timestamp;
pub struct Column {
data: Bytes,
number_of_rows: u64,
compression: CompressionKind,
compression: Option<Compression>,
footer: Arc<StripeFooter>,
name: String,
column: Arc<TypeDescription>,
Expand Down Expand Up @@ -99,7 +99,7 @@ impl Column {

pub fn new<R: Read + Seek>(
reader: &mut Reader<R>,
compression: CompressionKind,
compression: Option<Compression>,
name: &str,
column: &Arc<TypeDescription>,
footer: &Arc<StripeFooter>,
Expand All @@ -120,7 +120,7 @@ impl Column {

pub async fn new_async<R: AsyncRead + AsyncSeek + Unpin + Send>(
reader: &mut Reader<R>,
compression: CompressionKind,
compression: Option<Compression>,
name: &str,
column: &Arc<TypeDescription>,
footer: &Arc<StripeFooter>,
Expand Down
15 changes: 9 additions & 6 deletions src/arrow_reader/column/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ pub struct DateIterator {
}

pub fn convert_date(data: i64) -> Result<NaiveDate> {
let date = NaiveDate::from_ymd_opt(1970, 1, 1)
.context(error::InvalidDateSnafu)?
.checked_add_days(Days::new(data as u64))
.context(error::AddDaysSnafu)?;

Ok(date)
let days = Days::new(data.unsigned_abs());
// safe unwrap as is valid date
let epoch = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap();
let date = if data.is_negative() {
epoch.checked_sub_days(days)
} else {
epoch.checked_add_days(days)
};
date.context(error::AddDaysSnafu)
Comment on lines +17 to +25
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix to support dates before epoch

}

impl Iterator for DateIterator {
Expand Down
6 changes: 5 additions & 1 deletion src/async_arrow_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::arrow_reader::{
};
use crate::error::Result;
use crate::proto::StripeInformation;
use crate::reader::decompress::Compression;
use crate::reader::schema::TypeDescription;
use crate::reader::Reader;

Expand Down Expand Up @@ -188,7 +189,10 @@ impl Stripe {
) -> Result<Self> {
let footer = Arc::new(r.stripe_footer(stripe).clone());

let compression = r.metadata().postscript.compression();
let compression = Compression::from_proto(
r.metadata().postscript.compression(),
r.metadata().postscript.compression_block_size,
);
//TODO(weny): add tz
let mut columns = Vec::with_capacity(column_defs.len());
for (name, typ) in column_defs.iter() {
Expand Down
18 changes: 18 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ pub enum Error {
location: Location,
source: io::Error,
},

#[snafu(display("Failed to build snappy decoder: {}", source))]
BuildSnappyDecoder {
location: Location,
source: snap::Error,
},

#[snafu(display("Failed to build lzo decoder: {}", source))]
BuildLzoDecoder {
location: Location,
source: lzokay_native::Error,
},

#[snafu(display("Failed to build lz4 decoder: {}", source))]
BuildLz4Decoder {
location: Location,
source: lz4_flex::block::DecompressError,
},
}

pub type Result<T> = std::result::Result<T, Error>;
Loading
Loading