zjw1111 commented on code in PR #447: URL: https://github.com/apache/paimon-cpp/pull/447#discussion_r4375252864
########## src/paimon/core/table/file_store.h: ########## @@ -0,0 +1,236 @@ +/* + * 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 <map> +#include <memory> +#include <optional> +#include <string> + +#include "paimon/catalog/identifier.h" +#include "paimon/core/core_options.h" +#include "paimon/core/schema/schema_manager.h" +#include "paimon/core/utils/file_store_path_factory.h" +#include "paimon/core/utils/snapshot_manager.h" +#include "paimon/result.h" +#include "paimon/type_fwd.h" + +namespace arrow { +class Schema; +} // namespace arrow + +namespace paimon { + +class BinaryRowPartitionComputer; +class Catalog; +class IndexFileHandler; +class IndexManifestFile; +class ManifestFile; +class ManifestList; +class TableSchema; + +/// The storage a managed table is served through: the file system, root path, schema, branch, +/// options and the schema and snapshot managers it was loaded with - the state Java Paimon's +/// `AbstractFileStore` carries, parsed once here rather than per operator. `FileStoreTable` hands +/// the state it was loaded with to one of these and asks it back for the pieces every operator +/// opens with. +/// +/// The options are the ones the table was loaded with on this branch - the schema's own, or +/// the ones a load merged over them - the base every operator serves: `NewXxx` takes no +/// options of its own beyond them. A cache is not part of them - `WithCache()` arms a copy an +/// operator makes - so the factories below take the options of the call, not the store's own. +/// +/// The factory methods build a fresh instance on every call, never a cached one: a path factory +/// names each file it builds, and a snapshot manager a write or a commit arms with a catalog +/// loader is not one a scan should be served through afterwards. +class FileStore { + public: + /// @param file_system The file system the caller opened the table through, which wins over + /// the access configuration the schema's options may carry when it is not null. A + /// null one hands the resolution to that configuration: the table is then served by + /// the file system its options name - the way a load that only had a path and a + /// schema to read names it - and by the default local one when they name none. + /// @param root_path Root path of the table in the file system. + /// @param schema The schema the table was loaded with, whose partition keys name the + /// partitions the paths below are built for and whose options `options()` parses. It + /// is null when the caller had no schema; the operators then report that none was + /// found. + /// @param branch The branch the store serves, normalized here. + /// @param schema_manager A schema manager to carry instead of building one - the one a + /// context dispatch read the schema through, whose cache the operators then serve. + /// @param snapshot_manager A snapshot manager to carry instead of building one. + /// A null manager is built over `root_path` on `branch`, so the operators always read + /// through the managers the store carries. + /// @param fs_scheme_map The scheme-to-identifier map the caller's contexts resolve custom + /// schemes through. It takes part in building the store's options the way it took + /// part in reading the schema: without it a schema naming a custom scheme would + /// resolve to the default backend once its operators run. It is kept for a copy to + /// hand over again, so the copy resolves as this store does. + /// + /// Building the store parses the schema's options, so it fails when they do not parse: the + /// error is the caller's to see, which is why a store is built through this factory rather + /// than the constructor. + static Result<std::shared_ptr<FileStore>> Create( + const std::shared_ptr<FileSystem>& file_system, const std::string& root_path, + const std::shared_ptr<TableSchema>& schema, const std::string& branch, + const std::shared_ptr<SchemaManager>& schema_manager = nullptr, + const std::shared_ptr<SnapshotManager>& snapshot_manager = nullptr, + const std::map<std::string, std::string>& fs_scheme_map = {}); + + /// The branch this store serves, as resolved when it was built. + const std::string& branch() const { + return branch_; + } + + /// The schema manager the operators read through. It carries the schema cache of `root_path` + /// on `branch()`. + const std::shared_ptr<SchemaManager>& schema_manager() const { Review Comment: why these function name is lower_case, not UpperCase? -- 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]
