You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cell paths: foo.1 is not always equal to 1.foo #7498
Run [ { foo: "bar"}, { } ] | get foo.1, it returns Nothing
Run [ { foo: "bar"}, { } ] | get 1.foo, it fails with a ShellError
Expected behavior
If a cell path has 2 members and one member is a number but the other is a column name, the order of those members should not matter. I'm not sure exactly what the behaviour should be here, but I do think it's desirable for the behaviour to be consistent.
I lean toward making both return a ShellError, but I'm not sure if there are some situations where that would be problematic (dealing with JSON files maybe?). Please chime in if you have an opinion or are aware of important scenarios we should be considering.
What we really should have is nullable paths like foo.0? or a.b?.c (semantics the same as other languages that have it, like Javascript - a.b? turns into null and ignores the rest of the path if b doesn't exit). That way, stuff like this can be a ShellError by default but null if you'd prefer it that way.
I've been reconsidering the original example closely:
Run [ { foo: "bar"}, { } ] | get foo.1, it returns Nothing
Run [ { foo: "bar"}, { } ] | get 1.foo, it fails with a ShellError
Because tables are "actually" lists, 1.foo correctly retrieves { } from it. The .1 access then errors.
But what get foo does is produce a list of each value's foo property.
And here's the kicker: if it cannot retrieve that property, it defaults to null.
Importantly, this is different to how select works.
The fact that this works differently for select makes me think that it should just be a ShellError.
Are you saying that get foo should behave like select and return a ShellError if any record in the list does not have a foo column? If so I agree - select and get should be consistent in their behaviour.
Activity
webbedspace commentedon Dec 16, 2022
What we really should have is nullable paths like
foo.0?ora.b?.c(semantics the same as other languages that have it, like Javascript -a.b?turns intonulland ignores the rest of the path ifbdoesn't exit). That way, stuff like this can be a ShellError by default butnullif you'd prefer it that way.rgwood commentedon Dec 18, 2022
Agreed. I think I might know how to implement optional chaining like that in Nu, I'm going to do some experiments this week.
Revert "into cellpath command (#7417)" (#7523)
webbedspace commentedon Jan 1, 2023
I've been reconsidering the original example closely:
Because tables are "actually" lists, 1.foo correctly retrieves
{ }from it. The.1access then errors.But what
get foodoes is produce a list of each value'sfooproperty.And here's the kicker: if it cannot retrieve that property, it defaults to
null.Importantly, this is different to how
selectworks.The fact that this works differently for
selectmakes me think that it should just be aShellError.rgwood commentedon Jan 1, 2023
Are you saying that
get fooshould behave likeselectand return aShellErrorif any record in the list does not have afoocolumn? If so I agree -selectandgetshould be consistent in their behaviour.On a related note, #7002 attempted to address this but I don't think it got things quite right;
get foonow behaves differently from.foo:Make `get` hole errors and cell path hole errors identical (improveme…