Skip to content

Commit

Permalink
Fix select cell path renaming behavior (nushell#13361)
Browse files Browse the repository at this point in the history
# Description

Fixes nushell#13359

In an attempt to generate names for flat columns resulting from a nested
accesses nushell#3016 generated new column names on nested selection, out of
convenience, that composed the cell path as a string (including `.`) and
then simply replaced all `.` with `_`. As we permit `.` in column names
as long as you quote this surprisingly alters `select`ed columns.


# User-Facing Changes
New columns generated by selection with nested cell paths will for now
be named with a string containing the keys separated by `.` instead of
`_`. We may want to reconsider the semantics for nested access.

# Tests + Formatting
- Alter test to breaking change on nested `select`
  • Loading branch information
sholderbach authored Jul 13, 2024
1 parent b0bf546 commit f5bff8c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions crates/nu-command/src/filters/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fn select(
//FIXME: improve implementation to not clone
match input_val.clone().follow_cell_path(&path.members, false) {
Ok(fetcher) => {
record.push(path.to_string().replace('.', "_"), fetcher);
record.push(path.to_string(), fetcher);
if !columns_with_value.contains(&path) {
columns_with_value.push(path);
}
Expand Down Expand Up @@ -271,7 +271,7 @@ fn select(
// FIXME: remove clone
match v.clone().follow_cell_path(&cell_path.members, false) {
Ok(result) => {
record.push(cell_path.to_string().replace('.', "_"), result);
record.push(cell_path.to_string(), result);
}
Err(e) => return Err(e),
}
Expand All @@ -295,7 +295,7 @@ fn select(
//FIXME: improve implementation to not clone
match x.clone().follow_cell_path(&path.members, false) {
Ok(value) => {
record.push(path.to_string().replace('.', "_"), value);
record.push(path.to_string(), value);
}
Err(e) => return Err(e),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/tests/commands/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn complex_nested_columns() {
r#"
{sample}
| select nu."0xATYKARNU" nu.committers.name nu.releases.version
| get nu_releases_version
| get "nu.releases.version"
| where $it > "0.8"
| get 0
"#
Expand Down

0 comments on commit f5bff8c

Please sign in to comment.