laskoviymishka commented on code in PR #3231: URL: https://github.com/apache/iceberg-rust/pull/3231#discussion_r4046929008
########## crates/iceberg/src/writer/delta_writer/record_ops.rs: ########## @@ -0,0 +1,602 @@ +// 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. + +//! Splitting a change-type [`RecordBatch`] into insert and delete batches. +//! +//! A delta writer receives a single stream of row-level changes where each row +//! carries a `_change_type` indicator describing what kind of change it is. This +//! is the repo's [`_change_type`](RESERVED_COL_NAME_CHANGE_TYPE) convention: a +//! non-nullable [`Utf8`] column whose value is one of [`CHANGE_TYPE_INSERT`], +//! [`CHANGE_TYPE_DELETE`], [`CHANGE_TYPE_UPDATE_BEFORE`], or +//! [`CHANGE_TYPE_UPDATE_AFTER`]. +//! +//! [`split_by_change_type`] partitions such a batch into the insert and delete +//! payloads that the underlying data and delete writers consume, collapsing the +//! four change types onto two sides the way Java's `BaseDeltaTaskWriter` does: +//! `INSERT` and `UPDATE_AFTER` become inserts, `DELETE` and `UPDATE_BEFORE` +//! become deletes. The `_change_type` column is stripped from both outputs. +//! +//! This is a building block for the `DeltaWriter` epic (see +//! <https://github.com/apache/iceberg-rust/issues/2218>). +//! +//! [`RecordBatch`]: arrow_array::RecordBatch +//! [`Utf8`]: arrow_schema::DataType::Utf8 + +use std::sync::Arc; + +use arrow_arith::boolean::not; +use arrow_array::{Array, BooleanArray, RecordBatch, StringArray}; +use arrow_buffer::BooleanBufferBuilder; +use arrow_schema::{DataType, Schema}; +use arrow_select::filter::filter_record_batch; + +use crate::metadata_columns::RESERVED_COL_NAME_CHANGE_TYPE; +use crate::{Error, ErrorKind, Result}; + +/// `_change_type` value marking a row as an insert. +pub(crate) const CHANGE_TYPE_INSERT: &str = "INSERT"; +/// `_change_type` value marking a row as a delete. +pub(crate) const CHANGE_TYPE_DELETE: &str = "DELETE"; +/// `_change_type` value marking the pre-image of an updated row. +pub(crate) const CHANGE_TYPE_UPDATE_BEFORE: &str = "UPDATE_BEFORE"; +/// `_change_type` value marking the post-image of an updated row. +pub(crate) const CHANGE_TYPE_UPDATE_AFTER: &str = "UPDATE_AFTER"; + +/// The result of splitting a change-type batch with [`split_by_change_type`]. +/// +/// Both batches share the same schema: the schema of the input batch with the +/// `_change_type` column removed. Field metadata (including Parquet field ids) +/// and the schema-level metadata are preserved. +#[derive(Debug)] +pub struct SplitBatches { Review Comment: agree, fixed -- 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]
