Skip to content

Commit 2c4a1a0

Browse files
committed
chore: add MakeRequiredField/MakeOptionalField to resolve lengthy lines
Signed-off-by: Junwang Zhao <[email protected]>
1 parent 76ef8b6 commit 2c4a1a0

File tree

3 files changed

+73
-85
lines changed

3 files changed

+73
-85
lines changed

src/iceberg/manifest_entry.h

Lines changed: 39 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -192,78 +192,57 @@ struct ICEBERG_EXPORT DataFile {
192192
/// present
193193
std::optional<int64_t> content_size_in_bytes;
194194

195-
inline static const SchemaField kContent =
196-
SchemaField::MakeRequired(134, "content", std::make_shared<IntType>());
195+
inline static const SchemaField kContent = MakeRequiredField<IntType>(134, "content");
197196
inline static const SchemaField kFilePath =
198-
SchemaField::MakeRequired(100, "file_path", std::make_shared<StringType>());
197+
MakeRequiredField<StringType>(100, "file_path");
199198
inline static const SchemaField kFileFormat =
200-
SchemaField::MakeRequired(101, "file_format", std::make_shared<IntType>());
199+
MakeRequiredField<IntType>(101, "file_format");
201200
inline static const SchemaField kRecordCount =
202-
SchemaField::MakeRequired(103, "record_count", std::make_shared<LongType>());
201+
MakeRequiredField<LongType>(103, "record_count");
203202
inline static const SchemaField kFileSize =
204-
SchemaField::MakeRequired(104, "file_size_in_bytes", std::make_shared<LongType>());
205-
inline static const SchemaField kColumnSizes = SchemaField::MakeOptional(
203+
MakeRequiredField<LongType>(104, "file_size_in_bytes");
204+
inline static const SchemaField kColumnSizes = MakeOptionalField<MapType>(
206205
108, "column_sizes",
207-
std::make_shared<MapType>(
208-
SchemaField::MakeRequired(117, std::string(MapType::kKeyName),
209-
std::make_shared<IntType>()),
210-
SchemaField::MakeRequired(118, std::string(MapType::kValueName),
211-
std::make_shared<LongType>())));
212-
inline static const SchemaField kValueCounts = SchemaField::MakeOptional(
206+
MakeRequiredField<IntType>(117, std::string(MapType::kKeyName)),
207+
MakeRequiredField<LongType>(118, std::string(MapType::kValueName)));
208+
inline static const SchemaField kValueCounts = MakeOptionalField<MapType>(
213209
109, "value_counts",
214-
std::make_shared<MapType>(
215-
SchemaField::MakeRequired(119, std::string(MapType::kKeyName),
216-
std::make_shared<IntType>()),
217-
SchemaField::MakeRequired(120, std::string(MapType::kValueName),
218-
std::make_shared<LongType>())));
219-
inline static const SchemaField kNullValueCounts = SchemaField::MakeOptional(
210+
MakeRequiredField<IntType>(119, std::string(MapType::kKeyName)),
211+
MakeRequiredField<LongType>(120, std::string(MapType::kValueName)));
212+
inline static const SchemaField kNullValueCounts = MakeOptionalField<MapType>(
220213
110, "null_value_counts",
221-
std::make_shared<MapType>(
222-
SchemaField::MakeRequired(121, std::string(MapType::kKeyName),
223-
std::make_shared<IntType>()),
224-
SchemaField::MakeRequired(122, std::string(MapType::kValueName),
225-
std::make_shared<LongType>())));
226-
inline static const SchemaField kNanValueCounts = SchemaField::MakeOptional(
214+
MakeRequiredField<IntType>(121, std::string(MapType::kKeyName)),
215+
MakeRequiredField<LongType>(122, std::string(MapType::kValueName)));
216+
inline static const SchemaField kNanValueCounts = MakeOptionalField<MapType>(
227217
137, "nan_value_counts",
228-
std::make_shared<MapType>(
229-
SchemaField::MakeRequired(138, std::string(MapType::kKeyName),
230-
std::make_shared<IntType>()),
231-
SchemaField::MakeRequired(139, std::string(MapType::kValueName),
232-
std::make_shared<LongType>())));
233-
inline static const SchemaField kLowerBounds = SchemaField::MakeOptional(
218+
MakeRequiredField<IntType>(138, std::string(MapType::kKeyName)),
219+
MakeRequiredField<LongType>(139, std::string(MapType::kValueName)));
220+
inline static const SchemaField kLowerBounds = MakeOptionalField<MapType>(
234221
125, "lower_bounds",
235-
std::make_shared<MapType>(
236-
SchemaField::MakeRequired(126, std::string(MapType::kKeyName),
237-
std::make_shared<IntType>()),
238-
SchemaField::MakeRequired(127, std::string(MapType::kValueName),
239-
std::make_shared<BinaryType>())));
240-
inline static const SchemaField kUpperBounds = SchemaField::MakeOptional(
222+
MakeRequiredField<IntType>(126, std::string(MapType::kKeyName)),
223+
MakeRequiredField<BinaryType>(127, std::string(MapType::kValueName)));
224+
inline static const SchemaField kUpperBounds = MakeOptionalField<MapType>(
241225
128, "upper_bounds",
242-
std::make_shared<MapType>(
243-
SchemaField::MakeRequired(129, std::string(MapType::kKeyName),
244-
std::make_shared<IntType>()),
245-
SchemaField::MakeRequired(130, std::string(MapType::kValueName),
246-
std::make_shared<BinaryType>())));
226+
MakeRequiredField<IntType>(129, std::string(MapType::kKeyName)),
227+
MakeRequiredField<BinaryType>(130, std::string(MapType::kValueName)));
247228
inline static const SchemaField kKeyMetadata =
248-
SchemaField::MakeOptional(131, "key_metadata", std::make_shared<BinaryType>());
249-
inline static const SchemaField kSplitOffsets = SchemaField::MakeOptional(
229+
MakeOptionalField<BinaryType>(131, "key_metadata");
230+
inline static const SchemaField kSplitOffsets = MakeOptionalField<ListType>(
250231
132, "split_offsets",
251-
std::make_shared<ListType>(SchemaField::MakeRequired(
252-
133, std::string(ListType::kElementName), std::make_shared<LongType>())));
253-
inline static const SchemaField kEqualityIds = SchemaField::MakeOptional(
232+
MakeRequiredField<LongType>(133, std::string(ListType::kElementName)));
233+
inline static const SchemaField kEqualityIds = MakeOptionalField<ListType>(
254234
135, "equality_ids",
255-
std::make_shared<ListType>(SchemaField::MakeRequired(
256-
136, std::string(ListType::kElementName), std::make_shared<IntType>())));
235+
MakeRequiredField<IntType>(136, std::string(ListType::kElementName)));
257236
inline static const SchemaField kSortOrderId =
258-
SchemaField::MakeOptional(140, "sort_order_id", std::make_shared<IntType>());
237+
MakeOptionalField<IntType>(140, "sort_order_id");
259238
inline static const SchemaField kFirstRowId =
260-
SchemaField::MakeOptional(142, "first_row_id", std::make_shared<LongType>());
261-
inline static const SchemaField kReferencedDataFile = SchemaField::MakeOptional(
262-
143, "referenced_data_file", std::make_shared<StringType>());
239+
MakeOptionalField<LongType>(142, "first_row_id");
240+
inline static const SchemaField kReferencedDataFile =
241+
MakeOptionalField<StringType>(143, "referenced_data_file");
263242
inline static const SchemaField kContentOffset =
264-
SchemaField::MakeOptional(144, "content_offset", std::make_shared<LongType>());
265-
inline static const SchemaField kContentSize = SchemaField::MakeOptional(
266-
145, "content_size_in_bytes", std::make_shared<LongType>());
243+
MakeOptionalField<LongType>(144, "content_offset");
244+
inline static const SchemaField kContentSize =
245+
MakeOptionalField<LongType>(145, "content_size_in_bytes");
267246

268247
static std::shared_ptr<StructType> Type(std::shared_ptr<StructType> partition_type);
269248
};
@@ -292,14 +271,13 @@ struct ICEBERG_EXPORT ManifestEntry {
292271
/// File path, partition tuple, metrics, ...
293272
DataFile data_file;
294273

295-
inline static const SchemaField kStatus =
296-
SchemaField::MakeRequired(0, "status", std::make_shared<IntType>());
274+
inline static const SchemaField kStatus = MakeRequiredField<IntType>(0, "status");
297275
inline static const SchemaField kSnapshotId =
298-
SchemaField::MakeOptional(1, "snapshot_id", std::make_shared<LongType>());
276+
MakeOptionalField<LongType>(1, "snapshot_id");
299277
inline static const SchemaField kSequenceNumber =
300-
SchemaField::MakeOptional(3, "sequence_number", std::make_shared<LongType>());
278+
MakeOptionalField<LongType>(3, "sequence_number");
301279
inline static const SchemaField kFileSequenceNumber =
302-
SchemaField::MakeOptional(4, "file_sequence_number", std::make_shared<LongType>());
280+
MakeOptionalField<LongType>(4, "file_sequence_number");
303281

304282
static std::shared_ptr<StructType> TypeFromPartitionType(
305283
std::shared_ptr<StructType> partition_type);

src/iceberg/manifest_list.h

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ struct ICEBERG_EXPORT PartitionFieldSummary {
8181
std::optional<std::vector<uint8_t>> upper_bound;
8282

8383
inline static const SchemaField kConsTainsNull =
84-
SchemaField::MakeRequired(509, "contains_null", std::make_shared<BooleanType>());
84+
MakeRequiredField<BooleanType>(509, "contains_null");
8585
inline static const SchemaField kContainsNaN =
86-
SchemaField::MakeOptional(518, "contains_nan", std::make_shared<BooleanType>());
86+
MakeOptionalField<BooleanType>(518, "contains_nan");
8787
inline static const SchemaField kLowerBound =
88-
SchemaField::MakeOptional(510, "lower_bound", std::make_shared<BinaryType>());
88+
MakeOptionalField<BinaryType>(510, "lower_bound");
8989
inline static const SchemaField kUpperBound =
90-
SchemaField::MakeOptional(511, "upper_bound", std::make_shared<BinaryType>());
90+
MakeOptionalField<BinaryType>(511, "upper_bound");
9191

9292
static const StructType& Type();
9393
};
@@ -165,40 +165,38 @@ struct ICEBERG_EXPORT ManifestFile {
165165
bool has_deleted_files() const { return deleted_files_count.value_or(-1) > 0; }
166166

167167
inline static const SchemaField kManifestPath =
168-
SchemaField::MakeRequired(500, "manifest_path", std::make_shared<StringType>());
168+
MakeRequiredField<StringType>(500, "manifest_path");
169169
inline static const SchemaField kManifestLength =
170-
SchemaField::MakeRequired(501, "manifest_length", std::make_shared<LongType>());
170+
MakeRequiredField<LongType>(501, "manifest_length");
171171
inline static const SchemaField kPartitionSpecId =
172-
SchemaField::MakeRequired(502, "partition_spec_id", std::make_shared<IntType>());
173-
inline static const SchemaField kContent =
174-
SchemaField::MakeOptional(517, "content", std::make_shared<IntType>());
172+
MakeRequiredField<IntType>(502, "partition_spec_id");
173+
inline static const SchemaField kContent = MakeOptionalField<IntType>(517, "content");
175174
inline static const SchemaField kSequenceNumber =
176-
SchemaField::MakeOptional(515, "sequence_number", std::make_shared<LongType>());
175+
MakeOptionalField<LongType>(515, "sequence_number");
177176
inline static const SchemaField kMinSequenceNumber =
178-
SchemaField::MakeOptional(516, "min_sequence_number", std::make_shared<LongType>());
177+
MakeOptionalField<LongType>(516, "min_sequence_number");
179178
inline static const SchemaField kAddedSnapshotId =
180-
SchemaField::MakeRequired(503, "added_snapshot_id", std::make_shared<LongType>());
179+
MakeRequiredField<LongType>(503, "added_snapshot_id");
181180
inline static const SchemaField kAddedFilesCount =
182-
SchemaField::MakeOptional(504, "added_files_count", std::make_shared<IntType>());
181+
MakeOptionalField<IntType>(504, "added_files_count");
183182
inline static const SchemaField kExistingFilesCount =
184-
SchemaField::MakeOptional(505, "existing_files_count", std::make_shared<IntType>());
183+
MakeOptionalField<IntType>(505, "existing_files_count");
185184
inline static const SchemaField kDeletedFilesCount =
186-
SchemaField::MakeOptional(506, "deleted_files_count", std::make_shared<IntType>());
185+
MakeOptionalField<IntType>(506, "deleted_files_count");
187186
inline static const SchemaField kAddedRowsCount =
188-
SchemaField::MakeOptional(512, "added_rows_count", std::make_shared<LongType>());
187+
MakeOptionalField<LongType>(512, "added_rows_count");
189188
inline static const SchemaField kExistingRowsCount =
190-
SchemaField::MakeOptional(513, "existing_rows_count", std::make_shared<LongType>());
189+
MakeOptionalField<LongType>(513, "existing_rows_count");
191190
inline static const SchemaField kDeletedRowsCount =
192-
SchemaField::MakeOptional(514, "deleted_rows_count", std::make_shared<LongType>());
193-
inline static const SchemaField kPartitions = SchemaField::MakeOptional(
191+
MakeOptionalField<LongType>(514, "deleted_rows_count");
192+
inline static const SchemaField kPartitions = MakeOptionalField<ListType>(
194193
507, "partitions",
195-
std::make_shared<ListType>(SchemaField::MakeRequired(
196-
508, std::string(ListType::kElementName),
197-
std::make_shared<StructType>(PartitionFieldSummary::Type()))));
194+
MakeRequiredField<StructType>(508, std::string(ListType::kElementName),
195+
PartitionFieldSummary::Type()));
198196
inline static const SchemaField kKeyMetadata =
199-
SchemaField::MakeOptional(519, "key_metadata", std::make_shared<BinaryType>());
197+
MakeOptionalField<BinaryType>(519, "key_metadata");
200198
inline static const SchemaField kFirstRowId =
201-
SchemaField::MakeOptional(520, "first_row_id", std::make_shared<LongType>());
199+
MakeOptionalField<LongType>(520, "first_row_id");
202200

203201
static const StructType& Type();
204202
};

src/iceberg/schema_field.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,16 @@ class ICEBERG_EXPORT SchemaField : public iceberg::util::Formattable {
8686
bool optional_;
8787
};
8888

89+
template <typename T, typename... Args>
90+
inline SchemaField MakeRequiredField(int id, std::string name, Args&&... args) {
91+
return SchemaField::MakeRequired(id, std::move(name),
92+
std::make_shared<T>(std::forward<Args>(args)...));
93+
}
94+
95+
template <typename T, typename... Args>
96+
inline SchemaField MakeOptionalField(int id, std::string name, Args&&... args) {
97+
return SchemaField::MakeOptional(id, std::move(name),
98+
std::make_shared<T>(std::forward<Args>(args)...));
99+
}
100+
89101
} // namespace iceberg

0 commit comments

Comments
 (0)