Repository navigation
fix(commands): reject duplicate column names in split column - #19362
Conversation
|
looks like your backslashes |
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
The duplicate check works on both the runtime and const paths, but clippy fails on two of the new lines, the const path has no test, and headers and from csv still build the same duplicate-key records.
Findings: 0
Open (9)
Helper placed after the test module fails clippy Raw string with no quotes inside fails clippy Therun_constpath has no test Other commands still build records with duplicate keys Column names that are never used now raise an error New helper has no doc comment Test does not check the spans One call insplit_columnwould replace both copies Fewer names than pieces still drops data without an error
Notes from my clanker, checked on 4265b61. Built the branch, ran cargo test -p nu-command --test tests -- split_column (5 passed) and clippy with CI's flags on nu-command (2 errors), and ran each case on the branch binary and on 0.116.2.
Thanks, I fixed it. |
|
When you're ready, make sure you comment on each review finding to make sure we didn't miss anything. |
|
still 1 remaining unresolved item |
|
The PR description has been updated with the release note for unused duplicate column names, and a test covering |
|
Thanks |
nushell#19362 added a ColumnDefinedTwice to split column after this branch was cut, so main no longer compiled against the new help field.
…ng data (#19595) ## Description Fixes #19537. `from csv` / `from tsv` with a repeated header name built a record with duplicate keys. Every later name-based lookup (`get`, `to csv`, table rendering) then resolved the name to the last entry, so the earlier column was silently lost: ```nu "name,name\nAlice,Bob" | from csv | to csv # name,name # Bob,Bob ``` This PR renames repeated header names in `from_delimited_stream` (shared by `from csv` and `from tsv`): each repeat gets a `_N` suffix (`name`, `name_1`, `name_2`, ...). The suffix skips any name the header row already uses, so a real `name_1` column keeps its name. Every column now loads: ```nu "name,name\nAlice,Bob" | from csv | to nuon # [[name, "name_1"]; [Alice, Bob]] ``` Blank header cells are now named by position (`column2`, `column3`, ...) before the rename, the same way `headers` names them, so files with several unlabeled columns still open. It also fixes a related case: with `--flexible`, the generated filler names (`columnN`) for extra fields could collide with a header that is already called e.g. `column2`. Filler names now skip names the header already uses. This is the narrow fix for the CSV/TSV path. The broader idea from the #19362 review (a checked push on `Record` or a shared helper in `nu-protocol`) is left as its own follow-up. ## User-facing changes (Release notes) - `from csv` and `from tsv` now rename repeated header names with a `_N` suffix (`name`, `name_1`, ...) instead of silently keeping only the last value. The suffix skips names the header row already uses. - With `--flexible`, generated `columnN` names for extra fields no longer collide with a header column of the same name. - Blank header cells in `from csv` and `from tsv` are now named by position (`column1`, `column2`, ...), the same way `headers` names them. Before, every blank cell was named `""`. ## Additional notes - Tests: new unit tests in `from/csv.rs` and `from/tsv.rs`; `cargo test -p nu-command --lib -- from::csv from::tsv` and `cargo test -p nu-command --test tests -- csv tsv open` pass; `cargo fmt --all -- --check` and `cargo clippy -p nu-command --all-targets -- -D warnings -D clippy::unwrap_used` are clean. - AI disclosure: the code was drafted with an AI coding agent (GLM-5.3 via OpenCode) and reviewed and tested by me; this description was also written with AI help. - Repeated headers were an error in the first version of this PR; switched to renaming after review. --------- Co-authored-by: Claude Opus 5.5 <[email protected]>



Description
Previously,
split columndid not validate that custom column names provided in the positionalrestarguments were unique. For instance:silently overwrote the earlier column, producing a record where data was silently dropped (
col: b).This PR adds duplicate column detection in
split columnfor bothrunandrun_const, returningShellError::ColumnDefinedTwiceand pointing out the exact spans of the first and second definitions.User-facing changes (Release notes)
split columnnow rejects duplicate column names with acolumn_defined_twiceerror pointing at both uses, instead of silently overwriting the earlier column.Tests + Formatting
crates/nu-command/tests/commands/split_column.rs:split_column_duplicate_column_error(including unused duplicate names)split_column_duplicate_column_const_errorcargo test -p nu-command --test tests split_column(all passed).cargo fmt --check.