zed
zed copied to clipboard
Bare searches for complex values
Repro is with zq
commit 45ac6b4.
Searches for complex literals in named fields can work ok (though #5167 shows some challenges here).
$ zq -version
Version: v1.16.0-6-gf4970799
$ echo '{"foo": [2,4,6]}' | zq -z 'search foo==[2,4,6]' -
{foo:[2,4,6]}
But if I attempt to search for that same array "bare" as an unnamed complex value, it's a parse error.
$ echo '{"foo": [2,4,6]}' | zq -z 'search [2,4,6]' -
zq: error parsing Zed at line 1, column 15:
search [2,4,6]
=== ^ ===
I mentioned it to @mccanne and he offered the following take:
It’s a bit tricky since complex constants are actually expressions so you are searching for a value that is computed from the value. e..g, should this search work?
{a:b+c}
for this data…
{b:1,c:2,r:{a:3}}
My inclination is that searches for complex values should require them to be constants.
Note: When this issue was originally opened, the language was at a different point in its evolution such that a program consisting of just a "bare" complex value like [2,4,6]
would be treated as a search. However, ever since the changes in #3620, that's now treated as an implied yield
of that value, e.g.:
$ zq -version
Version: v0.33.0-203-g33d674db
$ echo '{"foo": [2,4,6]}' | zq -z '[2,4,6]' -
[2,4,6]
This is why the explicit search
is now included in the repro steps for this issue.