Skip to content

Commit 94863b5

Browse files
committed
refactor: use nesting enum for DataFile and ManifestFile content
1 parent e70d2ca commit 94863b5

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

src/iceberg/manifest_entry.h

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,19 @@ ICEBERG_EXPORT constexpr Result<ManifestStatus> ManifestStatusFromInt(
5656
}
5757
}
5858

59-
enum class DataFileContent {
60-
kData = 0,
61-
kPositionDeletes = 1,
62-
kEqualityDeletes = 2,
63-
};
64-
65-
/// \brief Get the relative data file content type from int
66-
ICEBERG_EXPORT constexpr Result<DataFileContent> DataFileContentFromInt(
67-
int content) noexcept {
68-
switch (content) {
69-
case 0:
70-
return DataFileContent::kData;
71-
case 1:
72-
return DataFileContent::kPositionDeletes;
73-
case 2:
74-
return DataFileContent::kEqualityDeletes;
75-
default:
76-
return InvalidArgument("Invalid data file content: {}", content);
77-
}
78-
}
79-
8059
/// \brief DataFile carries data file path, partition tuple, metrics, ...
8160
struct ICEBERG_EXPORT DataFile {
61+
/// \brief Content of a data file
62+
enum class Content {
63+
kData = 0,
64+
kPositionDeletes = 1,
65+
kEqualityDeletes = 2,
66+
};
67+
8268
/// Field id: 134
8369
/// Type of content stored by the data file: data, equality deletes, or position
8470
/// deletes (all v1 files are data files)
85-
DataFileContent content;
71+
Content content;
8672
/// Field id: 100
8773
/// Full URI for the file with FS scheme
8874
std::string file_path;
@@ -322,4 +308,19 @@ struct ICEBERG_EXPORT ManifestEntry {
322308
std::shared_ptr<StructType> datafile_type);
323309
};
324310

311+
/// \brief Get the relative data file content type from int
312+
ICEBERG_EXPORT constexpr Result<DataFile::Content> DataFileContentFromInt(
313+
int content) noexcept {
314+
switch (content) {
315+
case 0:
316+
return DataFile::Content::kData;
317+
case 1:
318+
return DataFile::Content::kPositionDeletes;
319+
case 2:
320+
return DataFile::Content::kEqualityDeletes;
321+
default:
322+
return InvalidArgument("Invalid data file content: {}", content);
323+
}
324+
}
325+
325326
} // namespace iceberg

src/iceberg/manifest_list.h

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,6 @@
3333

3434
namespace iceberg {
3535

36-
/// \brief The type of files tracked by the manifest, either data or delete files; 0 for
37-
/// all v1 manifests
38-
enum class ManifestContent {
39-
/// The manifest content is data.
40-
kData = 0,
41-
/// The manifest content is deletes.
42-
kDeletes = 1,
43-
};
44-
45-
/// \brief Get the relative manifest content type name
46-
ICEBERG_EXPORT constexpr std::string_view ManifestContentToString(
47-
ManifestContent type) noexcept {
48-
switch (type) {
49-
case ManifestContent::kData:
50-
return "data";
51-
case ManifestContent::kDeletes:
52-
return "deletes";
53-
}
54-
}
55-
56-
/// \brief Get the relative manifest content type from name
57-
ICEBERG_EXPORT constexpr Result<ManifestContent> ManifestContentFromString(
58-
std::string_view str) noexcept {
59-
if (str == "data") return ManifestContent::kData;
60-
if (str == "deletes") return ManifestContent::kDeletes;
61-
return InvalidArgument("Invalid manifest content type: {}", str);
62-
}
63-
6436
/// \brief Field summary for partition field in the spec.
6537
///
6638
/// Each field of this corresponds to a field in the manifest file's partition spec.
@@ -98,6 +70,15 @@ struct ICEBERG_EXPORT PartitionFieldSummary {
9870

9971
/// \brief Entry in a manifest list.
10072
struct ICEBERG_EXPORT ManifestFile {
73+
/// \brief The type of files tracked by the manifest, either data or delete files; 0 for
74+
/// all v1 manifests
75+
enum class Content {
76+
/// The manifest content is data.
77+
kData = 0,
78+
/// The manifest content is deletes.
79+
kDeletes = 1,
80+
};
81+
10182
/// Field id: 500
10283
/// Location of the manifest file
10384
std::string manifest_path;
@@ -111,7 +92,7 @@ struct ICEBERG_EXPORT ManifestFile {
11192
/// Field id: 517
11293
/// The type of files tracked by the manifest, either data or delete files; 0 for all v1
11394
/// manifests
114-
ManifestContent content;
95+
Content content;
11596
/// Field id: 515
11697
/// The sequence number when the manifest was added to the table; use 0 when reading v1
11798
/// manifest lists
@@ -232,4 +213,22 @@ struct ICEBERG_EXPORT ManifestList {
232213
std::vector<ManifestFile> entries;
233214
};
234215

216+
/// \brief Get the relative manifest content type name
217+
ICEBERG_EXPORT constexpr std::string_view ToString(ManifestFile::Content type) noexcept {
218+
switch (type) {
219+
case ManifestFile::Content::kData:
220+
return "data";
221+
case ManifestFile::Content::kDeletes:
222+
return "deletes";
223+
}
224+
}
225+
226+
/// \brief Get the relative manifest content type from name
227+
ICEBERG_EXPORT constexpr Result<ManifestFile::Content> ManifestFileContentFromString(
228+
std::string_view str) noexcept {
229+
if (str == "data") return ManifestFile::Content::kData;
230+
if (str == "deletes") return ManifestFile::Content::kDeletes;
231+
return InvalidArgument("Invalid manifest content type: {}", str);
232+
}
233+
235234
} // namespace iceberg

0 commit comments

Comments
 (0)