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
where implicitly coerces records to tables instead of returning the record (if condition is true) #6764
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.
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.
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.
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.
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.
Activity
fdncred commentedon Oct 16, 2022
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_blockisn't working on records so maybe this needs some design? It would be nice to have more record tools/commands.webbedspace commentedon Oct 16, 2022
I believe that
whereselects rows, and records are functionally "one-row tables", so I believe{A:1,B:2} | where A == 1actually 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.rgwood commentedon Oct 24, 2022
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.
webbedspace commentedon Oct 24, 2022
I see what you mean… that only
[{A:1,B:2}] | where A == 1should 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.
webbedspace commentedon Oct 29, 2022
I've decided to continue this in a different issue now that I more fully understand the problem and what the solution should be.