Skip to content

Commit 0dc4c11

Browse files
committed
add inline to the macro
Signed-off-by: Junwang Zhao <[email protected]>
1 parent 33d1fd7 commit 0dc4c11

File tree

3 files changed

+24
-29
lines changed

3 files changed

+24
-29
lines changed

src/iceberg/result.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ using Status = Result<void>;
6565
/// \brief Macro to define error creation functions
6666
#define DEFINE_ERROR_FUNCTION(name) \
6767
template <typename... Args> \
68-
auto name(const std::format_string<Args...> fmt, Args&&... args) \
68+
inline auto name(const std::format_string<Args...> fmt, Args&&... args) \
6969
-> unexpected<Error> { \
7070
return unexpected<Error>( \
7171
{ErrorKind::k##name, std::format(fmt, std::forward<Args>(args)...)}); \
@@ -80,6 +80,7 @@ DEFINE_ERROR_FUNCTION(IOError)
8080
DEFINE_ERROR_FUNCTION(JsonParseError)
8181
DEFINE_ERROR_FUNCTION(NoSuchNamespace)
8282
DEFINE_ERROR_FUNCTION(NoSuchTable)
83+
DEFINE_ERROR_FUNCTION(NotFound)
8384
DEFINE_ERROR_FUNCTION(NotImplemented)
8485
DEFINE_ERROR_FUNCTION(NotSupported)
8586
DEFINE_ERROR_FUNCTION(UnknownError)

src/iceberg/table_metadata.cc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <ranges>
2424
#include <string>
2525

26+
#include <iceberg/result.h>
27+
2628
#include "iceberg/expected.h"
2729
#include "iceberg/partition_spec.h"
2830
#include "iceberg/schema.h"
@@ -44,10 +46,7 @@ Result<std::shared_ptr<Schema>> TableMetadata::Schema() const {
4446
return schema->schema_id() == current_schema_id;
4547
});
4648
if (iter == schemas.end()) {
47-
return unexpected<Error>({
48-
.kind = ErrorKind::kNotFound,
49-
.message = std::format("Current schema is not found"),
50-
});
49+
return NotFound("Current schema is not found");
5150
}
5251
return *iter;
5352
}
@@ -57,10 +56,7 @@ Result<std::shared_ptr<PartitionSpec>> TableMetadata::PartitionSpec() const {
5756
return spec->spec_id() == default_spec_id;
5857
});
5958
if (iter == partition_specs.end()) {
60-
return unexpected<Error>({
61-
.kind = ErrorKind::kNotFound,
62-
.message = std::format("Default partition spec is not found"),
63-
});
59+
return NotFound("Default partition spec is not found");
6460
}
6561
return *iter;
6662
}
@@ -70,10 +66,7 @@ Result<std::shared_ptr<SortOrder>> TableMetadata::SortOrder() const {
7066
return order->order_id() == default_sort_order_id;
7167
});
7268
if (iter == sort_orders.end()) {
73-
return unexpected<Error>({
74-
.kind = ErrorKind::kNotFound,
75-
.message = std::format("Default sort order is not found"),
76-
});
69+
return NotFound("Default sort order is not found");
7770
}
7871
return *iter;
7972
}

test/metadata_serde_test.cc

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,23 @@ TEST_F(MetadataSerdeTest, DeserializeV2Valid) {
166166
EXPECT_EQ(metadata->current_snapshot_id, 3055729675574597004);
167167

168168
// Compare snapshots
169-
std::vector<Snapshot> expected_snapshots{{
170-
.snapshot_id = 3051729675574597004,
171-
.sequence_number = 0,
172-
.timestamp_ms = 1515100955770,
173-
.manifest_list = "s3://a/b/1.avro",
174-
.summary = {{"operation", "append"}},
175-
},
176-
{
177-
.snapshot_id = 3055729675574597004,
178-
.parent_snapshot_id = 3051729675574597004,
179-
.sequence_number = 1,
180-
.timestamp_ms = 1555100955770,
181-
.manifest_list = "s3://a/b/2.avro",
182-
.summary = {{"operation", "append"}},
183-
.schema_id = 1,
184-
}};
169+
std::vector<Snapshot> expected_snapshots{
170+
{
171+
.snapshot_id = 3051729675574597004,
172+
.sequence_number = 0,
173+
.timestamp_ms = TimePointMsFromUnixMs(1515100955770).value(),
174+
.manifest_list = "s3://a/b/1.avro",
175+
.summary = {{"operation", "append"}},
176+
},
177+
{
178+
.snapshot_id = 3055729675574597004,
179+
.parent_snapshot_id = 3051729675574597004,
180+
.sequence_number = 1,
181+
.timestamp_ms = TimePointMsFromUnixMs(1555100955770).value(),
182+
.manifest_list = "s3://a/b/2.avro",
183+
.summary = {{"operation", "append"}},
184+
.schema_id = 1,
185+
}};
185186
EXPECT_EQ(metadata->snapshots.size(), expected_snapshots.size());
186187
for (size_t i = 0; i < expected_snapshots.size(); ++i) {
187188
EXPECT_EQ(*metadata->snapshots[i], expected_snapshots[i]);

0 commit comments

Comments
 (0)