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
A strict reading of the over operator docs indicates the following record should probably be output as is, but instead its top level is broken out into a key and value pairing.
all other values generate a single value equal to itself.
Noted! Then it goes on to:
Records can be converted to maps with the flatten function resulting in a map that can be traversed, e.g., if this is a record, it can be traversed with over flatten(this).
Putting aside the questionable use of the word "map" here, that also checks out. The path through the hierarchical layers of the record are reflected in the array elements ["a","b","c"]. ✅
But what happens if over is attempted on a record without using flatten? As a user, my assumption was that this would probably be subject to the "generate a single value equal to itself", but it turns out that's not the case. Instead it unwraps the top level of the record hierarchy into a key and puts the remaining levels of the record in a value:
My reason for wanting to do this was that I wanted to operate on a hierarchical record in a lateral expression and hence wanted it to pass through over undisturbed. I realized I could get what I want by temporarily treating my record as the single element of an array:
But I hesitate at the thought of showing this in docs as if it's the preferred guidance to users. Indeed, when I shared all of this in a group discussion, the reaction was that the unwrapping of the top level was unexpected, so this should be revisited at some point.
The text was updated successfully, but these errors were encountered:
tl;dr
A strict reading of the
over
operator docs indicates the following record should probably be output as is, but instead its top level is broken out into akey
andvalue
pairing.Details
Repro is with Zed commit 21b7168.
Walking through the
over
docs, here's how the bullets sayover <expr>
handles different data types:Checks out. ✅
Checks out. ✅
Noted! Then it goes on to:
Putting aside the questionable use of the word "map" here, that also checks out. The path through the hierarchical layers of the record are reflected in the array elements
["a","b","c"]
. ✅But what happens if
over
is attempted on a record without usingflatten
? As a user, my assumption was that this would probably be subject to the "generate a single value equal to itself", but it turns out that's not the case. Instead it unwraps the top level of the record hierarchy into akey
and puts the remaining levels of the record in avalue
:My reason for wanting to do this was that I wanted to operate on a hierarchical record in a lateral expression and hence wanted it to pass through
over
undisturbed. I realized I could get what I want by temporarily treating my record as the single element of an array:But I hesitate at the thought of showing this in docs as if it's the preferred guidance to users. Indeed, when I shared all of this in a group discussion, the reaction was that the unwrapping of the top level was unexpected, so this should be revisited at some point.
The text was updated successfully, but these errors were encountered: