-
Notifications
You must be signed in to change notification settings - Fork 762
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
bump arrow2 to main #4212
Merged
Merged
bump arrow2 to main #4212
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,81 @@ | ||
// Copyright 2022 Datafuse Labs. | ||
// | ||
// Licensed 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 arrow::datatypes::Field; | ||
use arrow::error::Result; | ||
use arrow::io::parquet::read::to_deserializer; | ||
use arrow::io::parquet::read::ArrayIter; | ||
use futures::AsyncRead; | ||
use futures::AsyncReadExt; | ||
use futures::AsyncSeek; | ||
use futures::AsyncSeekExt; | ||
use parquet2::metadata::ColumnChunkMetaData; | ||
use parquet2::metadata::RowGroupMetaData; | ||
|
||
fn get_field_columns<'a>( | ||
columns: &'a [ColumnChunkMetaData], | ||
field_name: &str, | ||
) -> Vec<&'a ColumnChunkMetaData> { | ||
columns | ||
.iter() | ||
.filter(|x| x.descriptor().path_in_schema()[0] == field_name) | ||
.collect() | ||
} | ||
|
||
async fn _read_single_column_async<R>( | ||
reader: &mut R, | ||
meta: &ColumnChunkMetaData, | ||
) -> Result<Vec<u8>> | ||
where | ||
R: AsyncRead + AsyncSeek + Send + Unpin, | ||
{ | ||
let (start, len) = meta.byte_range(); | ||
reader.seek(std::io::SeekFrom::Start(start)).await?; | ||
let mut chunk = vec![0; len as usize]; | ||
reader.read_exact(&mut chunk).await?; | ||
Result::Ok(chunk) | ||
} | ||
|
||
async fn read_columns_async<'a, R: AsyncRead + AsyncSeek + Send + Unpin>( | ||
reader: &mut R, | ||
columns: &'a [ColumnChunkMetaData], | ||
field_name: &str, | ||
) -> Result<Vec<(&'a ColumnChunkMetaData, Vec<u8>)>> { | ||
let col_metas = get_field_columns(columns, field_name); | ||
let mut cols = Vec::with_capacity(col_metas.len()); | ||
for meta in col_metas { | ||
cols.push((meta, _read_single_column_async(reader, meta).await?)) | ||
} | ||
Ok(cols) | ||
} | ||
|
||
// used when we can not use arrow::io::parquet::read::read_columns_many_async which need a factory of reader | ||
pub async fn read_columns_many_async<'a, R: AsyncRead + AsyncSeek + Send + Unpin>( | ||
reader: &mut R, | ||
row_group: &RowGroupMetaData, | ||
fields: Vec<&Field>, | ||
chunk_size: Option<usize>, | ||
) -> Result<Vec<ArrayIter<'a>>> { | ||
let mut arrays = Vec::with_capacity(fields.len()); | ||
for field in fields { | ||
let columns = read_columns_async(reader, row_group.columns(), &field.name).await?; | ||
arrays.push(to_deserializer( | ||
columns, | ||
field.to_owned(), | ||
row_group.num_rows() as usize, | ||
chunk_size, | ||
)?); | ||
} | ||
Ok(arrays) | ||
} |
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,46 @@ | ||
// Copyright 2022 Datafuse Labs. | ||
// | ||
// Licensed 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 std::io::Write; | ||
|
||
use arrow::array::Array; | ||
use arrow::chunk::Chunk; | ||
use arrow::datatypes::Schema; | ||
use arrow::error::Result; | ||
use arrow::io::parquet::write::FileWriter; | ||
use arrow::io::parquet::write::RowGroupIterator; | ||
use parquet2::write::WriteOptions; | ||
|
||
// a simple wrapper for code reuse | ||
pub fn write_parquet_file<W: Write, A, I>( | ||
writer: &mut W, | ||
row_groups: RowGroupIterator<A, I>, | ||
schema: Schema, | ||
options: WriteOptions, | ||
) -> Result<u64> | ||
where | ||
W: Write, | ||
A: AsRef<dyn Array> + 'static + Send + Sync, | ||
I: Iterator<Item = Result<Chunk<A>>>, | ||
{ | ||
let mut file_writer = FileWriter::try_new(writer, schema, options)?; | ||
|
||
file_writer.start()?; | ||
for group in row_groups { | ||
let (group, len) = group?; | ||
file_writer.write(group, len)?; | ||
} | ||
let (size, _) = file_writer.end(None)?; | ||
Ok(size) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to make IO run on parallel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about accepting an
Operator
orObject
here to create different readers for different columns?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my version of read_columns_many_async is not parallel.
need it because SourceFactory pass a Reader to ParquetSource
https://github.com/datafuselabs/databend/blob/b41d39b05dcf281db921377d8b027477d333f8b6/common/streams/src/sources/source_factory.rs#L32
the one in arrow2 is parallel, it is ok to use it in block_reader.
https://github.com/jorgecarleitao/arrow2/blob/3d528c99589e96f0539de4c07b11843fa22f23ac/src/io/parquet/read/row_group.rs#L166
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So let's export
_read_single_column_async
as pub, we can use it inblock_reader
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, block_reader already used it, I mean maybe SourceFactory can accept something like (data_accessor, path). even use factory justlike arrow2, and struct(data_accessor, path) an impl of it