zjw1111 commented on code in PR #484:
URL: https://github.com/apache/paimon-cpp/pull/484#discussion_r4450744447
##########
include/paimon/file_index/file_indexer.h:
##########
@@ -38,6 +40,13 @@ class PAIMON_EXPORT FileIndexer {
public:
virtual ~FileIndexer() = default;
+ /// Whether this indexer returns exact file-local matching row positions
for the field type.
+ /// Supported evaluations return BitmapIndexResult (or Skip), never Remain
or false positives.
+ /// The schema and values must satisfy the index's writer constraints.
+ virtual bool SupportsExactPredicate(Function::Type, FieldType) const {
Review Comment:
need param name? like `SupportsExactPredicate(Function::Type function,
FieldType field_type)`
##########
src/paimon/core/operation/raw_file_split_read_test.cpp:
##########
@@ -285,6 +285,89 @@ TEST_F(RawFileSplitReadTest, TestCreateReader) {
CheckReadResult(read_schema, expected_array);
}
+TEST_F(RawFileSplitReadTest, TestCreateReaderUsesExplicitPredicate) {
+ const std::string path =
+ GetDataDir() +
"/orc/multi_partition_append_table.db/multi_partition_append_table";
+ ReadContextBuilder builder(path);
+ builder.EnablePredicateFilter(true)
+ .SetPredicate(PredicateBuilder::Equal(0, "f0", FieldType::STRING,
+ Literal(FieldType::STRING,
"Bob", 3)))
+ .AddOption(Options::FILE_INDEX_READ_ENABLED, "false");
+ ASSERT_OK_AND_ASSIGN(std::shared_ptr<ReadContext> read_context,
builder.Finish());
+ SchemaManager schemas(std::make_shared<LocalFileSystem>(), path);
+ ASSERT_OK_AND_ASSIGN(std::shared_ptr<TableSchema> table_schema,
schemas.ReadSchema(0));
+ ASSERT_OK_AND_ASSIGN(
+ std::shared_ptr<InternalReadContext> context,
+ InternalReadContext::Create(read_context, table_schema,
table_schema->Options()));
+ const CoreOptions& options = context->GetCoreOptions();
+ const auto schema =
DataField::ConvertDataFieldsToArrowSchema(table_schema->Fields());
+ ASSERT_OK_AND_ASSIGN(std::vector<std::string> external_paths,
options.CreateExternalPaths());
+ ASSERT_OK_AND_ASSIGN(std::optional<std::string> global_index_path,
+ options.CreateGlobalIndexExternalPath());
+ ASSERT_OK_AND_ASSIGN(
+ std::shared_ptr<FileStorePathFactory> paths,
+ FileStorePathFactory::Create(
+ path, schema, table_schema->PartitionKeys(),
options.GetPartitionDefaultName(),
+ options.GetFileFormat()->Identifier(), options.DataFilePrefix(),
+ options.LegacyPartitionNameEnabled(), external_paths,
global_index_path,
+ options.IndexFileInDataFileDir(), pool_));
+ ASSERT_OK_AND_ASSIGN(std::shared_ptr<Executor> executor,
CreateDefaultExecutor(2));
+ RawFileSplitRead read(paths, context, pool_, executor);
+ auto split =
std::dynamic_pointer_cast<DataSplitImpl>(PrepareDataSplits().front());
+ ASSERT_NE(nullptr, split);
+ const auto first = split->DataFiles().front();
+ const auto second = std::make_shared<DataFileMeta>(*first);
+ // The supplied predicate, not the context's predicate, must be used for
both files.
+ const std::shared_ptr<Predicate> predicate =
+ PredicateBuilder::Equal(0, "f0", FieldType::STRING,
Literal(FieldType::STRING, "Tony", 4));
+ RoaringBitmap32 deleted;
+ deleted.Add(1);
+ std::shared_ptr<DeletionVector> dv =
std::make_shared<BitmapDeletionVector>(deleted);
+ DeletionVector::Factory dv_factory =
+ [dv](const std::string&) -> Result<std::shared_ptr<DeletionVector>> {
return dv; };
+ RawFileSplitRead::PredicateProvider no_pushdown =
+ [](const std::shared_ptr<DataFileMeta>&) ->
Result<std::shared_ptr<Predicate>> {
+ return std::shared_ptr<Predicate>();
+ };
+ ASSERT_NOK_WITH_MSG(
+ read.CreateReaderWithPredicateProvider(split->Partition(),
split->Bucket(), {first, second},
+ dv_factory, std::nullopt,
context->GetReadSchema(),
+ predicate,
/*predicate_provider=*/{}),
+ "file predicate provider is null");
+ ASSERT_NOK_WITH_MSG(
+ read.CreateReaderWithPredicateProvider(split->Partition(),
split->Bucket(), {first, second},
+ dv_factory,
std::vector<Range>{Range(0, 0)},
+ context->GetReadSchema(),
predicate, no_pushdown),
+ "file-local row ranges require exactly one data file");
+ arrow::FieldVector output_fields = {arrow::field("_VALUE_KIND",
arrow::int8())};
+ output_fields.insert(output_fields.end(), schema->fields().begin(),
schema->fields().end());
+ auto expected =
arrow::ipc::internal::json::ArrayFromJSON(arrow::struct_(output_fields), R"([
+ [0, "Tony", 10, 0, 14.1],
+ [0, "Tony", 10, 0, 14.1]
+ ])")
+ .ValueOrDie();
+ for (bool use_provider : {false, true}) {
Review Comment:
Is this writing allowed?
##########
src/paimon/core/realtime/realtime_context_impl.cpp:
##########
@@ -369,104 +376,147 @@ Status RealtimeContextImpl::AdvanceCommittedProgress(
if (snapshot_id < 0) {
return Status::Invalid("real-time refresh snapshot id must not be
negative");
}
- std::lock_guard<std::mutex> progress_lock(progress_mutex_);
- if (last_refreshed_snapshot_id_ && snapshot_id <
last_refreshed_snapshot_id_.value()) {
- return Status::Invalid("real-time committed snapshot cannot move
backwards");
- }
- if (!last_refreshed_snapshot_id_ || snapshot_id >
last_refreshed_snapshot_id_.value()) {
- for (const auto& [partition_bucket, committed_end_offset] :
committed_offsets) {
- if (partition_bucket.bucket < 0 || committed_end_offset < 0) {
- return Status::Invalid("invalid partition-bucket committed
offset");
- }
+ std::lock_guard<std::mutex> refresh_lock(refresh_mutex_);
Review Comment:
this function is too long, please split it
##########
include/paimon/realtime/realtime_store.h:
##########
@@ -211,6 +212,28 @@ class PAIMON_EXPORT RealtimeStore {
virtual uint64_t GetMemoryUsage() const = 0;
};
+/// Optional capability for `RealtimeStore` implementations to separate
segment freezing from spill
+/// I/O.
+class PAIMON_EXPORT RealtimeStoreTwoPhaseSeal {
Review Comment:
why not inherit `RealtimeStore`
##########
src/paimon/testing/utils/blocking_file_system.h:
##########
@@ -0,0 +1,231 @@
+/*
+ * 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 <chrono>
+#include <condition_variable>
+#include <cstdint>
+#include <map>
+#include <memory>
+#include <mutex>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "paimon/fs/file_system.h"
+#include "paimon/macros.h"
+
+namespace paimon::test {
+
+/// Blocks selected file operations on a delegated file system.
+class BlockingFileSystem final : public FileSystem {
Review Comment:
Is BlockingFileSystem for all fault injection test? maybe should check all
other test files and use it.
##########
src/paimon/core/realtime/realtime_deduplicate_writer.h:
##########
@@ -77,7 +78,7 @@ class RealtimeDeduplicateWriter final : public BatchWriter {
std::shared_ptr<arrow::Field>
deduplicate_key_field,
int64_t next_offset, std::shared_ptr<MemoryPool>
memory_pool);
- Status SealCurrentSegment();
+ Status SealCurrentSegment(bool spill);
Review Comment:
I'm not sure the param name is good or not.
##########
src/paimon/core/realtime/realtime_append_only_writer.cpp:
##########
@@ -135,12 +137,12 @@ Status RealtimeAppendOnlyWriter::SealCurrentSegment() {
Status RealtimeAppendOnlyWriter::Seal() {
std::lock_guard<std::mutex> lock(prepare_mutex_);
- return SealCurrentSegment();
+ return SealCurrentSegment(/*spill=*/true);
Review Comment:
I want to know when need spill, when no need spill
##########
src/paimon/core/schema/schema_validation.cpp:
##########
@@ -689,14 +689,14 @@ Status SchemaValidation::ValidateRealtime(const
TableSchema& schema, const CoreO
PAIMON_RETURN_NOT_OK(Preconditions::CheckState(
!options.DeletionVectorsBitmap64(),
"Real-time deduplicate mode does not support
'deletion-vectors.bitmap64=true'."));
- PAIMON_RETURN_NOT_OK(Preconditions::CheckState(
- !options.RealtimeSpillEnabled(),
- "Real-time deduplicate mode does not support
'realtime.spill-enabled=true'."));
-
const std::shared_ptr<arrow::Schema> arrow_schema =
DataField::ConvertDataFieldsToArrowSchema(schema.Fields());
PAIMON_RETURN_NOT_OK(
RealtimeUtils::ValidateDeduplicateSchema(arrow_schema,
deduplicate_key_fields));
+ PAIMON_RETURN_NOT_OK(Preconditions::CheckState(
Review Comment:
why add this check?
##########
src/paimon/core/realtime/realtime_append_only_writer.cpp:
##########
@@ -118,9 +118,11 @@ Status
RealtimeAppendOnlyWriter::Write(std::unique_ptr<RecordBatch>&& batch) {
return Status::OK();
}
-Status RealtimeAppendOnlyWriter::SealCurrentSegment() {
+Status RealtimeAppendOnlyWriter::SealCurrentSegment(bool spill) {
Review Comment:
similar function in RealtimeAppendOnlyWriter and RealtimePrimaryKeyWriter,
consider refactor?
--
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]