Repository navigation
Refactor Value cell path functions to fix bugs - #11066
Conversation
|
Nushell has always had problem with updating deeply nested data. I'm hopeful this will fix that, or at least be one good step to fixing it. Thanks! I'm always excited to see your PRs!!! |
sholderbach
left a comment
There was a problem hiding this comment.
Thanks for tackling this!
Great to see more idiomatic rust, the nested insert/assignment etc.
Will mark this as a potentially breaking change as we might still run into some records with duplicated column names.
| } | ||
| }) { | ||
| current = found.1.clone(); | ||
| current = found.1.clone(); // TODO: avoid clone here |
There was a problem hiding this comment.
Is .into_iter() not an option here?
The existing code is still defensive around finding more than one entry with the same column name. in the future we can probably replace that all with Record::remove()
Edit: As the upsert/update logic makes the assumptions that the first hit is the true hit, you could go for that and we see what starts to burn 😆
There was a problem hiding this comment.
Unfortunately, the records columns are used below in did_you_mean(val.columns(), column_name), so we can't use into_iter here without cloning.
There was a problem hiding this comment.
Ah then an if let Some(val) = record.remove(col) magic could be the workaround, right?
There was a problem hiding this comment.
There's a predicate for the case insensitivity. So, maybe index_of followed by swap_remove?
There was a problem hiding this comment.
Grr sloppy insensitive. In my view that should have no business in any cell-path access but I digress.
Yeah sounds good. Adding remove_index/swap_remove_index to record should be trivial.
| ) -> Result<(), ShellError> { | ||
| match cell_path.first() { | ||
| Some(path_member) => match path_member { | ||
| if let Some((member, path)) = cell_path.split_first() { |
| } | ||
| _ => { | ||
| let path_member = cell_path.first().expect("there is a first"); | ||
| [member, path @ ..] => { |
There was a problem hiding this comment.
Chef's kiss! Love how this is both explicit and gets rid of a bunch of triple checking
There was a problem hiding this comment.
Pattern matching is too powerful! 😄
|
Seems like some of these new things work but this one doesn't. Not sure if that is expected or a bug? ❯ {z: 0} | insert z.z 0
Error: nu::shell::unsupported_input
× Unsupported input
╭─[entry #7:1:1]
1 │ {z: 0} | insert z.z 0
· ───┬── ┬
· │ ╰── input type: Int
· ╰── table or record
╰──── |
|
this was one of the examples of the issue that has been closed as completed 😮 |
|
The |
# Description
Slightly refactors the cell path functions (`insert_data_at_cell_path`,
etc.) for `Value` to fix a few bugs and ensure consistent behavior.
Namely, case (in)sensitivity now applies to lazy records just like it
does for regular `Records`. Also, the insert behavior of `insert` and
`upsert` now match, alongside fixing a few related bugs described below.
Otherwise, a few places were changed to use the `Record` API.
# Tests
Added tests for two bugs:
- `{a: {}} | insert a.b.c 0`: before this PR, doesn't create the
innermost record `c`.
- `{table: [[col]; [{a: 1}], [{a: 1}]]} | insert table.col.b 2`: before
this PR, doesn't add the field `b: 2` to each row.
# Description
Slightly refactors the cell path functions (`insert_data_at_cell_path`,
etc.) for `Value` to fix a few bugs and ensure consistent behavior.
Namely, case (in)sensitivity now applies to lazy records just like it
does for regular `Records`. Also, the insert behavior of `insert` and
`upsert` now match, alongside fixing a few related bugs described below.
Otherwise, a few places were changed to use the `Record` API.
# Tests
Added tests for two bugs:
- `{a: {}} | insert a.b.c 0`: before this PR, doesn't create the
innermost record `c`.
- `{table: [[col]; [{a: 1}], [{a: 1}]]} | insert table.col.b 2`: before
this PR, doesn't add the field `b: 2` to each row.
Description
Slightly refactors the cell path functions (
insert_data_at_cell_path, etc.) forValueto fix a few bugs and ensure consistent behavior. Namely, case (in)sensitivity now applies to lazy records just like it does for regularRecords. Also, the insert behavior ofinsertandupsertnow match, alongside fixing a few related bugs described below. Otherwise, a few places were changed to use theRecordAPI.Tests
Added tests for two bugs:
{a: {}} | insert a.b.c 0: before this PR, doesn't create the innermost recordc.{table: [[col]; [{a: 1}], [{a: 1}]]} | insert table.col.b 2: before this PR, doesn't add the fieldb: 2to each row.