Skip to content

Commit 83e900a

Browse files
committed
refine signature
1 parent 52bb393 commit 83e900a

3 files changed

Lines changed: 39 additions & 43 deletions

File tree

src/iceberg/location_provider.cc

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,25 @@ namespace iceberg {
2828

2929
namespace {
3030

31-
constexpr uint8_t kEntropyDirMask = 0x0f;
32-
constexpr uint8_t kRestDirMask = 0xff;
31+
constexpr uint8_t kEntropyDirMask = 0x0F;
32+
constexpr uint8_t kRestDirMask = 0xFF;
3333
constexpr int32_t kHashBits = 20;
3434
constexpr int32_t kEntropyDirLength = 4;
3535
constexpr int32_t kEntropyDirDepth = 3;
3636

37-
std::string DataLocation(const TableProperties& properties,
38-
std::string_view table_location) {
37+
std::string DataLocation(const TableProperties& properties, std::string_view location) {
3938
auto data_location = properties.Get(TableProperties::kWriteDataLocation);
4039
if (data_location.empty()) {
41-
data_location = std::format("{}/data", table_location);
40+
data_location = std::format("{}/data", location);
4241
}
4342
return data_location;
4443
}
4544

46-
std::string PathContext(std::string_view table_location) {
47-
std::string_view path = LocationUtil::StripTrailingSlash(table_location);
45+
std::string PathContext(std::string_view location) {
46+
std::string_view path = LocationUtil::StripTrailingSlash(location);
4847

4948
size_t last_slash = path.find_last_of('/');
50-
if (last_slash != std::string::npos && last_slash < path.length() - 1) {
49+
if (last_slash != std::string_view::npos && last_slash < path.length() - 1) {
5150
std::string_view data_path = path.substr(last_slash + 1);
5251
std::string_view parent_path(path.data(), last_slash);
5352
size_t parent_last_slash = parent_path.find_last_of('/');
@@ -60,7 +59,7 @@ std::string PathContext(std::string_view table_location) {
6059
}
6160
}
6261

63-
return std::string(table_location);
62+
return std::string(location);
6463
}
6564

6665
/// \brief Divides hash into directories for optimized orphan removal operation using
@@ -97,50 +96,48 @@ std::string ComputeHash(std::string_view file_name) {
9796

9897
} // namespace
9998

100-
/// \brief DefaultLocationProvider privides default location provider for local file
101-
/// system.
99+
// Default location provider for local file system.
102100
class DefaultLocationProvider : public LocationProvider {
103101
public:
104-
DefaultLocationProvider(std::string_view table_location,
105-
const TableProperties& properties);
102+
DefaultLocationProvider(std::string_view location, const TableProperties& properties);
106103

107104
std::string NewDataLocation(std::string_view filename) override;
108105

109106
Result<std::string> NewDataLocation(const PartitionSpec& spec,
110-
const PartitionValues& partition_data,
107+
const PartitionValues& partition,
111108
std::string_view filename) override;
112109

113110
private:
114111
std::string data_location_;
115112
};
116113

117114
// Implementation of DefaultLocationProvider
118-
DefaultLocationProvider::DefaultLocationProvider(std::string_view table_location,
115+
DefaultLocationProvider::DefaultLocationProvider(std::string_view location,
119116
const TableProperties& properties)
120117
: data_location_(
121-
LocationUtil::StripTrailingSlash(DataLocation(properties, table_location))) {}
118+
LocationUtil::StripTrailingSlash(DataLocation(properties, location))) {}
122119

123120
std::string DefaultLocationProvider::NewDataLocation(std::string_view filename) {
124121
return std::format("{}/{}", data_location_, filename);
125122
}
126123

127124
Result<std::string> DefaultLocationProvider::NewDataLocation(
128-
const PartitionSpec& spec, const PartitionValues& partition_data,
125+
const PartitionSpec& spec, const PartitionValues& partition,
129126
std::string_view filename) {
130-
ICEBERG_ASSIGN_OR_RAISE(auto partition_path, spec.PartitionPath(partition_data));
127+
ICEBERG_ASSIGN_OR_RAISE(auto partition_path, spec.PartitionPath(partition));
131128
return std::format("{}/{}/{}", data_location_, partition_path, filename);
132129
}
133130

134-
/// \brief ObjectStoreLocationProvider provides location provider for object stores.
131+
// Location provider for object stores.
135132
class ObjectStoreLocationProvider : public LocationProvider {
136133
public:
137-
ObjectStoreLocationProvider(std::string_view table_location,
134+
ObjectStoreLocationProvider(std::string_view location,
138135
const TableProperties& properties);
139136

140137
std::string NewDataLocation(std::string_view filename) override;
141138

142139
Result<std::string> NewDataLocation(const PartitionSpec& spec,
143-
const PartitionValues& partition_data,
140+
const PartitionValues& partition,
144141
std::string_view filename) override;
145142

146143
private:
@@ -151,16 +148,16 @@ class ObjectStoreLocationProvider : public LocationProvider {
151148

152149
// Implementation of ObjectStoreLocationProvider
153150
ObjectStoreLocationProvider::ObjectStoreLocationProvider(
154-
std::string_view table_location, const TableProperties& properties)
151+
std::string_view location, const TableProperties& properties)
155152
: include_partition_paths_(
156153
properties.Get(TableProperties::kWriteObjectStorePartitionedPaths)) {
157154
storage_location_ =
158-
LocationUtil::StripTrailingSlash(DataLocation(properties, table_location));
155+
LocationUtil::StripTrailingSlash(DataLocation(properties, location));
159156

160157
// If the storage location is within the table prefix, don't add table and database name
161158
// context
162-
if (!storage_location_.starts_with(table_location)) {
163-
context_ = PathContext(table_location);
159+
if (!storage_location_.starts_with(location)) {
160+
context_ = PathContext(location);
164161
}
165162
}
166163

@@ -183,21 +180,21 @@ std::string ObjectStoreLocationProvider::NewDataLocation(std::string_view filena
183180
}
184181

185182
Result<std::string> ObjectStoreLocationProvider::NewDataLocation(
186-
const PartitionSpec& spec, const PartitionValues& partition_data,
183+
const PartitionSpec& spec, const PartitionValues& partition,
187184
std::string_view filename) {
188185
if (include_partition_paths_) {
189-
ICEBERG_ASSIGN_OR_RAISE(auto partition_path, spec.PartitionPath(partition_data));
186+
ICEBERG_ASSIGN_OR_RAISE(auto partition_path, spec.PartitionPath(partition));
190187
return NewDataLocation(std::format("{}/{}", partition_path, filename));
191188
} else {
192189
return NewDataLocation(filename);
193190
}
194191
}
195192

196193
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);
194+
std::string_view location, const TableProperties& properties) {
195+
location = LocationUtil::StripTrailingSlash(location);
199196

200-
// TODO(xxx): Support dynamic constructor according to kWriteLocationProviderImpl
197+
// TODO(xxx): create location provider specified by "write.location-provider.impl"
201198

202199
if (properties.Get(TableProperties::kObjectStoreEnabled)) {
203200
return std::make_unique<ObjectStoreLocationProvider>(location, properties);

src/iceberg/location_provider.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,43 @@
2121

2222
#include <memory>
2323
#include <string>
24+
#include <string_view>
2425

2526
#include "iceberg/iceberg_export.h"
2627
#include "iceberg/result.h"
2728
#include "iceberg/type_fwd.h"
2829

2930
namespace iceberg {
3031

31-
/// \brief Interface for providing data file locations to write tasks.
32+
/// \brief Interface for providing data file locations.
3233
class ICEBERG_EXPORT LocationProvider {
3334
public:
3435
virtual ~LocationProvider() = default;
3536

3637
/// \brief Return a fully-qualified data file location for the given filename.
3738
///
38-
/// \param filename a file name
39+
/// \param filename file name to get location
3940
/// \return a fully-qualified location URI for a data file
4041
virtual std::string NewDataLocation(std::string_view filename) = 0;
4142

4243
/// \brief Return a fully-qualified data file location for the given partition and
4344
/// filename.
4445
///
45-
/// \param spec a partition spec
46-
/// \param partition_data a tuple of partition data for data in the file, matching the
47-
/// given spec
48-
/// \param filename a file name
46+
/// \param spec partition spec
47+
/// \param partition a tuple of partition values matching the given spec
48+
/// \param filename file name
4949
/// \return a fully-qualified location URI for a data file
5050
virtual Result<std::string> NewDataLocation(const PartitionSpec& spec,
51-
const PartitionValues& partition_data,
51+
const PartitionValues& partition,
5252
std::string_view filename) = 0;
5353

5454
/// \brief Create a LocationProvider for the given table location and properties.
5555
///
56-
/// \param input_location the table location
57-
/// \param properties the table properties
56+
/// \param location table location
57+
/// \param properties table properties
5858
/// \return a LocationProvider instance
5959
static Result<std::unique_ptr<LocationProvider>> Make(
60-
const std::string& input_location, const TableProperties& properties);
60+
std::string_view location, const TableProperties& properties);
6161
};
6262

6363
} // namespace iceberg

src/iceberg/test/location_provider_test.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
#include "iceberg/location_provider.h"
2121

22-
#include <string>
23-
2422
#include <gtest/gtest.h>
2523

2624
#include "iceberg/location_provider.h"
@@ -33,6 +31,7 @@
3331
namespace iceberg {
3432

3533
namespace {
34+
3635
// Helper function to split a string by delimiter
3736
std::vector<std::string> SplitString(const std::string& str, char delimiter) {
3837
std::vector<std::string> result;
@@ -45,9 +44,9 @@ std::vector<std::string> SplitString(const std::string& str, char delimiter) {
4544

4645
return result;
4746
}
47+
4848
} // namespace
4949

50-
// Test fixture for location provider tests
5150
class LocationProviderTest : public ::testing::Test {
5251
protected:
5352
void SetUp() override { table_location_ = "/test/table/location"; }

0 commit comments

Comments
 (0)