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
However, if I try what I think is the equivalent with strings and grep(), I no longer see the field name one in the output.
$ echo '{x:"one is a bun"} {x:"two is a shoe"}' | zq -Z 'this[grep(one*, x) ? "one" : "two"]:=x' -
{
x: "one is a bun",
two: "one is a bun"
}
{
x: "two is a shoe",
two: "two is a shoe"
}
It feels like it should work the same since grep() is supposed to return a boolean. And it does what I expect if I yield the result of the conditional on its own or launder the field name through an intermediate value.
$ echo '{x:"one is a bun"} {x:"two is a shoe"}' | zq -Z 'yield grep(one*, x) ? "one" : "two"' -
"one"
"two"
$ echo '{x:"one is a bun"} {x:"two is a shoe"}' | zq -Z '_fieldname := grep(one*, x) ? "one" : "two" | this[_fieldname] := x | drop _fieldname' -
{
x: "one is a bun",
one: "one is a bun"
}
{
x: "two is a shoe",
two: "two is a shoe"
}
$ echo '{x:"one is a bun"} {x:"two is a shoe"}' | zq -Z '_fieldname := grep(one*, x) ? "one" : "two" | this[_fieldname] := x | drop _fieldname' -
{
x: "one is a bun",
one: "one is a bun"
}
{
x: "two is a shoe",
two: "two is a shoe"
}
The text was updated successfully, but these errors were encountered:
tl;dr
The output from the following seems incorrect compared to when we compute each part separately and combine.
Details
Repro is with Zed commit d103420. I bumped into this while trying to write the Zed equivalent of the
CASE
logic in mgbench bench3/q6.The following uses a conditional in a record index expression and works as expected:
However, if I try what I think is the equivalent with strings and
grep()
, I no longer see the field nameone
in the output.It feels like it should work the same since
grep()
is supposed to return a boolean. And it does what I expect if Iyield
the result of the conditional on its own or launder the field name through an intermediate value.The text was updated successfully, but these errors were encountered: