From 4a2b7a2f36255847a149a5dfeaad5d5fab5f40ad Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Thu, 26 Sep 2024 15:32:54 +0100 Subject: [PATCH] agent: refactor resource_configs.update_materialization_resource_spec --- crates/agent/src/resource_configs.rs | 36 +++++++++++++--------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/crates/agent/src/resource_configs.rs b/crates/agent/src/resource_configs.rs index 79bfe639df..739c279dab 100644 --- a/crates/agent/src/resource_configs.rs +++ b/crates/agent/src/resource_configs.rs @@ -36,35 +36,31 @@ pub fn update_materialization_resource_spec( let source_capture_def = source_capture.to_normalized_def(); if source_capture_def.target_schema == SourceCaptureSchemaMode::FromSourceName { - if let Some(x_schema_name_ptr) = &resource_spec_pointers.x_schema_name { - if let Some(x_schema_name_prev) = x_schema_name_ptr.create_value(resource_spec) { - let _ = std::mem::replace(x_schema_name_prev, x_schema_name.into()); - } else { - anyhow::bail!( - "cannot create location '{x_schema_name_ptr}' in resource spec '{resource_spec}'" - ); - } - } else { + let Some(x_schema_name_ptr) = &resource_spec_pointers.x_schema_name else { anyhow::bail!( "sourceCapture.targetSchema set on a materialization which does not have x-schema-name annotation" ); - } + }; + let Some(x_schema_name_prev) = x_schema_name_ptr.create_value(resource_spec) else { + anyhow::bail!( + "cannot create location '{x_schema_name_ptr}' in resource spec '{resource_spec}'" + ); + }; + let _ = std::mem::replace(x_schema_name_prev, x_schema_name.into()); } if source_capture_def.delta_updates { - if let Some(x_delta_updates_ptr) = &resource_spec_pointers.x_delta_updates { - if let Some(x_delta_updates_prev) = x_delta_updates_ptr.create_value(resource_spec) { - let _ = std::mem::replace(x_delta_updates_prev, true.into()); - } else { - anyhow::bail!( - "cannot create location '{x_delta_updates_ptr}' in resource spec '{resource_spec}'" - ); - } - } else { + let Some(x_delta_updates_ptr) = &resource_spec_pointers.x_delta_updates else { anyhow::bail!( "sourceCapture.deltaUpdates set on a materialization which does not have x-delta-updates annotation" ); - } + }; + let Some(x_delta_updates_prev) = x_delta_updates_ptr.create_value(resource_spec) else { + anyhow::bail!( + "cannot create location '{x_delta_updates_ptr}' in resource spec '{resource_spec}'" + ); + }; + let _ = std::mem::replace(x_delta_updates_prev, true.into()); } Ok(())