Conciseness cleanups#30
Conversation
- metrics.rs: replace the 13 hand-written counter registrations with a counter_registry! macro (single source of truth for field + id + desc), collapse 5 observable gauges into a layer_gauge! macro, and generate the no-arg record_* helpers via a simple_recorders! macro. - Remove a duplicated #[instrument] attribute on head_cached. - Extract config::is_insecure_auth_allowed(), shared by the pgwire and gRPC auth paths instead of inlining the env-var check twice. - Extract record_query_span() in pgwire_handlers, used by both the simple and extended query handlers.
Adds derive_more (debug + display features) and uses it for:
- StorageConfig: #[debug("[redacted]")] on the two credential fields keeps
them out of {:?} output without a hand-rolled fmt impl.
- DmlQueryPlanner / DmlExec: #[debug(skip)] on the non-printable plan/session
fields, preserving the previous Debug output.
- FoyerObjectStoreCache: container-level #[display]/#[debug] over inner.
Behavior-preserving; removes ~45 lines of boilerplate fmt code.
- Route the two error-swallowing payload-collection sites (proactive and
background _last_checkpoint refresh) through the existing collect_payload
helper instead of re-inlining the Stream/File match. The two sites that
propagate errors or slice ranges keep their bespoke handling.
- Extract table_path_from_uri(), shared by both invalidate_checkpoint_cache
impls instead of duplicating the scheme-strip + trim logic.
- Extract is_parquet_file() and use it at the 7 inline .ends_with(".parquet")
call sites.
ToCharUDF and AtTimeZoneUDF both inlined the same ~20-line block to pull a constant UTF-8 string out of a scalar-or-length-1-array argument (StringView or String). Factor it into extract_scalar_string(arg, label); the label parameterizes the error messages. Preserves the && short-circuit so is_null(0) is never evaluated on an empty array.
The as_any/name/signature trio was spelled out identically in every UDF
ScalarUDFImpl block. A scalar_udf_boilerplate!("name") macro emits all three;
return_type and invoke_with_args stay per-impl. Covers JsonToPgText, ToChar,
AtTimeZone, JsonBuildArray, ToJson, ExtractEpoch, ApproxPercentile and
JsonbPathExists.
- functions.rs: push_json_primitive! macro collapses the identical downcast + null-aware json!() loop for the Int64/Float64/Boolean arms. - manifest.rs: extract mutate() for the shared load->apply->save skeleton behind upsert() and remove_many().
query() and query_partitioned() both matched on the optional compiled predicate to filter a bucket snapshot. Factor that into filter_snapshot(); the text_match query variant keeps its bespoke id-set + predicate flow. Verified by the mem_buffer unit tests (27 passed).
The DynamoDB-locking storage-option block was written twice: once in AwsConfig::build_storage_options and again, hand-inlined, in the per-project custom-table path in database.rs. Extract a single add_dynamodb_locking_options method and call it from both, so the locking config has one source of truth.
Code Review: Conciseness CleanupsThis is a solid refactoring PR that achieves genuine reduction of repetition (-180 net lines across 12 files) without behavioral changes. The extractions are well-scoped and improve long-term maintainability. A few minor items worth noting. Summary of Changes
Security: Improvement Worth HighlightingReplacing the manual Minor Issues1. Subtle error message regression in The shared helper normalizes messages. For the non-scalar array path, the original 2. The original impl called 3. This was the same behaviour before (the read was inlined), but extraction makes it more visible. It is only called at startup/connection time so there is no performance concern. The real risk is in tests that mutate env vars between calls — both auth paths could see different values. Caching in 4. PR description is not filled in The "Closes #" line and checklist items are left at template defaults. Even for a cleanup PR it helps to note that no tests are required (pure refactor) and which issue, if any, prompted it. Nits
VerdictApproved with minor suggestions. Each extraction is small enough to verify at a glance and improves the code without over-abstracting. The credential-redaction change is a net security improvement. The only thing worth confirming before merge is that no tests assert on the exact error strings that were normalized. |
Closes #
How to test
Checklist