HaHaJeff commented on code in PR #224:
URL: https://github.com/apache/paimon-cpp/pull/224#discussion_r3855833666
##########
src/paimon/core/table/source/key_value_table_read.cpp:
##########
@@ -34,6 +50,62 @@ class Executor;
class FileStorePathFactory;
class InternalReadContext;
class MemoryPool;
+struct ColumnarBatchContext;
+
+namespace {
+
+Result<std::vector<std::unique_ptr<KeyValueRecordReader>>> CreateMemoryReaders(
+ const std::shared_ptr<RealtimeSplit>& split, const
RealtimePartitionBucketView& memory,
+ const std::shared_ptr<arrow::Schema>& key_schema,
+ const std::shared_ptr<arrow::Schema>& value_schema,
+ const std::shared_ptr<FieldsComparator>& key_comparator,
+ const std::shared_ptr<InternalReadContext>& context,
+ const std::shared_ptr<MemoryPool>& memory_pool) {
+ std::shared_ptr<arrow::Schema> full_value_schema =
+
DataField::ConvertDataFieldsToArrowSchema(context->GetTableSchema()->Fields());
+ arrow::FieldVector prepared_fields = {
+
DataField::ConvertDataFieldToArrowField(SpecialFields::ValueKind())->WithNullable(false),
+
DataField::ConvertDataFieldToArrowField(SpecialFields::SequenceNumber())
+ ->WithNullable(false),
+
DataField::ConvertDataFieldToArrowField(SpecialFields::RealtimeOffset())};
+ prepared_fields.insert(prepared_fields.end(),
full_value_schema->fields().begin(),
+ full_value_schema->fields().end());
+ std::shared_ptr<arrow::Schema> prepared_schema =
arrow::schema(std::move(prepared_fields));
+ auto c_schema = std::make_unique<ArrowSchema>();
+ PAIMON_RETURN_NOT_OK_FROM_ARROW(arrow::ExportSchema(*prepared_schema,
c_schema.get()));
+ ScopeGuard schema_guard([schema = c_schema.get()]() {
ArrowSchemaRelease(schema); });
+ RealtimeQueryContext query_context{c_schema.get(), nullptr, false};
+ PAIMON_ASSIGN_OR_RAISE(std::vector<std::unique_ptr<BatchReader>>
batch_readers,
+ memory.store->CreateQueryReaders(memory.read_view,
0, query_context));
Review Comment:
Fixed in `51671a68ef295fd55613c1da974279d5f13383d4`: the query schema is
built from the `MergeFileSplitRead` value schema instead of the full table
schema. The winning in-memory row still needs the projected output fields, not
only the primary key and sequence fields.
##########
src/paimon/core/realtime/prepared_key_value_reader.h:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <cstdint>
+#include <memory>
+#include <optional>
+#include <vector>
+
+#include "arrow/type_fwd.h"
+#include "paimon/core/io/key_value_record_reader.h"
+#include "paimon/realtime/offset_range.h"
+#include "paimon/result.h"
+
+namespace paimon {
+class BatchReader;
+class FieldsComparator;
+class MemoryPool;
+
+/// Validates the required leading fields of a prepared real-time transport
schema.
+Status ValidatePreparedTransportSchema(const std::shared_ptr<arrow::Schema>&
prepared_schema);
Review Comment:
Fixed in `13cba67b9ef802f9acebe6b0b997d1e44dc528bf`: these helpers are now
static methods of `PreparedKeyValueReaderFactory`.
##########
src/paimon/core/table/source/key_value_table_read.cpp:
##########
@@ -34,6 +50,62 @@ class Executor;
class FileStorePathFactory;
class InternalReadContext;
class MemoryPool;
+struct ColumnarBatchContext;
+
+namespace {
+
+Result<std::vector<std::unique_ptr<KeyValueRecordReader>>> CreateMemoryReaders(
+ const std::shared_ptr<RealtimeSplit>& split, const
RealtimePartitionBucketView& memory,
+ const std::shared_ptr<arrow::Schema>& key_schema,
+ const std::shared_ptr<arrow::Schema>& value_schema,
+ const std::shared_ptr<FieldsComparator>& key_comparator,
+ const std::shared_ptr<InternalReadContext>& context,
+ const std::shared_ptr<MemoryPool>& memory_pool) {
+ std::shared_ptr<arrow::Schema> full_value_schema =
+
DataField::ConvertDataFieldsToArrowSchema(context->GetTableSchema()->Fields());
+ arrow::FieldVector prepared_fields = {
+
DataField::ConvertDataFieldToArrowField(SpecialFields::ValueKind())->WithNullable(false),
+
DataField::ConvertDataFieldToArrowField(SpecialFields::SequenceNumber())
+ ->WithNullable(false),
+
DataField::ConvertDataFieldToArrowField(SpecialFields::RealtimeOffset())};
+ prepared_fields.insert(prepared_fields.end(),
full_value_schema->fields().begin(),
+ full_value_schema->fields().end());
+ std::shared_ptr<arrow::Schema> prepared_schema =
arrow::schema(std::move(prepared_fields));
+ auto c_schema = std::make_unique<ArrowSchema>();
+ PAIMON_RETURN_NOT_OK_FROM_ARROW(arrow::ExportSchema(*prepared_schema,
c_schema.get()));
+ ScopeGuard schema_guard([schema = c_schema.get()]() {
ArrowSchemaRelease(schema); });
+ RealtimeQueryContext query_context{c_schema.get(), nullptr, false};
+ PAIMON_ASSIGN_OR_RAISE(std::vector<std::unique_ptr<BatchReader>>
batch_readers,
+ memory.store->CreateQueryReaders(memory.read_view,
0, query_context));
+ ScopeGuard batch_readers_guard([&batch_readers]() {
+ for (const std::unique_ptr<BatchReader>& reader : batch_readers) {
+ if (reader) {
+ reader->Close();
+ }
+ }
+ });
+ std::vector<std::unique_ptr<KeyValueRecordReader>> result;
+ result.reserve(batch_readers.size());
+ for (std::unique_ptr<BatchReader>& reader : batch_readers) {
+ if (!reader) {
+ return Status::Invalid("PK real-time store returned a null query
reader");
+ }
+ PAIMON_ASSIGN_OR_RAISE(
+ std::unique_ptr<KeyValueRecordReader> prepared_reader,
+ AdaptPreparedBatchReader(
+ std::move(reader), prepared_schema,
+ OffsetRange(split->CommittedEndOffset(),
split->MemoryEndOffset()), key_schema,
+ value_schema, key_comparator, memory_pool));
+ auto merge = std::make_unique<DeduplicateMergeFunction>(false);
+ result.push_back(std::make_unique<MergedKeyValueRecordReader>(
+ std::move(prepared_reader), key_comparator,
Review Comment:
Fixed in `13cba67b9ef802f9acebe6b0b997d1e44dc528bf`: this now uses
`PrimaryKeyTableUtils::CreateMergeFunction`.
--
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]