Skip to content

fix(commands): reject duplicate column names in split column - #19362

Merged
fdncred merged 3 commits into
nushell:mainfrom
patatoish:fix/split-column-duplicate-names
Oct 28, 2026
Merged

fdncred merged 3 commits into
nushell:mainfrom
patatoish:fix/split-column-duplicate-names

Conversation

@patatoish

@patatoish patatoish commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Previously, split column did not validate that custom column names provided in the positional rest arguments were unique. For instance:

'a-b' | split column '-' col col

silently overwrote the earlier column, producing a record where data was silently dropped (col: b).

This PR adds duplicate column detection in split column for both run and run_const, returning ShellError::ColumnDefinedTwice and pointing out the exact spans of the first and second definitions.

User-facing changes (Release notes)

split column now rejects duplicate column names with a column_defined_twice error pointing at both uses, instead of silently overwriting the earlier column.

Tests + Formatting

  • Added integration tests in crates/nu-command/tests/commands/split_column.rs:
    • split_column_duplicate_column_error (including unused duplicate names)
    • split_column_duplicate_column_const_error
  • Ran cargo test -p nu-command --test tests split_column (all passed).
  • Checked formatting with cargo fmt --check.

@fdncred

fdncred commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

looks like your backslashes \ need to be replace with backticks `

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity · 3 Medium severity · 6 Low severity

Open (9)

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.

@patatoish

Copy link
Copy Markdown
Contributor Author

looks like your backslashes \ need to be replace with backticks `

Thanks, I fixed it.

@fdncred

fdncred commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

When you're ready, make sure you comment on each review finding to make sure we didn't miss anything.

@patatoish
patatoish requested a review from fdncred October 28, 2026 13:59
@fdncred

fdncred commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

still 1 remaining unresolved item

@patatoish

Copy link
Copy Markdown
Contributor Author

The PR description has been updated with the release note for unused duplicate column names, and a test covering 'a' | split column '-' x x was added in commit 8f62cad.

@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Oct 28, 2026
@fdncred
fdncred merged commit 06e65cd into nushell:main Oct 28, 2026
11 checks passed
@fdncred

fdncred commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.117.0 milestone Oct 28, 2026
mvanhorn added a commit to mvanhorn/nushell that referenced this pull request Oct 30, 2026
nushell#19362 added a ColumnDefinedTwice to split column after this branch was
cut, so main no longer compiled against the new help field.
fdncred pushed a commit that referenced this pull request Nov 18, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants