Skip to content

Commit 0779a52

Browse files
authored
refactor: add factory functions for primitive types (#134)
1 parent c06c261 commit 0779a52

24 files changed

+502
-502
lines changed

src/iceberg/expression/literal.cc

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,32 +126,22 @@ Literal::Literal(Value value, std::shared_ptr<PrimitiveType> type)
126126
: value_(std::move(value)), type_(std::move(type)) {}
127127

128128
// Factory methods
129-
Literal Literal::Boolean(bool value) {
130-
return {Value{value}, std::make_shared<BooleanType>()};
131-
}
129+
Literal Literal::Boolean(bool value) { return {Value{value}, iceberg::boolean()}; }
132130

133-
Literal Literal::Int(int32_t value) {
134-
return {Value{value}, std::make_shared<IntType>()};
135-
}
131+
Literal Literal::Int(int32_t value) { return {Value{value}, iceberg::int32()}; }
136132

137-
Literal Literal::Long(int64_t value) {
138-
return {Value{value}, std::make_shared<LongType>()};
139-
}
133+
Literal Literal::Long(int64_t value) { return {Value{value}, iceberg::int64()}; }
140134

141-
Literal Literal::Float(float value) {
142-
return {Value{value}, std::make_shared<FloatType>()};
143-
}
135+
Literal Literal::Float(float value) { return {Value{value}, iceberg::float32()}; }
144136

145-
Literal Literal::Double(double value) {
146-
return {Value{value}, std::make_shared<DoubleType>()};
147-
}
137+
Literal Literal::Double(double value) { return {Value{value}, iceberg::float64()}; }
148138

149139
Literal Literal::String(std::string value) {
150-
return {Value{std::move(value)}, std::make_shared<StringType>()};
140+
return {Value{std::move(value)}, iceberg::string()};
151141
}
152142

153143
Literal Literal::Binary(std::vector<uint8_t> value) {
154-
return {Value{std::move(value)}, std::make_shared<BinaryType>()};
144+
return {Value{std::move(value)}, iceberg::binary()};
155145
}
156146

157147
Result<Literal> Literal::Deserialize(std::span<const uint8_t> data,

src/iceberg/manifest_entry.h

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -176,94 +176,90 @@ struct ICEBERG_EXPORT DataFile {
176176
std::optional<int64_t> content_size_in_bytes;
177177

178178
inline static const SchemaField kContent = SchemaField::MakeRequired(
179-
134, "content", std::make_shared<IntType>(),
179+
134, "content", iceberg::int32(),
180180
"Contents of the file: 0=data, 1=position deletes, 2=equality deletes");
181181
inline static const SchemaField kFilePath = SchemaField::MakeRequired(
182-
100, "file_path", std::make_shared<StringType>(), "Location URI with FS scheme");
183-
inline static const SchemaField kFileFormat =
184-
SchemaField::MakeRequired(101, "file_format", std::make_shared<IntType>(),
185-
"File format name: avro, orc, or parquet");
182+
100, "file_path", iceberg::string(), "Location URI with FS scheme");
183+
inline static const SchemaField kFileFormat = SchemaField::MakeRequired(
184+
101, "file_format", iceberg::int32(), "File format name: avro, orc, or parquet");
186185
inline static const SchemaField kRecordCount = SchemaField::MakeRequired(
187-
103, "record_count", std::make_shared<LongType>(), "Number of records in the file");
188-
inline static const SchemaField kFileSize =
189-
SchemaField::MakeRequired(104, "file_size_in_bytes", std::make_shared<LongType>(),
190-
"Total file size in bytes");
186+
103, "record_count", iceberg::int64(), "Number of records in the file");
187+
inline static const SchemaField kFileSize = SchemaField::MakeRequired(
188+
104, "file_size_in_bytes", iceberg::int64(), "Total file size in bytes");
191189
inline static const SchemaField kColumnSizes = SchemaField::MakeOptional(
192190
108, "column_sizes",
193191
std::make_shared<MapType>(
194192
SchemaField::MakeRequired(117, std::string(MapType::kKeyName),
195-
std::make_shared<IntType>()),
193+
iceberg::int32()),
196194
SchemaField::MakeRequired(118, std::string(MapType::kValueName),
197-
std::make_shared<LongType>())),
195+
iceberg::int64())),
198196
"Map of column id to total size on disk");
199197
inline static const SchemaField kValueCounts = SchemaField::MakeOptional(
200198
109, "value_counts",
201199
std::make_shared<MapType>(
202200
SchemaField::MakeRequired(119, std::string(MapType::kKeyName),
203-
std::make_shared<IntType>()),
201+
iceberg::int32()),
204202
SchemaField::MakeRequired(120, std::string(MapType::kValueName),
205-
std::make_shared<LongType>())),
203+
iceberg::int64())),
206204
"Map of column id to total count, including null and NaN");
207205
inline static const SchemaField kNullValueCounts = SchemaField::MakeOptional(
208206
110, "null_value_counts",
209207
std::make_shared<MapType>(
210208
SchemaField::MakeRequired(121, std::string(MapType::kKeyName),
211-
std::make_shared<IntType>()),
209+
iceberg::int32()),
212210
SchemaField::MakeRequired(122, std::string(MapType::kValueName),
213-
std::make_shared<LongType>())),
211+
iceberg::int64())),
214212
"Map of column id to null value count");
215213
inline static const SchemaField kNanValueCounts = SchemaField::MakeOptional(
216214
137, "nan_value_counts",
217215
std::make_shared<MapType>(
218216
SchemaField::MakeRequired(138, std::string(MapType::kKeyName),
219-
std::make_shared<IntType>()),
217+
iceberg::int32()),
220218
SchemaField::MakeRequired(139, std::string(MapType::kValueName),
221-
std::make_shared<LongType>())),
219+
iceberg::int64())),
222220
"Map of column id to number of NaN values in the column");
223221
inline static const SchemaField kLowerBounds = SchemaField::MakeOptional(
224222
125, "lower_bounds",
225223
std::make_shared<MapType>(
226224
SchemaField::MakeRequired(126, std::string(MapType::kKeyName),
227-
std::make_shared<IntType>()),
225+
iceberg::int32()),
228226
SchemaField::MakeRequired(127, std::string(MapType::kValueName),
229-
std::make_shared<BinaryType>())),
227+
iceberg::binary())),
230228
"Map of column id to lower bound");
231229
inline static const SchemaField kUpperBounds = SchemaField::MakeOptional(
232230
128, "upper_bounds",
233231
std::make_shared<MapType>(
234232
SchemaField::MakeRequired(129, std::string(MapType::kKeyName),
235-
std::make_shared<IntType>()),
233+
iceberg::int32()),
236234
SchemaField::MakeRequired(130, std::string(MapType::kValueName),
237-
std::make_shared<BinaryType>())),
235+
iceberg::binary())),
238236
"Map of column id to upper bound");
239-
inline static const SchemaField kKeyMetadata =
240-
SchemaField::MakeOptional(131, "key_metadata", std::make_shared<BinaryType>(),
241-
"Encryption key metadata blob");
237+
inline static const SchemaField kKeyMetadata = SchemaField::MakeOptional(
238+
131, "key_metadata", iceberg::binary(), "Encryption key metadata blob");
242239
inline static const SchemaField kSplitOffsets = SchemaField::MakeOptional(
243240
132, "split_offsets",
244241
std::make_shared<ListType>(SchemaField::MakeRequired(
245-
133, std::string(ListType::kElementName), std::make_shared<LongType>())),
242+
133, std::string(ListType::kElementName), iceberg::int64())),
246243
"Splittable offsets");
247244
inline static const SchemaField kEqualityIds = SchemaField::MakeOptional(
248245
135, "equality_ids",
249246
std::make_shared<ListType>(SchemaField::MakeRequired(
250-
136, std::string(ListType::kElementName), std::make_shared<IntType>())),
247+
136, std::string(ListType::kElementName), iceberg::int32())),
251248
"Equality comparison field IDs");
252-
inline static const SchemaField kSortOrderId = SchemaField::MakeOptional(
253-
140, "sort_order_id", std::make_shared<IntType>(), "Sort order ID");
254-
inline static const SchemaField kFirstRowId =
255-
SchemaField::MakeOptional(142, "first_row_id", std::make_shared<LongType>(),
256-
"Starting row ID to assign to new rows");
249+
inline static const SchemaField kSortOrderId =
250+
SchemaField::MakeOptional(140, "sort_order_id", iceberg::int32(), "Sort order ID");
251+
inline static const SchemaField kFirstRowId = SchemaField::MakeOptional(
252+
142, "first_row_id", iceberg::int64(), "Starting row ID to assign to new rows");
257253
inline static const SchemaField kReferencedDataFile = SchemaField::MakeOptional(
258-
143, "referenced_data_file", std::make_shared<StringType>(),
254+
143, "referenced_data_file", iceberg::string(),
259255
"Fully qualified location (URI with FS scheme) of a data file that all deletes "
260256
"reference");
261257
inline static const SchemaField kContentOffset =
262-
SchemaField::MakeOptional(144, "content_offset", std::make_shared<LongType>(),
258+
SchemaField::MakeOptional(144, "content_offset", iceberg::int64(),
263259
"The offset in the file where the content starts");
264-
inline static const SchemaField kContentSize = SchemaField::MakeOptional(
265-
145, "content_size_in_bytes", std::make_shared<LongType>(),
266-
"The length of referenced content stored in the file");
260+
inline static const SchemaField kContentSize =
261+
SchemaField::MakeOptional(145, "content_size_in_bytes", iceberg::int64(),
262+
"The length of referenced content stored in the file");
267263

268264
static std::shared_ptr<StructType> Type(std::shared_ptr<StructType> partition_type);
269265
};
@@ -293,13 +289,13 @@ struct ICEBERG_EXPORT ManifestEntry {
293289
DataFile data_file;
294290

295291
inline static const SchemaField kStatus =
296-
SchemaField::MakeRequired(0, "status", std::make_shared<IntType>());
292+
SchemaField::MakeRequired(0, "status", iceberg::int32());
297293
inline static const SchemaField kSnapshotId =
298-
SchemaField::MakeOptional(1, "snapshot_id", std::make_shared<LongType>());
294+
SchemaField::MakeOptional(1, "snapshot_id", iceberg::int64());
299295
inline static const SchemaField kSequenceNumber =
300-
SchemaField::MakeOptional(3, "sequence_number", std::make_shared<LongType>());
296+
SchemaField::MakeOptional(3, "sequence_number", iceberg::int64());
301297
inline static const SchemaField kFileSequenceNumber =
302-
SchemaField::MakeOptional(4, "file_sequence_number", std::make_shared<LongType>());
298+
SchemaField::MakeOptional(4, "file_sequence_number", iceberg::int64());
303299

304300
static std::shared_ptr<StructType> TypeFromPartitionType(
305301
std::shared_ptr<StructType> partition_type);

src/iceberg/manifest_list.h

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,15 @@ struct ICEBERG_EXPORT PartitionFieldSummary {
5454
std::optional<std::vector<uint8_t>> upper_bound;
5555

5656
inline static const SchemaField kContainsNull =
57-
SchemaField::MakeRequired(509, "contains_null", std::make_shared<BooleanType>(),
57+
SchemaField::MakeRequired(509, "contains_null", iceberg::boolean(),
5858
"True if any file has a null partition value");
5959
inline static const SchemaField kContainsNaN =
60-
SchemaField::MakeOptional(518, "contains_nan", std::make_shared<BooleanType>(),
60+
SchemaField::MakeOptional(518, "contains_nan", iceberg::boolean(),
6161
"True if any file has a nan partition value");
62-
inline static const SchemaField kLowerBound =
63-
SchemaField::MakeOptional(510, "lower_bound", std::make_shared<BinaryType>(),
64-
"Partition lower bound for all files");
65-
inline static const SchemaField kUpperBound =
66-
SchemaField::MakeOptional(511, "upper_bound", std::make_shared<BinaryType>(),
67-
"Partition upper bound for all files");
62+
inline static const SchemaField kLowerBound = SchemaField::MakeOptional(
63+
510, "lower_bound", iceberg::binary(), "Partition lower bound for all files");
64+
inline static const SchemaField kUpperBound = SchemaField::MakeOptional(
65+
511, "upper_bound", iceberg::binary(), "Partition upper bound for all files");
6866

6967
static const StructType& Type();
7068
};
@@ -150,48 +148,44 @@ struct ICEBERG_EXPORT ManifestFile {
150148
/// \brief Checks if this manifest file contains entries with DELETED status
151149
bool has_deleted_files() const { return deleted_files_count.value_or(1) > 0; }
152150

153-
inline static const SchemaField kManifestPath =
154-
SchemaField::MakeRequired(500, "manifest_path", std::make_shared<StringType>(),
155-
"Location URI with FS scheme");
151+
inline static const SchemaField kManifestPath = SchemaField::MakeRequired(
152+
500, "manifest_path", iceberg::string(), "Location URI with FS scheme");
156153
inline static const SchemaField kManifestLength = SchemaField::MakeRequired(
157-
501, "manifest_length", std::make_shared<LongType>(), "Total file size in bytes");
154+
501, "manifest_length", iceberg::int64(), "Total file size in bytes");
158155
inline static const SchemaField kPartitionSpecId = SchemaField::MakeRequired(
159-
502, "partition_spec_id", std::make_shared<IntType>(), "Spec ID used to write");
160-
inline static const SchemaField kContent =
161-
SchemaField::MakeOptional(517, "content", std::make_shared<IntType>(),
162-
"Contents of the manifest: 0=data, 1=deletes");
156+
502, "partition_spec_id", iceberg::int32(), "Spec ID used to write");
157+
inline static const SchemaField kContent = SchemaField::MakeOptional(
158+
517, "content", iceberg::int32(), "Contents of the manifest: 0=data, 1=deletes");
163159
inline static const SchemaField kSequenceNumber =
164-
SchemaField::MakeOptional(515, "sequence_number", std::make_shared<LongType>(),
160+
SchemaField::MakeOptional(515, "sequence_number", iceberg::int64(),
165161
"Sequence number when the manifest was added");
166162
inline static const SchemaField kMinSequenceNumber =
167-
SchemaField::MakeOptional(516, "min_sequence_number", std::make_shared<LongType>(),
163+
SchemaField::MakeOptional(516, "min_sequence_number", iceberg::int64(),
168164
"Lowest sequence number in the manifest");
169-
inline static const SchemaField kAddedSnapshotId =
170-
SchemaField::MakeRequired(503, "added_snapshot_id", std::make_shared<LongType>(),
171-
"Snapshot ID that added the manifest");
165+
inline static const SchemaField kAddedSnapshotId = SchemaField::MakeRequired(
166+
503, "added_snapshot_id", iceberg::int64(), "Snapshot ID that added the manifest");
172167
inline static const SchemaField kAddedFilesCount = SchemaField::MakeOptional(
173-
504, "added_files_count", std::make_shared<IntType>(), "Added entry count");
168+
504, "added_files_count", iceberg::int32(), "Added entry count");
174169
inline static const SchemaField kExistingFilesCount = SchemaField::MakeOptional(
175-
505, "existing_files_count", std::make_shared<IntType>(), "Existing entry count");
170+
505, "existing_files_count", iceberg::int32(), "Existing entry count");
176171
inline static const SchemaField kDeletedFilesCount = SchemaField::MakeOptional(
177-
506, "deleted_files_count", std::make_shared<IntType>(), "Deleted entry count");
172+
506, "deleted_files_count", iceberg::int32(), "Deleted entry count");
178173
inline static const SchemaField kAddedRowsCount = SchemaField::MakeOptional(
179-
512, "added_rows_count", std::make_shared<LongType>(), "Added rows count");
174+
512, "added_rows_count", iceberg::int64(), "Added rows count");
180175
inline static const SchemaField kExistingRowsCount = SchemaField::MakeOptional(
181-
513, "existing_rows_count", std::make_shared<LongType>(), "Existing rows count");
176+
513, "existing_rows_count", iceberg::int64(), "Existing rows count");
182177
inline static const SchemaField kDeletedRowsCount = SchemaField::MakeOptional(
183-
514, "deleted_rows_count", std::make_shared<LongType>(), "Deleted rows count");
178+
514, "deleted_rows_count", iceberg::int64(), "Deleted rows count");
184179
inline static const SchemaField kPartitions = SchemaField::MakeOptional(
185180
507, "partitions",
186181
std::make_shared<ListType>(SchemaField::MakeRequired(
187182
508, std::string(ListType::kElementName),
188183
std::make_shared<StructType>(PartitionFieldSummary::Type()))),
189184
"Summary for each partition");
190-
inline static const SchemaField kKeyMetadata =
191-
SchemaField::MakeOptional(519, "key_metadata", std::make_shared<BinaryType>(),
192-
"Encryption key metadata blob");
185+
inline static const SchemaField kKeyMetadata = SchemaField::MakeOptional(
186+
519, "key_metadata", iceberg::binary(), "Encryption key metadata blob");
193187
inline static const SchemaField kFirstRowId = SchemaField::MakeOptional(
194-
520, "first_row_id", std::make_shared<LongType>(),
188+
520, "first_row_id", iceberg::int64(),
195189
"Starting row ID to assign to new rows in ADDED data files");
196190

197191
static const StructType& Type();

0 commit comments

Comments
 (0)