SteNicholas commented on code in PR #269: URL: https://github.com/apache/paimon-cpp/pull/269#discussion_r3923896883
########## src/paimon/core/realtime/realtime_offset_batch_reader.cpp: ########## @@ -0,0 +1,106 @@ +/* + * 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. + */ + +#include "paimon/core/realtime/realtime_offset_batch_reader.h" + +#include <cstdint> +#include <memory> +#include <utility> + +#include "arrow/array/array_base.h" +#include "arrow/array/array_nested.h" +#include "arrow/array/array_primitive.h" +#include "arrow/c/bridge.h" +#include "fmt/format.h" +#include "paimon/common/table/special_fields.h" +#include "paimon/common/utils/arrow/arrow_utils.h" +#include "paimon/common/utils/arrow/status_utils.h" +#include "paimon/common/utils/checked_cast.h" +#include "paimon/metrics.h" +#include "paimon/status.h" + +namespace paimon { +RealtimeOffsetBatchReader::RealtimeOffsetBatchReader(std::unique_ptr<BatchReader>&& reader, + const OffsetRange& visible_offsets) + : reader_(std::move(reader)), visible_offsets_(visible_offsets) {} + +Result<BatchReader::ReadBatch> RealtimeOffsetBatchReader::NextBatch() { + return Status::Invalid( + "paimon inner reader RealtimeOffsetBatchReader should use NextBatchWithBitmap"); +} + +Result<BatchReader::ReadBatchWithBitmap> RealtimeOffsetBatchReader::NextBatchWithBitmap() { + while (true) { + PAIMON_ASSIGN_OR_RAISE(ReadBatchWithBitmap batch_with_bitmap, + reader_->NextBatchWithBitmap()); + if (IsEofBatch(batch_with_bitmap)) { + return batch_with_bitmap; + } + auto& [batch, input_bitmap] = batch_with_bitmap; + auto& [c_array, c_schema] = batch; + PAIMON_ASSIGN_OR_RAISE_FROM_ARROW(std::shared_ptr<arrow::Array> arrow_array, + arrow::ImportArray(c_array.get(), c_schema.get())); + if (!arrow_array || arrow_array->type_id() != arrow::Type::STRUCT) { + return Status::Invalid("realtime query batch must be a StructArray"); + } + std::shared_ptr<arrow::StructArray> struct_array = + checked_pointer_cast<arrow::StructArray>(arrow_array); + std::shared_ptr<arrow::Array> offset_field = + struct_array->GetFieldByName(SpecialFields::RealtimeOffset().Name()); + if (!offset_field || offset_field->type_id() != arrow::Type::INT64) { + return Status::Invalid("realtime query batch must contain int64 _REALTIME_OFFSET"); + } + std::shared_ptr<arrow::Int64Array> offsets = + checked_pointer_cast<arrow::Int64Array>(offset_field); + if (offsets->null_count() != 0) { + return Status::Invalid("realtime query offset column contains null"); + } + + RoaringBitmap32 output_bitmap; Review Comment: This adapter keeps only rows selected by the store bitmap. PK queries pass `predicate=nullptr`, so every raw mutation must participate in MOR; a partial bitmap can silently omit the newest update or delete and let an older disk row resurface. The previous PK adapter explicitly required the bitmap cardinality to equal the batch length. Please preserve that check for PK query readers, for example through a strict/all-rows pipeline mode. -- 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]
