Repository navigation
compact: accept cell paths for column arguments - #19624
Merged
Merged
Conversation
added 4 commits
November 20, 2026 22:31
compact read its column arguments as literal top-level names, so a nested path like labels.c looked up a key named "labels.c" and dropped every row. The arguments are now cell paths, the same change made to default. The example for a nested null is added.
Covers a nested path that keeps and drops rows, --empty on a nested value, a missing nested path, several paths at once, a top-level column as a regression guard, and a quoted dotted name that still matches the literal key.
A plain column name is one record lookup. Only multi-member and nested paths still walk follow_cell_path. Missing columns and optional misses still drop the row, as before. Timed debug builds on 200k rows: compact a 211 -> 133 ms, compact a id s 337 -> 181 ms, same as main.
Pins that an optional nested member drops rows where it is missing or null, and that an int cell path leaves list rows unchanged.
fdncred
reviewed
Nov 20, 2026
Contributor
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
compact labels.c now follows the nested path. Plain names, quoted dotted names, typed string params and spread string lists all behave as they do on main. What's left: a bare number now empties a table of records with no error, plus two small notes.
Findings: 1
Open (3)
Notes from my clanker, checked on b4611fb. Built the branch, ran cargo test -p nu-command --test tests -- commands::compact (15 passed), and ran each case on the branch binary and on main (ca70639). CI's macOS and Windows lint jobs passed on this head, so I didn't rerun clippy.
added 2 commits
November 21, 2026 01:12
A bare number such as `compact 2024` parsed as a row index, so on record rows the lookup failed and every row was dropped with no error. Main errored here with "can't convert int to string". It now errors with a hint to quote the name. A number later in the path (`compact a.0`) still works. Replaces the list-row test with rejection tests and adds quoted-number and nested-index cases. Without the check, int_cell_path_is_rejected and number_column_is_rejected fail (16/18); with it, 18/18.
The do_keep closure had one caller left.
Contributor
|
Thanks |
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.



Description
Fixes #4274.
compactread its column arguments as plain strings, so a nested path was looked up as one literal key and every row was dropped:[{labels: {c: 1}} {labels: {c: null}}] | compact labels.c # before: [] # after: [{labels: {c: 1}}]The column arguments are now cell paths, the same change
defaultgot in #19058, socompactanddefaultread columns the same way:compact a.bfollows the nested path;--emptyapplies to the nested value too ([{a: {b: ""}} {a: {b: x}}] | compact -e a.bkeeps only the second row; main dropped both).compact a?.bdrops rows whereaorbis missing or null.compact 2024orcompact 0, is an error that asks for a quoted name (compact "2024"). Main also errored on these, with "can't convert int to string"; without the check a number would parse as a row index and silently drop every record row. A number later in the path (compact a.0) works.User-facing changes (Release notes)
compactaccepts cell paths:compact labels.cchecks the nested fieldcinsidelabelsinstead of a column literally namedlabels.c. To match a column whose name contains a.or ends in?or!, quote it:compact "a.b",compact "a?"(a quoted name or a string variable still matches the literal key). Unquoted,a?is an optional member anda!a case-insensitive one.Additional notes
crates/nu-command/tests/commands/compact.rs(nested path, nested with--empty, missing nested path, several paths, plain top-level column, quoted dotted name, optional path, a number as the first member rejected on list rows and on record rows, quoted number column, number later in the path) and anexamples()entry. The nested ones fail on main; the plain-column and quoted-name ones pin behaviour that did not change. The two rejection tests fail with the new check commented out.cargo test -p nu-command --test tests -- commands::compact(18 passed),cargo test -p nu-command --lib -- compact(5 passed),cargo fmt --all --checkandcargo clippy -p nu-command --all-targets -- -D warnings -D clippy::unwrap_usedare clean.timeitruns):compact a131 ms on main, 133 ms here;compact a id s178 ms on main, 181 ms here. The first version of this change walked every column withfollow_cell_pathand was about 1.5-2x slower, so a single plain name now goes straight torecord.getand only real paths walk.