nushell.github.io icon indicating copy to clipboard operation
nushell.github.io copied to clipboard

Document why `get` is strict and errors on blanks

Open sophiajt opened this issue 3 years ago • 1 comments

originally from https://github.com/nushell/nushell/issues/3193

sophiajt avatar Jul 07 '21 19:07 sophiajt

We may want to look into this deeper. get does need to be strict (it's not fully strict). I believe it is strict for rows that have missing columns. However, if all rows have the column of interest present and one of them is $nothing, get will happily ignore it.

This should error (but it's not):

> echo [[a]; [$nothing] [value]] | get a
value

the user should see the error showing up and fix like so:

> echo [[a]; [$nothing] [value]] | compact | get a
value
> echo [[a]; [$nothing] [value]] | default a some_value | get a
───┬────────────
 0 │ some_value
 1 │ value
───┴────────────

needs more investigation.

andrasio avatar Aug 26 '21 23:08 andrasio

I believe this can be closed. The current behavior is now documented in a combination of the nothing type and Navigating and Accessing Structured Data - Handling Missing Data, which is that;

  • A missing value is different than a null/nothing value
  • get will error on a missing value
  • get will not error when a result has a null
  • default can be used to convert both *missingandnothing` values to another value
  • The optional operator ? can be used to return a null in place of a missing value

NotTheDr01ds avatar Aug 19 '24 17:08 NotTheDr01ds