Improve CellPath display output#14197
Improve CellPath display output#14197fdncred merged 2 commits intonushell:mainfrom aionescu:cell-path-display
CellPath display output#14197Conversation
|
Started this as a draft because there's some details to iron out (CC @fdncred @sholderbach):
|
I think we should have a separate function generating the
Here's the line where it naively tries to turn a
Yeah but we have a silent conversion to nushell/crates/nu-protocol/src/value/from_value.rs Lines 582 to 595 in 2c31b3d I am suspicious of those coercions #14147 |
Good point. I added a new method
Yeah, that looks naive indeed :) So basically For now, I just replaced that Also, a side-effect of this PR is that more strings are quoted by > [...] | to nuon # old
[...]
> [...] | to nuon # new
["..."]
> "..." | to nuon # unchanged, outside structures it was quoted anyway
"..."I personally like this (as it's more consistent between inside & outside structures), but I'm not sure if that's the intended output of |
sholderbach
left a comment
There was a problem hiding this comment.
Thanks for implementing that!
Not sure how the internals of flatten actually behave without digging into it.
Some folks want(ed) to make NUON way more parsimonous with characters than it is sane to read ^^
I personally would be fine with us disallowing the . for the existence of ranges and the spread operator alone.
| s += &val.to_string(); | ||
| } | ||
| PathMember::String { val, .. } => { | ||
| s += val; |
There was a problem hiding this comment.
Here we still need quotes around number-like columns otherwise they will become indistinguishable from rows.
There was a problem hiding this comment.
Yeah, but is that a problem in this situation? Since all the column names get crammed into a string anyway, I think it's easier for users to not quote indexes, e.g. get 'a."0".x' vs get 'a.0.x'
There was a problem hiding this comment.
0- PathMember::Int -> row
"0" - PathMember::String -> column
It would be impossible to determine the meaning of something like
let confusing = [{"0": bla, "1": blub}, {"0": foo, "1": bar}]
let cellp = $.0."1"
print $cellp
$confusing | select $cellpThere was a problem hiding this comment.
There was a problem hiding this comment.
I'm not following? Rows should be ints and Columns should be strings. Are we talking about changing that? If so, in what way?
In the example above $cellp should return blub, correct? Not sure why it doesn't.
Seems like $confusing | get $cellp works but $confusing | select $cellp doesn't. That should be fixed IMO.
There was a problem hiding this comment.
Seems like
$confusing | get $cellpworks but$confusing | select $cellpdoesn't.
That's because select doesn't let you mix rows and columns in a single cell-path (see this check).
And I think this actually makes the point raised by @sholderbach not a problem, because the column names produced by select will never contain row indices. e.g. if select produces a column a.0.b, that 0 came from a pre-existing column name, so there's no point quoting it?
There was a problem hiding this comment.
Just my opinion, but I like the way get works, as far as following cell paths, better than how select works right now. I like the flexibility of being able to do get 0.a or get a.0 and getting the same result.
|
|
||
| for (column_index, (column, value)) in val.into_owned().into_iter().enumerate() { | ||
| let column_requested = columns.iter().find(|c| c.to_string() == column); | ||
| let column_requested = columns.iter().find(|c| c.to_column_name() == column); |
There was a problem hiding this comment.
Is flatten accepting a nested cell path semantically or only a single column level?
There was a problem hiding this comment.
It only accepts a single (string) column name, and trying to pass it a cell-path results in an error. (Sorry, I was thinking of select).
Yes, flatten accepts a nested cell-path semantically, but as a string (e.g. "a.b" not $.a.b).
There was a problem hiding this comment.
Ah OK, otherwise we could have moved away from using CellPath internally to something more explicit as just a string.
| run_test( | ||
| r#"let a = 4; [... $a ... [1] ... (5) ...bare ...] | to nuon"#, | ||
| "[..., 4, ..., [1], ..., 5, ...bare, ...]", | ||
| r#"["...", 4, "...", [1], "...", 5, "...bare", "..."]"#, |
There was a problem hiding this comment.
That run_test kind of escapes the meaning of that old test and is more one for the nuon sanity checks right?
|
IMO it's ready, but we should wait for @sholderbach's opinion. |
|
We can land this and rework the last bug source #14197 (comment) later if we don't want to entertain the breakage during development. |
|
ok, let's do that. i'll land this and close my revert. thanks! |
|
marking this as a "breaking change" as it broke the CI of Nupm
|
|
@amtoine |
|
i have been distracted by some other stuff tonight but a fix for Nupm is in preparation, hopefully it's not too bad, should just be a matter of getting the new hashes 😉 and it was not to suggest reverting this PR, no worries 😋 |
Description
Fixes: #13362
This PR fixes the
Displayimpl forCellPath, as laid out in #13362 and #14090:User-Facing Changes
Cell-paths are now printed using the same
$.notation that is used to create them, and ambiguous column names are properly quoted.Tests + Formatting
After Submitting