Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/paimon/read_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class FormatTable;
class MemoryPool;
class Predicate;
class FileSystem;
class FileStoreTable;
class RealtimeContext;
struct VectorSearch;

Expand Down Expand Up @@ -208,6 +209,8 @@ class PAIMON_EXPORT ReadContext {
void SetReadSchema(std::unique_ptr<ArrowSchema> schema);

private:
friend class FileStoreTable;
Comment thread
realAaronWu marked this conversation as resolved.
Resolved

std::string path_;
std::string branch_;
std::vector<std::string> read_field_names_;
Expand Down
3 changes: 3 additions & 0 deletions src/paimon/core/table/file_store_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ Result<std::unique_ptr<TableRead>> FileStoreTable::NewRead(
internal_context->GetCoreOptions().GetScanFallbackBranch();
if (!scan_fallback_branch ||
StringUtils::IsNullOrWhitespaceOnly(scan_fallback_branch.value())) {
// The typed reader keeps the context, but has finished using the serialized schema.
read_context->table_schema_.reset();
return std::move(table_read);
}

Expand Down Expand Up @@ -687,6 +689,7 @@ Result<std::unique_ptr<TableRead>> FileStoreTable::NewRead(
CreateTableRead(fallback_context, read_context->GetMemoryPool(),
read_context->GetExecutor()));
const std::shared_ptr<arrow::MemoryPool>& arrow_pool = internal_context->GetArrowMemoryPool();
read_context->table_schema_.reset();
return std::make_unique<FallbackTableRead>(std::move(table_read),
std::move(fallback_table_read), arrow_pool);
}
Expand Down
40 changes: 40 additions & 0 deletions src/paimon/core/table/source/table_read_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <vector>

#include "arrow/api.h"
#include "arrow/c/bridge.h"
#include "arrow/type.h"
#include "gtest/gtest.h"
#include "paimon/catalog/identifier.h"
Expand Down Expand Up @@ -136,6 +137,45 @@ TEST(TableReadTest, TestReadWithSpecifiedInvalidSchema) {
"Get field field_no_exist failed: not exist in table schema");
}

TEST(TableReadTest, SuppliedManagedSchemaIsReleasedBeforeReading) {
const auto path = GetDataDir() + "/parquet/append_types_compatibility.db/rust_time_types";
LocalFileSystem fs;
std::string schema;
ASSERT_OK(fs.ReadFile(path + "/schema/schema-0", &schema));

ReadContextBuilder builder(path);
builder.SetReadFieldIds({0}).SetTableSchema("{");
ASSERT_OK_AND_ASSIGN(auto invalid_context, builder.Finish());
ASSERT_NOK_WITH_MSG(TableRead::Create(std::move(invalid_context)), "deserialize failed");

builder.SetReadFieldIds({0}).SetTableSchema(schema);
ASSERT_OK_AND_ASSIGN(auto context, builder.Finish());
ASSERT_EQ(context->GetSpecificTableSchema(), schema);
const auto* retained_context = context.get();
ASSERT_OK_AND_ASSIGN(auto read, TableRead::Create(std::move(context)));
// AppendOnlyTableRead retains this exact ReadContext through InternalReadContext.
ASSERT_NE(dynamic_cast<AppendOnlyTableRead*>(read.get()), nullptr);
EXPECT_FALSE(retained_context->GetSpecificTableSchema());

ScanContextBuilder scan_builder(path);
scan_builder.AddOption("scan.mode", "from-snapshot-full").AddOption("scan.snapshot-id", "1");
ASSERT_OK_AND_ASSIGN(auto scan_context, scan_builder.Finish());
ASSERT_OK_AND_ASSIGN(auto scan, TableScan::Create(std::move(scan_context)));
ASSERT_OK_AND_ASSIGN(auto plan, scan->CreatePlan());
const auto splits = plan->Splits();
ASSERT_FALSE(splits.empty());
ASSERT_OK_AND_ASSIGN(auto reader, read->CreateReader(splits.front()));
ASSERT_OK_AND_ASSIGN(auto batch, reader->NextBatch());
ASSERT_FALSE(BatchReader::IsEofBatch(batch));
const auto rows = arrow::ImportRecordBatch(batch.first.get(), batch.second.get());
ASSERT_TRUE(rows.ok()) << rows.status();
EXPECT_GT((*rows)->num_rows(), 0);
EXPECT_NE((*rows)->schema()->GetFieldByName("id"), nullptr);
EXPECT_EQ((*rows)->schema()->GetFieldByName("f_time_0"), nullptr);
EXPECT_FALSE(retained_context->GetSpecificTableSchema());
reader->Close();
}

TEST(TableReadTest, TestFullTextMatchReadEntryAndScoreValidation) {
auto match = std::make_shared<FullTextMatch>("f0", R"({"match":{"query":"apple"}})");
ASSERT_OK_AND_ASSIGN(auto full_text, PredicateBuilder::FullTextMatch(/*field_index=*/0, match));
Expand Down
1 change: 1 addition & 0 deletions src/paimon/core/table/table_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2658,6 +2658,7 @@ TEST(TableTest, StaticFallbackReadUsesSuppliedMainSchema) {
ASSERT_EQ(main->GetSchema()->FieldNames(),
fallback_read->context_->GetTableSchema()->FieldNames());
ASSERT_EQ("main", fallback_read->context_->GetCoreOptions().GetBranch());
ASSERT_FALSE(fallback_read->context_->read_context_->GetSpecificTableSchema());
ASSERT_OK_AND_ASSIGN(std::unique_ptr<ReadContext> missing_schema,
ReadContextBuilder(dir->Str())
.WithBranch("dev")
Expand Down
Loading