@@ -35,7 +35,7 @@ constexpr int32_t kEntropyDirLength = 4;
3535constexpr int32_t kEntropyDirDepth = 3 ;
3636
3737std::string DataLocation (const TableProperties& properties,
38- const std::string& table_location) {
38+ std::string_view table_location) {
3939 auto data_location = properties.Get (TableProperties::kWriteDataLocation );
4040 if (data_location.empty ()) {
4141 data_location = std::format (" {}/data" , table_location);
@@ -44,11 +44,11 @@ std::string DataLocation(const TableProperties& properties,
4444}
4545
4646std::string PathContext (std::string_view table_location) {
47- std::string path = LocationUtil::StripTrailingSlash (table_location);
47+ std::string_view path = LocationUtil::StripTrailingSlash (table_location);
4848
4949 size_t last_slash = path.find_last_of (' /' );
5050 if (last_slash != std::string::npos && last_slash < path.length () - 1 ) {
51- std::string_view data_path (path. data (), path.size () - last_slash - 1 );
51+ std::string_view data_path = path.substr ( last_slash + 1 );
5252 std::string_view parent_path (path.data (), last_slash);
5353 size_t parent_last_slash = parent_path.find_last_of (' /' );
5454
@@ -74,7 +74,7 @@ std::string PathContext(std::string_view table_location) {
7474std::string DirsFromHash (int32_t hash) {
7575 std::string hash_with_dirs;
7676
77- for (int i = 0 ; i < kEntropyDirDepth * kEntropyDirLength ; i += kEntropyDirLength ) {
77+ for (int32_t i = 0 ; i < kEntropyDirDepth * kEntropyDirLength ; i += kEntropyDirLength ) {
7878 if (i > 0 ) {
7979 hash_with_dirs += " /" ;
8080 }
@@ -97,23 +97,25 @@ std::string ComputeHash(std::string_view file_name) {
9797
9898} // namespace
9999
100- Result<std::unique_ptr<LocationProvider>> LocationProviderFactory::For (
101- const std::string& input_location, const TableProperties& properties) {
102- std::string location = LocationUtil::StripTrailingSlash (input_location);
100+ // / \brief DefaultLocationProvider privides default location provider for local file
101+ // / system.
102+ class DefaultLocationProvider : public LocationProvider {
103+ public:
104+ DefaultLocationProvider (std::string_view table_location,
105+ const TableProperties& properties);
103106
104- // Note: Not support dynamic constructor according to kWriteLocationProviderImpl
107+ std::string NewDataLocation ( const std::string& filename) override ;
105108
106- properties.Get (TableProperties::kObjectStoreEnabled );
109+ Result<std::string> NewDataLocation (const PartitionSpec& spec,
110+ const PartitionValues& partition_data,
111+ const std::string& filename) override ;
107112
108- if (properties.Get (TableProperties::kObjectStoreEnabled )) {
109- return std::make_unique<ObjectStoreLocationProvider>(location, properties);
110- } else {
111- return std::make_unique<DefaultLocationProvider>(location, properties);
112- }
113- }
113+ private:
114+ std::string data_location_;
115+ };
114116
115117// Implementation of DefaultLocationProvider
116- DefaultLocationProvider::DefaultLocationProvider (const std::string& table_location,
118+ DefaultLocationProvider::DefaultLocationProvider (std::string_view table_location,
117119 const TableProperties& properties)
118120 : data_location_(
119121 LocationUtil::StripTrailingSlash (DataLocation(properties, table_location))) {}
@@ -129,9 +131,27 @@ Result<std::string> DefaultLocationProvider::NewDataLocation(
129131 return std::format (" {}/{}/{}" , data_location_, partition_path, filename);
130132}
131133
134+ // / \brief ObjectStoreLocationProvider provides location provider for object stores.
135+ class ObjectStoreLocationProvider : public LocationProvider {
136+ public:
137+ ObjectStoreLocationProvider (std::string_view table_location,
138+ const TableProperties& properties);
139+
140+ std::string NewDataLocation (const std::string& filename) override ;
141+
142+ Result<std::string> NewDataLocation (const PartitionSpec& spec,
143+ const PartitionValues& partition_data,
144+ const std::string& filename) override ;
145+
146+ private:
147+ std::string storage_location_;
148+ std::string context_;
149+ bool include_partition_paths_;
150+ };
151+
132152// Implementation of ObjectStoreLocationProvider
133153ObjectStoreLocationProvider::ObjectStoreLocationProvider (
134- const std::string& table_location, const TableProperties& properties)
154+ std::string_view table_location, const TableProperties& properties)
135155 : include_partition_paths_(
136156 properties.Get(TableProperties::kWriteObjectStorePartitionedPaths )) {
137157 storage_location_ =
@@ -173,4 +193,17 @@ Result<std::string> ObjectStoreLocationProvider::NewDataLocation(
173193 }
174194}
175195
196+ Result<std::unique_ptr<LocationProvider>> LocationProvider::Make (
197+ const std::string& input_location, const TableProperties& properties) {
198+ std::string_view location = LocationUtil::StripTrailingSlash (input_location);
199+
200+ // TODO(xxx): Support dynamic constructor according to kWriteLocationProviderImpl
201+
202+ if (properties.Get (TableProperties::kObjectStoreEnabled )) {
203+ return std::make_unique<ObjectStoreLocationProvider>(location, properties);
204+ } else {
205+ return std::make_unique<DefaultLocationProvider>(location, properties);
206+ }
207+ }
208+
176209} // namespace iceberg
0 commit comments