Skip to content

When where return an empty table, sort-by should still work, or: columns names should not be stripped by filters #5957

Closed

Description

@poliorcetics

Describe the bug

The example below should return an empty table, never crash on a no values to work with

How to reproduce

Run in a folder with small files only:

mkdir /tmp/where-sort-by-crash
cd /tmp/where-sort-by-crash
touch file1
echo "file2" | save file2
ls -la | where size > 2Gb | sort-by name

Gives:

Error: 
  × no values to work with
  help: no values to work with

Expected behavior

This doesn't crash and return an empty table

Screenshots

No response

Configuration

key value
version 0.64.0
branch
commit_hash
build_os macos-aarch64
build_target aarch64-apple-darwin
rust_version rustc 1.61.0 (fe5b13d68 2022-05-18)
rust_channel stable-aarch64-apple-darwin
cargo_version cargo 1.61.0 (a028ae42f 2022-04-29)
pkg_version 0.64.0
build_time 2022-06-15 09:42:32 +02:00
build_rust_channel release
features default, trash, which, zip
installed_plugins

Additional context

No response

Activity

  1. added
    status:needs-design
    on Jul 6, 2022
  2. sholderbach commented on Jul 6, 2022

    @sholderbach
    Member

    That is currently incompatible with the underlying data model. A regular nushell table under the hood is a list of records. This has some nice properties, like that we don't have to do much work ingesting data with potentially any type. But as soon as the list doesn't contain any records, there is nothing defining the columns.

    This might favor having an explicit nu Value::Table type. https://docs.rs/nu-protocol/latest/nu_protocol/enum.Value.html. This may move some checking and missing value handling to the creation time of this table but would be able to have columns with zero rows.

    For typed columnar data we currently have the dataframe support. This has the requirement that all values in a column share the same primitive type but allows for much more efficient computations/aggregations. The operations are currently moved over to feel like regular nushell operations but you have to explicitly convert something to a dataframe for them to work.

  3. olivia-fl commented on Mar 29, 2023

    @olivia-fl
    Contributor

    One possible alternative is to have sort-by work transparently with empty lists. So ([] | sort-by foo) == []. Several other commands that operate on columns already work this way (select, get, rename, where, etc).

    Having an explicit Value:: Table is a really thorny design problem, but I don't think it's necessary in order to solve 90% of the cases with this type of issue.

    I could make a PR to change the behavior of sort-by if that sounds good?

  4. sholderbach commented on Mar 30, 2023

    @sholderbach
    Member

    Closed by #8669

  5. added this to the v0.78.0 milestone on Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:needs-design

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions