@@ -31,6 +31,14 @@ std::string_view ToView(const T& value) {
3131 return {reinterpret_cast <const char *>(value.data ()), value.size ()}; // NOLINT
3232}
3333
34+ template <typename T>
35+ Result<Scalar> FromOptional (const std::optional<T>& value) {
36+ if (value.has_value ()) {
37+ return value.value ();
38+ }
39+ return std::monostate{};
40+ }
41+
3442} // namespace
3543
3644Result<Scalar> PartitionFieldSummaryStructLike::GetField (size_t pos) const {
@@ -40,24 +48,14 @@ Result<Scalar> PartitionFieldSummaryStructLike::GetField(size_t pos) const {
4048 switch (pos) {
4149 case 0 :
4250 return summary_.get ().contains_null ;
43- case 1 : {
44- if (summary_.get ().contains_nan .has_value ()) {
45- return summary_.get ().contains_nan .value ();
46- }
47- return {};
48- }
49- case 2 : {
50- if (summary_.get ().lower_bound .has_value ()) {
51- return ToView (summary_.get ().lower_bound .value ());
52- }
53- return {};
54- }
55- case 3 : {
56- if (summary_.get ().upper_bound .has_value ()) {
57- return ToView (summary_.get ().upper_bound .value ());
58- }
59- return {};
60- }
51+ case 1 :
52+ return FromOptional (summary_.get ().contains_nan );
53+ case 2 :
54+ return FromOptional (
55+ summary_.get ().lower_bound .transform (ToView<std::vector<uint8_t >>));
56+ case 3 :
57+ return FromOptional (
58+ summary_.get ().upper_bound .transform (ToView<std::vector<uint8_t >>));
6159 default :
6260 return InvalidArgument (" Invalid partition field summary index: {}" , pos);
6361 }
@@ -97,42 +95,18 @@ Result<Scalar> ManifestFileStructLike::GetField(size_t pos) const {
9795 return manifest_file.min_sequence_number ;
9896 case ManifestFileField::kAddedSnapshotId :
9997 return manifest_file.added_snapshot_id ;
100- case ManifestFileField::kAddedFilesCount : {
101- if (manifest_file.added_files_count .has_value ()) {
102- return manifest_file.added_files_count .value ();
103- }
104- return {};
105- }
106- case ManifestFileField::kExistingFilesCount : {
107- if (manifest_file.existing_files_count .has_value ()) {
108- return manifest_file.existing_files_count .value ();
109- }
110- return {};
111- }
112- case ManifestFileField::kDeletedFilesCount : {
113- if (manifest_file.deleted_files_count .has_value ()) {
114- return manifest_file.deleted_files_count .value ();
115- }
116- return {};
117- }
118- case ManifestFileField::kAddedRowsCount : {
119- if (manifest_file.added_rows_count .has_value ()) {
120- return manifest_file.added_rows_count .value ();
121- }
122- return {};
123- }
124- case ManifestFileField::kExistingRowsCount : {
125- if (manifest_file.existing_rows_count .has_value ()) {
126- return manifest_file.existing_rows_count .value ();
127- }
128- return {};
129- }
130- case ManifestFileField::kDeletedRowsCount : {
131- if (manifest_file.deleted_rows_count .has_value ()) {
132- return manifest_file.deleted_rows_count .value ();
133- }
134- return {};
135- }
98+ case ManifestFileField::kAddedFilesCount :
99+ return FromOptional (manifest_file.added_files_count );
100+ case ManifestFileField::kExistingFilesCount :
101+ return FromOptional (manifest_file.existing_files_count );
102+ case ManifestFileField::kDeletedFilesCount :
103+ return FromOptional (manifest_file.deleted_files_count );
104+ case ManifestFileField::kAddedRowsCount :
105+ return FromOptional (manifest_file.added_rows_count );
106+ case ManifestFileField::kExistingRowsCount :
107+ return FromOptional (manifest_file.existing_rows_count );
108+ case ManifestFileField::kDeletedRowsCount :
109+ return FromOptional (manifest_file.deleted_rows_count );
136110 case ManifestFileField::kPartitionFieldSummary : {
137111 if (summaries_ == nullptr ) {
138112 summaries_ =
@@ -145,10 +119,7 @@ Result<Scalar> ManifestFileStructLike::GetField(size_t pos) const {
145119 case ManifestFileField::kKeyMetadata :
146120 return ToView (manifest_file.key_metadata );
147121 case ManifestFileField::kFirstRowId :
148- if (manifest_file.first_row_id .has_value ()) {
149- return manifest_file.first_row_id .value ();
150- }
151- return {};
122+ return FromOptional (manifest_file.first_row_id );
152123 case ManifestFileField::kNextUnusedId :
153124 return InvalidArgument (" Invalid manifest file field index: {}" , pos);
154125 }
0 commit comments