Skip to content

Commit e34ce83

Browse files
committed
datalake: refactor apply_evolution_rules result type
More readable code.
1 parent e2e124f commit e34ce83

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/v/datalake/catalog_schema_manager.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ checked<std::nullopt_t, fill_errc> check_schema_compat(
9898
// Returns true if successful, false if the fill is incomplete because the
9999
// table schema does not have all the necessary fields. The latter is a
100100
// signal that the caller needs to add the schema to the table.
101-
checked<bool, schema_manager::errc> apply_evolution_rules(
101+
using schema_update_required
102+
= ss::bool_class<struct schema_update_required_tag>;
103+
checked<schema_update_required, schema_manager::errc> apply_evolution_rules(
102104
const iceberg::table_identifier& table_id,
103105
const iceberg::table_metadata& table_meta,
104106
const iceberg::schema& schema,
@@ -121,10 +123,10 @@ checked<bool, schema_manager::errc> apply_evolution_rules(
121123
vlog(datalake_log.warn, "Type mismatch with table {}", table_id);
122124
return schema_manager::errc::not_supported;
123125
case fill_errc::schema_evolution_needed:
124-
return false;
126+
return schema_update_required::yes;
125127
}
126128
}
127-
return true;
129+
return schema_update_required::no;
128130
}
129131

130132
} // namespace
@@ -261,11 +263,11 @@ catalog_schema_manager::ensure_table_schema(
261263
// Make a copy so that we still have the original struct in case we
262264
// need to log it on the error path.
263265
auto merged_schema_with_evo = merged_schema_struct_type.copy();
264-
auto get_res = apply_evolution_rules(
266+
auto evo_res = apply_evolution_rules(
265267
table_id, txn.table(), *current_schema, merged_schema_with_evo);
266-
if (get_res.has_error()) {
267-
co_return get_res.error();
268-
} else if (get_res.value()) {
268+
if (evo_res.has_error()) {
269+
co_return evo_res.error();
270+
} else if (evo_res.value() == schema_update_required::no) {
269271
vlog(
270272
datalake_log.error,
271273
"Applying evolution rules on merged schema resulted in a "
@@ -294,11 +296,11 @@ catalog_schema_manager::ensure_table_schema(
294296
} else {
295297
// Apply evolution rules from current schema to writer schema.
296298
auto type_copy = writer_struct_type.copy();
297-
auto get_res = apply_evolution_rules(
299+
auto evo_res = apply_evolution_rules(
298300
table_id, txn.table(), *current_schema, type_copy);
299-
if (get_res.has_error()) {
300-
co_return get_res.error();
301-
} else if (!get_res.value()) {
301+
if (evo_res.has_error()) {
302+
co_return evo_res.error();
303+
} else if (evo_res.value() == schema_update_required::yes) {
302304
new_schema.emplace(std::move(type_copy));
303305
}
304306
}

0 commit comments

Comments
 (0)