lszskye commented on code in PR #447:
URL: https://github.com/apache/paimon-cpp/pull/447#discussion_r4387006992
##########
src/paimon/core/operation/internal_read_context.cpp:
##########
@@ -275,11 +279,74 @@ std::optional<DataField>
InternalReadContext::TryResolveSpecialFieldByName(
Result<std::unique_ptr<InternalReadContext>> InternalReadContext::Create(
const std::shared_ptr<ReadContext>& context, const
std::shared_ptr<TableSchema>& table_schema,
- const std::map<std::string, std::string>& options) {
- PAIMON_ASSIGN_OR_RAISE(CoreOptions core_options,
- CoreOptions::FromMap(options,
context->GetSpecificFileSystem(),
-
context->GetFileSystemSchemeToIdentifierMap()));
+ CoreOptions core_options, const std::string* path) {
core_options.WithCache(context->GetCache());
+ return CreateFromCoreOptions(context, table_schema,
std::move(core_options), path);
+}
+
+Result<std::unique_ptr<InternalReadContext>> InternalReadContext::Create(
+ const std::shared_ptr<ReadContext>& context, const
std::shared_ptr<TableSchema>& table_schema,
+ const std::map<std::string, std::string>& options,
+ const std::shared_ptr<FileSystem>& file_system, const std::string* path) {
+ // The file system the caller named, or null for the read context's own,
which callers
+ // without a table hand over. The scheme map the context carries does not
take part: a file
+ // system handed over wins and one missing falls to the resolving one, the
same way a scan
+ // resolves its own.
+ PAIMON_ASSIGN_OR_RAISE(
+ CoreOptions core_options,
+ CoreOptions::FromMap(
+ options, file_system != nullptr ? file_system :
context->GetSpecificFileSystem()));
+ core_options.WithCache(context->GetCache());
+ return CreateFromCoreOptions(context, table_schema,
std::move(core_options), path);
+}
+
+Result<std::unique_ptr<InternalReadContext>>
InternalReadContext::CreateForFallbackBranch(
+ const std::shared_ptr<ReadContext>& context, const std::string& branch,
+ const std::shared_ptr<FileSystem>& file_system, const std::string&
root_path,
+ const std::map<std::string, std::string>& table_dynamic_options) {
+ std::shared_ptr<TableSchema> table_schema;
+ const auto& specific_table_schema = context->GetSpecificTableSchema();
+ if (branch == BranchManager::DEFAULT_MAIN_BRANCH && specific_table_schema)
{
+ PAIMON_ASSIGN_OR_RAISE(table_schema,
+
TableSchema::CreateFromJson(specific_table_schema.value()));
+ } else {
+ auto schema_manager = std::make_shared<SchemaManager>(file_system,
root_path, branch);
+ PAIMON_ASSIGN_OR_RAISE(std::optional<std::shared_ptr<TableSchema>>
latest_schema,
+ schema_manager->Latest());
+ if (!latest_schema) {
+ return Status::Invalid(
+ fmt::format("schema file not found in path {}, branch {}",
root_path, branch));
+ }
+ table_schema = latest_schema.value();
+ }
+ assert(table_schema);
+ auto options = table_schema->Options();
+ // The dynamic options the load merged into this table - and the ones its
copies accumulated -
+ // speak for the read, and the fallback branch serves the same read: they
are merged over the
+ // fallback's own schema options the way the load merged them over the
table's, so the fallback
+ // reader recognises what the main one does. `type` stays the branch's
own: neither a copy nor
+ // a fallback restyles the table.
+ for (const auto& [key, value] : table_dynamic_options) {
+ if (key != Options::TYPE) {
+ options[key] = value;
+ }
+ }
+ for (const auto& [key, value] : context->GetOptions()) {
Review Comment:
The main reader ignores context options that are absent from the loaded
table, while the fallback reader merges them.
Could we apply a consistent policy to both paths?
--
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]