Skip to content

rename silently creates columns with non-unique names #11020

Closed

Description

@sholderbach

Describe the bug

rename currently still allows you to create records (and thus tables) where a column name appears more than once.

The display through table will display only the last column for a table but will show all elements with the same key for a record.

How to reproduce

ls | rename a a a a

OR

ls | rename --column {name: a, type: a, size: a, modified: a}
╭─#──┬──────a───────╮
│ 0  │ a year ago   │
│ 1  │ 3 weeks ago  │
│ 2  │ an hour ago  │
│ 3  │ a day ago    │

and then to see that the record kept all columns

ls | rename a a a a | get 0
╭───┬────────────────────╮
│ a │ CODE_OF_CONDUCT.md │
│ a │ file               │
│ a │ 3.4 KB             │
│ a │ a year ago         │
╰───┴────────────────────╯

For extra fun:

ls | rename --block { "a" }

Expected behavior

Records and tables should have unique column names so they can be cleanly addressed by cell paths and internal operations can make safe assumptions about the column names.

Open for debate:

Should rename always error either up front or when trying to write the new record:

e.g. having hetoregeneous record that should be converted to a common schema:

[
  {last_name: "Curie"},
  {surname: "Lovelace"},
  {family_name: "Hopper"},
] | rename --columns {surname: last_name, family_name: last_name}  

Also we could have modes that allow you to either keep the first or last column getting assigned the non-unique name. (This may be of concern for the closure case)
Another option would be to implicitly add a suffix following a particular schema.

Configuration

key value
version 0.86.0
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.71.1 (eb26296b5 2023-08-03)
rust_channel 1.71.1-x86_64-unknown-linux-gnu
cargo_version cargo 1.71.1 (7f1d04c00 2023-07-29)
build_time 2023-10-18 13:38:18 +02:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash, which, zip
installed_plugins

Activity

  1. added
    status:needs-design
    semantics
    on Nov 10, 2023
  2. IanManske commented on Nov 10, 2023

    @IanManske
    Member

    Looking over the other commands, I think headers also has this problem.

  3. amtoine commented on Nov 10, 2023

    @amtoine
    Member

    my two cents: it should always throw an error rather than assume things and do things silently on behalf of the user 🤔

    otherwise it looks like Python doing conversions all over the place for you so that you get the least amount of errors...
    i like errors 😋

  4. sholderbach commented on Nov 13, 2023

    @sholderbach
    MemberAuthor

    @amtoine erroring ahead of time or when the specific rename causes a problem?
    See the example using the latter behavior.

    We practically have to implement something to error out at run time so we can deal with the closure case.

  5. amtoine commented on Nov 13, 2023

    @amtoine
    Member

    erroring ahead of time or when the specific rename causes a problem?
    See the example using the latter behavior.

    We practically have to implement something to error out at run time so we can deal with the closure case.

    i'd say, if we know the shape of the data at parse-time, e.g. ls is a table<name: string, type: string, size: filesize, modified: date>, we now at parse-time that rename a a or rename {name: a, size: a} does not make sense and it probably a mistake => it should error out at parse-time imo

    when we either don't know the shape of the input data or rename operated on a closure, then an error at runtime could be the only thing we can do, right? 🤔

    See the example using the latter behavior.

    do you mean this?

    [
      {last_name: "Curie"},
      {surname: "Lovelace"},
      {family_name: "Hopper"},
    ] | rename --columns {surname: last_name, family_name: last_name}  

    i'm not even sure what to expect there, merging the $.surname and $.family_name columns?

    Another option would be to implicitly add a suffix following a particular schema.

    not a fan of that

  6. added
    category:bug
    on Mar 28, 2024
  7. added
    A:error-silent-fail
    on Aug 16, 2024
  8. kronberger-droid commented on Nov 14, 2026

    @kronberger-droid
    Contributor

    rename refuses duplicate names since #19196.
    headers still creates them on 0.117: [[a b]; [x x] [1 2]] | headers | to nuon gives [{x: 1, x: 2}].

  9. added a commit that references this issue on Nov 20, 2026
    18424af
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-silent-failcategory:bugsemanticsstatus:needs-design

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions