Skip to content

Commit

Permalink
agent: refactor resource_configs.update_materialization_resource_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mdibaiee committed Sep 26, 2024
1 parent 410d406 commit 4a2b7a2
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions crates/agent/src/resource_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down

0 comments on commit 4a2b7a2

Please sign in to comment.