-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
11 changed files
with
208 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use arrow::array::MapBuilder; | ||
use snafu::{OptionExt, ResultExt}; | ||
|
||
use super::present::new_present_iter; | ||
use super::Column; | ||
use crate::arrow_reader::{reader_factory, BoxedArrayBuilder, Decoder, Stripe}; | ||
use crate::error::{self, Result}; | ||
use crate::proto::stream::Kind; | ||
use crate::reader::decode::RleVersion; | ||
|
||
pub struct MapDecoder { | ||
pub(crate) key: Box<Decoder>, | ||
pub(crate) value: Box<Decoder>, | ||
present: Box<dyn Iterator<Item = bool> + Send>, | ||
lengths: Box<dyn Iterator<Item = Result<u64>> + Send>, | ||
} | ||
|
||
impl MapDecoder { | ||
fn append_value( | ||
&mut self, | ||
root_builder: &mut MapBuilder<BoxedArrayBuilder, BoxedArrayBuilder>, | ||
) -> Result<()> { | ||
let len = self.lengths.next().unwrap()?; | ||
let _ = self | ||
.key | ||
.append_value(&mut root_builder.keys().builder, len as usize); | ||
let _ = self | ||
.value | ||
.append_value(&mut root_builder.values().builder, len as usize); | ||
Ok(()) | ||
} | ||
|
||
fn next( | ||
&mut self, | ||
root_builder: &mut MapBuilder<BoxedArrayBuilder, BoxedArrayBuilder>, | ||
) -> Option<Result<()>> { | ||
match self.present.next() { | ||
Some(present) => { | ||
if present { | ||
if let Err(err) = self.append_value(root_builder) { | ||
return Some(Err(err)); | ||
} | ||
} | ||
if let Err(err) = root_builder.append(present).context(error::MapBuilderSnafu) { | ||
return Some(Err(err)); | ||
}; | ||
} | ||
None => return None, | ||
} | ||
|
||
Some(Ok(())) | ||
} | ||
|
||
pub fn collect_chunk( | ||
&mut self, | ||
root_builder: &mut MapBuilder<BoxedArrayBuilder, BoxedArrayBuilder>, | ||
chunk: usize, | ||
) -> Option<Result<()>> { | ||
for _ in 0..chunk { | ||
match self.next(root_builder) { | ||
Some(Ok(_)) => { | ||
// continue | ||
} | ||
Some(Err(err)) => return Some(Err(err)), | ||
None => break, | ||
} | ||
} | ||
|
||
Some(Ok(())) | ||
} | ||
} | ||
|
||
pub fn new_map_iter(column: &Column, stripe: &Stripe) -> Result<MapDecoder> { | ||
let present = new_present_iter(column, stripe)?.collect::<Result<Vec<_>>>()?; | ||
let version: RleVersion = column.encoding().kind().into(); | ||
let lengths = stripe | ||
.stream_map | ||
.get(column, Kind::Length) | ||
.map(|reader| version.get_unsigned_rle_reader(reader)) | ||
.context(error::InvalidColumnSnafu { name: &column.name })?; | ||
|
||
let children = column.children(); | ||
let key = &children[0]; | ||
let value = &children[1]; | ||
|
||
let key = reader_factory(key, stripe)?; | ||
let value = reader_factory(value, stripe)?; | ||
|
||
Ok(MapDecoder { | ||
key: Box::new(key), | ||
value: Box::new(value), | ||
present: Box::new(present.into_iter()), | ||
lengths, | ||
}) | ||
} |
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,34 @@ | ||
use arrow::array::{ArrayBuilder, ArrayRef}; | ||
|
||
/// BoxedArrayBuilder | ||
/// | ||
/// It implements the [ArrayBuilder] and [Sized] trait. | ||
pub struct BoxedArrayBuilder { | ||
pub(crate) builder: Box<dyn ArrayBuilder>, | ||
} | ||
|
||
impl ArrayBuilder for BoxedArrayBuilder { | ||
fn len(&self) -> usize { | ||
self.builder.len() | ||
} | ||
|
||
fn finish(&mut self) -> ArrayRef { | ||
self.builder.finish() | ||
} | ||
|
||
fn finish_cloned(&self) -> ArrayRef { | ||
self.builder.finish_cloned() | ||
} | ||
|
||
fn as_any(&self) -> &dyn std::any::Any { | ||
self.builder.as_any() | ||
} | ||
|
||
fn as_any_mut(&mut self) -> &mut dyn std::any::Any { | ||
self.builder.as_any_mut() | ||
} | ||
|
||
fn into_box_any(self: Box<Self>) -> Box<dyn std::any::Any> { | ||
self.builder.into_box_any() | ||
} | ||
} |
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
Binary file not shown.
Binary file not shown.
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