feat(pragmastats): adds to stats cache#3596
Merged
Merged
Conversation
One-sample mode now appends 7 robust statistic columns (ps_n, ps_center, ps_spread, ps_center_lower, ps_center_upper, ps_spread_lower, ps_spread_upper) to the .stats.csv cache file, matching the moarstats pattern. Added --standalone flag to preserve the old standalone CSV output, plus --stats-options, --round, and --force flags. Extracted get_stats_csv_path() to util.rs for sharing between moarstats and pragmastat. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…idation - Write to temp file then rename when updating stats cache in-place, preventing cache corruption on partial write failures (e.g. disk full) - Error out if stats CSV lacks required 'field' or 'type' columns instead of silently producing empty ps_* fields - Build complete StringRecord per row instead of individual write_field calls, making column count mismatches easier to catch - Clarify --force behavior: always regenerates full baseline stats then recomputes ps_* columns Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates pragmastat so that (in one-sample mode) it can append computed ps_* columns into the existing .stats.csv cache file by default, while providing a --standalone flag to preserve the prior “print CSV to stdout” behavior.
Changes:
- Make one-sample
pragmastatdefault to cache-append behavior; add--standaloneto force old stdout CSV output. - Add shared
util::get_stats_csv_pathand refactormoarstatsto use it. - Expand the pragmastat test suite with cache-append scenarios and adjust existing tests to use
--standalonewhen they expect stdout output.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
tests/test_pragmastat.rs |
Updates existing tests for the new default behavior and adds new tests covering cache-append behavior. |
src/util.rs |
Adds a shared helper to compute the absolute .stats.csv path for an input CSV. |
src/cmd/pragmastat.rs |
Implements cache-append mode, adds new CLI flags (--standalone, --stats-options, --round, --force), and updates help text. |
src/cmd/moarstats.rs |
Removes local stats-path logic and delegates to util::get_stats_csv_path. |
- --force only recomputes ps_* columns, no longer regenerates baseline stats (avoids clobbering moarstats columns) - Auto-generated stats inherit --delimiter and --no-headers from input - Derive ColType from stats CSV "type" column instead of result_map - Fix temp file naming: append ".tmp" suffix instead of with_extension() - Add Windows-safe rename (remove before rename since fs::rename won't overwrite) - Wire --round through all standalone formatting paths; remove redundant fmt_point_round/fmt_spread_round helpers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… rename Move ColType derivation inside the `if is_numeric_type` block so it's only computed when actually used, avoiding a misleading fallback that mapped non-numeric types to `ColType::Numeric`. Replace the non-atomic Windows rename (remove_file + rename) with a safer backup strategy: rename original to .bak, rename .tmp to target, then delete .bak — ensuring the original is recoverable if the process crashes mid-rename. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.