laskoviymishka commented on code in PR #3230: URL: https://github.com/apache/iceberg-rust/pull/3230#discussion_r4046963458
########## crates/iceberg/src/writer/base_writer/position_delete_input.rs: ########## @@ -0,0 +1,333 @@ +// 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. + +//! Assembles a spec-conforming position delete [`RecordBatch`] from `(file_path, pos)` rows. +//! +//! A [`PositionDeleteFileWriter`](super::position_delete_writer::PositionDeleteFileWriter) +//! accepts batches with exactly the two required position delete columns: `file_path` +//! (`Utf8`, field id [`crate::metadata_columns::RESERVED_FIELD_ID_DELETE_FILE_PATH`]) and +//! `pos` (`Int64`, field id [`crate::metadata_columns::RESERVED_FIELD_ID_DELETE_FILE_POS`]), +//! both required. [`position_delete_batch`] produces exactly such a batch, with rows sorted +//! by `(file_path, pos)` and duplicate pairs removed, as the spec requires for position +//! delete files. +//! +//! Position delete files are a v2 construct. v3 tables use deletion vectors and forbid adding +//! new position delete files, so a format-version gate must be applied at the +//! transaction/commit layer before routing v3 writes here. + +use std::collections::BTreeMap; +use std::sync::Arc; + +use arrow_array::{ArrayRef, Int64Array, RecordBatch, StringArray}; +use roaring::RoaringTreemap; + +use crate::{Error, ErrorKind, Result}; + +/// Builds a spec-conforming position delete [`RecordBatch`] from `(file_path, pos)` rows. +/// +/// The returned batch has exactly the two required position delete columns and passes the +/// per-batch validation of +/// [`PositionDeleteFileWriter`](super::position_delete_writer::PositionDeleteFileWriter), so +/// it can be handed straight to that writer. Rows are emitted sorted by `(file_path, pos)` +/// with duplicate pairs removed, satisfying the spec's ordering requirement regardless of the +/// order in which they are supplied. Empty input yields a valid 0-row batch. +/// +/// `pos` is a non-negative row position; a negative `pos` is rejected with +/// [`ErrorKind::DataInvalid`]. +/// +/// # Example +/// +/// ``` +/// use iceberg::writer::base_writer::position_delete_input::position_delete_batch; +/// +/// // Rows may be supplied in any order; the batch comes out sorted. +/// let batch = position_delete_batch([ +/// ("s3://bucket/data/f0.parquet", 4), +/// ("s3://bucket/data/f0.parquet", 1), +/// ]) +/// .unwrap(); +/// assert_eq!(batch.num_rows(), 2); +/// assert_eq!(batch.num_columns(), 2); +/// ``` +pub fn position_delete_batch<S, I>(rows: I) -> Result<RecordBatch> Review Comment: Yeah, I circled this and agree with you. Reshaped it into `PositionDeletes { rows: BTreeMap<String, RoaringTreemap> `: accumulate deletes with `insert(path, pos)` as you find them, then `to_record_batch()` materializes the two required columns already sorted by `(file_path, pos)` and deduped, ready to hand to `PositionDeleteFileWriter`. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
