Skip to content

Commit 60af2dd

Browse files
committed
refactor: initialize missing fields in TableMetadata and update compile options
1 parent c4149ce commit 60af2dd

4 files changed

Lines changed: 75 additions & 20 deletions

File tree

src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
2020
if(MSVC)
2121
add_compile_options(/W4 /we4100)
2222
else()
23-
add_compile_options(-Wall -Wextra -Werror=unused-parameter)
23+
add_compile_options(-Wall -Wextra -Werror=unused-parameter
24+
-Werror=missing-field-initializers)
2425
endif()
2526

2627
add_subdirectory(iceberg)

src/iceberg/table_metadata.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,31 @@ struct ICEBERG_EXPORT TableMetadata {
8080
static inline const std::unordered_map<TypeId, int8_t> kMinFormatVersions{};
8181

8282
/// An integer version number for the format
83-
int8_t format_version = 0;
83+
int8_t format_version;
8484
/// A UUID that identifies the table
8585
std::string table_uuid;
8686
/// The table's base location
8787
std::string location;
8888
/// The table's highest assigned sequence number
89-
int64_t last_sequence_number = 0;
89+
int64_t last_sequence_number;
9090
/// Timestamp in milliseconds from the unix epoch when the table was last updated.
91-
TimePointMs last_updated_ms{};
91+
TimePointMs last_updated_ms;
9292
/// The highest assigned column ID for the table
93-
int32_t last_column_id = 0;
93+
int32_t last_column_id;
9494
/// A list of schemas
9595
std::vector<std::shared_ptr<iceberg::Schema>> schemas;
9696
/// ID of the table's current schema
97-
int32_t current_schema_id = 0;
97+
int32_t current_schema_id;
9898
/// A list of partition specs
9999
std::vector<std::shared_ptr<iceberg::PartitionSpec>> partition_specs;
100100
/// ID of the current partition spec that writers should use by default
101-
int32_t default_spec_id{};
101+
int32_t default_spec_id;
102102
/// The highest assigned partition field ID across all partition specs for the table
103-
int32_t last_partition_id{};
103+
int32_t last_partition_id;
104104
/// A string to string map of table properties
105-
TableProperties properties{};
105+
TableProperties properties;
106106
/// ID of the current table snapshot
107-
int64_t current_snapshot_id = 0;
107+
int64_t current_snapshot_id;
108108
/// A list of valid snapshots
109109
std::vector<std::shared_ptr<iceberg::Snapshot>> snapshots;
110110
/// A list of timestamp and snapshot ID pairs that encodes changes to the current
@@ -116,15 +116,15 @@ struct ICEBERG_EXPORT TableMetadata {
116116
/// A list of sort orders
117117
std::vector<std::shared_ptr<iceberg::SortOrder>> sort_orders;
118118
/// Default sort order id of the table
119-
int32_t default_sort_order_id = 0;
119+
int32_t default_sort_order_id;
120120
/// A map of snapshot references
121121
std::unordered_map<std::string, std::shared_ptr<SnapshotRef>> refs;
122122
/// A list of table statistics
123123
std::vector<std::shared_ptr<struct StatisticsFile>> statistics;
124124
/// A list of partition statistics
125125
std::vector<std::shared_ptr<struct PartitionStatisticsFile>> partition_statistics;
126126
/// A `long` higher than all assigned row IDs
127-
int64_t next_row_id = 0;
127+
int64_t next_row_id;
128128

129129
static Result<std::unique_ptr<TableMetadata>> Make(
130130
const Schema& schema, const PartitionSpec& spec, const SortOrder& sort_order,

src/iceberg/test/metrics_config_test.cc

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,29 @@ TEST(MetricsConfigTest, ForTable) {
7272

7373
{
7474
// Default
75-
auto metadata = std::make_shared<TableMetadata>(
76-
TableMetadata{.format_version = 2, .schemas = {schema}, .current_schema_id = 1});
75+
auto metadata =
76+
std::make_shared<TableMetadata>(TableMetadata{.format_version = 2,
77+
.table_uuid = "",
78+
.location = "",
79+
.last_sequence_number = 0,
80+
.last_updated_ms = {},
81+
.last_column_id = 0,
82+
.schemas = {schema},
83+
.current_schema_id = 1,
84+
.partition_specs = {},
85+
.default_spec_id = 0,
86+
.last_partition_id = 0,
87+
.properties = {},
88+
.current_snapshot_id = 0,
89+
.snapshots = {},
90+
.snapshot_log = {},
91+
.metadata_log = {},
92+
.sort_orders = {},
93+
.default_sort_order_id = 0,
94+
.refs = {},
95+
.statistics = {},
96+
.partition_statistics = {},
97+
.next_row_id = 0});
7798
ICEBERG_UNWRAP_OR_FAIL(
7899
auto table, Table::Make(ident, metadata, "s3://bucket/meta.json", io, catalog));
79100

@@ -94,10 +115,28 @@ TEST(MetricsConfigTest, ForTable) {
94115
// Custom metrics mode by set default metrics mode properties
95116
auto metadata = std::make_shared<TableMetadata>(
96117
TableMetadata{.format_version = 2,
118+
.table_uuid = "",
119+
.location = "",
120+
.last_sequence_number = 0,
121+
.last_updated_ms = {},
122+
.last_column_id = 0,
97123
.schemas = {schema},
98124
.current_schema_id = 1,
125+
.partition_specs = {},
126+
.default_spec_id = 0,
127+
.last_partition_id = 0,
99128
.properties = TableProperties::FromMap(
100-
{{TableProperties::kDefaultWriteMetricsMode.key(), "full"}})});
129+
{{TableProperties::kDefaultWriteMetricsMode.key(), "full"}}),
130+
.current_snapshot_id = 0,
131+
.snapshots = {},
132+
.snapshot_log = {},
133+
.metadata_log = {},
134+
.sort_orders = {},
135+
.default_sort_order_id = 0,
136+
.refs = {},
137+
.statistics = {},
138+
.partition_statistics = {},
139+
.next_row_id = 0});
101140
ICEBERG_UNWRAP_OR_FAIL(
102141
auto table, Table::Make(ident, metadata, "s3://bucket/meta.json", io, catalog));
103142

@@ -123,16 +162,31 @@ TEST(MetricsConfigTest, ForTable) {
123162

124163
auto metadata = std::make_shared<TableMetadata>(TableMetadata{
125164
.format_version = 2,
165+
.table_uuid = "",
166+
.location = "",
167+
.last_sequence_number = 0,
168+
.last_updated_ms = {},
169+
.last_column_id = 0,
126170
.schemas = {schema},
127171
.current_schema_id = 1,
172+
.partition_specs = {},
173+
.default_spec_id = 0,
174+
.last_partition_id = 0,
128175
.properties = TableProperties::FromMap(
129176
{{TableProperties::kDefaultWriteMetricsMode.key(), "none"},
130177
{TableProperties::kMetricsMaxInferredColumnDefaults.key(), "2"},
131178
{std::string(TableProperties::kMetricModeColumnConfPrefix) + "name",
132179
"full"}}),
180+
.current_snapshot_id = 0,
181+
.snapshots = {},
182+
.snapshot_log = {},
183+
.metadata_log = {},
133184
.sort_orders = {sort_order},
134185
.default_sort_order_id = 1,
135-
});
186+
.refs = {},
187+
.statistics = {},
188+
.partition_statistics = {},
189+
.next_row_id = 0});
136190

137191
ICEBERG_UNWRAP_OR_FAIL(
138192
auto table, Table::Make(ident, metadata, "s3://bucket/meta.json", io, catalog));

src/iceberg/test/schema_test.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ struct SelectTestParam {
709709
std::function<std::unique_ptr<iceberg::Schema>()> create_schema;
710710
std::vector<std::string> select_fields;
711711
std::function<std::unique_ptr<iceberg::Schema>()> expected_schema;
712-
bool should_succeed;
713-
std::string expected_error_message;
712+
bool should_succeed = false;
713+
std::string expected_error_message = "";
714714
bool case_sensitive = true;
715715
};
716716

@@ -850,8 +850,8 @@ struct ProjectTestParam {
850850
std::function<std::unique_ptr<iceberg::Schema>()> create_schema;
851851
std::unordered_set<int32_t> selected_ids;
852852
std::function<std::unique_ptr<iceberg::Schema>()> expected_schema;
853-
bool should_succeed;
854-
std::string expected_error_message;
853+
bool should_succeed = false;
854+
std::string expected_error_message = "";
855855
};
856856

857857
class ProjectParamTest : public ::testing::TestWithParam<ProjectTestParam> {};

0 commit comments

Comments
 (0)