Skip to content

where implicitly coerces records to tables instead of returning the record (if condition is true) #6764

Closed as not planned

Description

@webbedspace

Describe the bug

When piped a record, and if the condition is true regarding the record, where will NOT return the record, but a table of it.

How to reproduce

See example:

〉{A:1,B:2}
╭───┬───╮
│ A │ 1 │
│ B │ 2 │
╰───┴───╯
〉{A:1,B:2} | where A == 1
╭───┬───┬───╮
│ # │ A │ B │
├───┼───┼───┤
│ 0 │ 1 │ 2 │
╰───┴───┴───╯

Expected behavior

I understand the type signature of where is a little dicey at the moment, but there is one principle I think it should uphold: not type-coercing the data like 90s JavaScript. As such, I think its current behaviour regarding JSON-style records is rather unpleasant. I expect where to filter data, not transform it.

Screenshots

No response

Configuration

key value
version 0.69.1
branch
commit_hash 8a5abc7
build_os windows-x86_64
build_target x86_64-pc-windows-msvc
rust_version rustc 1.64.0 (a55dd71d5 2022-09-19)
rust_channel stable-x86_64-pc-windows-msvc
cargo_version cargo 1.64.0 (387270bc7 2022-09-16)
pkg_version 0.69.1
build_time 2022-09-28 02:58:08 +00:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins

Additional context

No response

Activity

  1. fdncred commented on Oct 16, 2022

    @fdncred
    Contributor

    Thanks. I think this is a good point. One would think this wouldn't be too tricky to change. Oh, and is also looks like it doesn't even work with records, otherwise it would only have the A == 1 result I think.

    It's looking like the eval_block isn't working on records so maybe this needs some design? It would be nice to have more record tools/commands.

  2. added
    category:inconsistent-behavior
    on Oct 16, 2022
  3. webbedspace commented on Oct 16, 2022

    @webbedspace
    ContributorAuthor

    I believe that where selects rows, and records are functionally "one-row tables", so I believe {A:1,B:2} | where A == 1 actually works correctly - i.e. it lets the record pass if it has A:1, and produces an empty something-or-other if it doesn't.

  4. rgwood commented on Oct 24, 2022

    @rgwood
    Contributor

    Hmm. I kind of think that this should return an error. IMO a collection/list of values is the only input that makes sense for where;
    I'm a little scared by the idea of treating single values like 1-element lists.

  5. webbedspace commented on Oct 24, 2022

    @webbedspace
    ContributorAuthor

    I see what you mean… that only [{A:1,B:2}] | where A == 1 should be considered valid use? Because that explicitly states that the row is part of a list? Hmm.

    In that case, this issue is still valid, but the expected behaviour should be an error.

  6. webbedspace commented on Oct 29, 2022

    @webbedspace
    ContributorAuthor

    I've decided to continue this in a different issue now that I more fully understand the problem and what the solution should be.

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

    category:inconsistent-behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions