jkylling commented on code in PR #7307: URL: https://github.com/apache/arrow-rs/pull/7307#discussion_r2083606207
########## parquet/src/arrow/array_reader/row_number.rs: ########## @@ -0,0 +1,154 @@ +// 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::arrow::array_reader::ArrayReader; +use crate::errors::{ParquetError, Result}; +use crate::file::metadata::RowGroupMetaData; +use arrow_array::{ArrayRef, Int64Array}; +use arrow_schema::DataType; +use std::any::Any; +use std::collections::VecDeque; +use std::sync::Arc; + +pub(crate) struct RowNumberReader { + row_numbers: Vec<i64>, + row_groups: RowGroupSizeIterator, +} + +impl RowNumberReader { + pub(crate) fn try_new<I>(row_groups: impl IntoIterator<Item = I>) -> Result<Self> + where + I: TryInto<RowGroupSize, Error = ParquetError>, + { + let row_groups = RowGroupSizeIterator::try_new(row_groups)?; + Ok(Self { + row_numbers: Vec::new(), + row_groups, + }) + } +} + +impl ArrayReader for RowNumberReader { + fn as_any(&self) -> &dyn Any { + self + } + + fn get_data_type(&self) -> &DataType { + &DataType::Int64 + } + + fn read_records(&mut self, batch_size: usize) -> Result<usize> { + let read = self + .row_groups + .read_records(batch_size, &mut self.row_numbers); + Ok(read) + } + + fn consume_batch(&mut self) -> Result<ArrayRef> { + Ok(Arc::new(Int64Array::from_iter(self.row_numbers.drain(..)))) + } + + fn skip_records(&mut self, num_records: usize) -> Result<usize> { + let skipped = self.row_groups.skip_records(num_records); + Ok(skipped) + } + + fn get_def_levels(&self) -> Option<&[i16]> { + None + } + + fn get_rep_levels(&self) -> Option<&[i16]> { + None + } +} + +struct RowGroupSizeIterator { + row_groups: VecDeque<RowGroupSize>, +} + +impl RowGroupSizeIterator { + fn try_new<I>(row_groups: impl IntoIterator<Item = I>) -> Result<Self> + where + I: TryInto<RowGroupSize, Error = ParquetError>, Review Comment: @scovich I see you are involved in the maintenance of delta-kernel-rs. If you are interested, I've started on an implementation of deletion vector read support in delta-rs in [this branch](https://github.com/delta-io/delta-rs/compare/main...jkylling:delta-rs:feature/deletion-vectors), based on a back port of an early version of this PR to arrow-54.2.1. The PR is still very rough, but the read path has got okay test coverage and it's able to read tables with deletion vectors produced by Spark correctly. The write support for deletion vectors is rudimentary (deletion vectors are only used for deletes when configured, and deleting from the same file twice is unsupported), and is mostly there to be able to unit test the read support. Unfortunately, I've not had time to wokr on this lately. -- 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-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org