zed icon indicating copy to clipboard operation
zed copied to clipboard

inconsistency between docs and code regarding "not" in expressions

Open nwt opened this issue 3 years ago • 1 comments

This issue was pointed out by a community member in a Slack thread.

The docs say not true is a valid expression:
https://github.com/brimdata/zed/blob/3b24a114cabc32c5a306defd7f582ba967d43786/docs/language/overview.md#L861-L868

But the parser says it isn't (though ! true, which isn't documented, is):
https://github.com/brimdata/zed/blob/3b24a114cabc32c5a306defd7f582ba967d43786/compiler/parser/parser.peg#L683-L687

What we should do:

  • [ ] Update the versioned docs in https://github.com/brimdata/zed-docs-site/tree/main/versioned_docs/ so they're accurate
  • [ ] Decide what we want in the language
  • [ ] Update docs and code to reflect that

nwt avatar Jul 15 '22 17:07 nwt

Community member @henridf also stumbled across this. In his own words:

I was trying to do a filter on something not in a list, and based on the docs, it looked like I should use not, but that’s resulting in syntax errors, and I randomly tried ! and that finally worked: where !( id in [1,2])

philrz avatar Jul 24 '22 23:07 philrz

I've noticed https://github.com/brimdata/zed/issues/2070 is effectively a duplicate of this, so I'm closing that one. Capturing @mccanne's original wording from there:

Currently, search can use "not" or "!" but expr can use only "!". This should be unified.

philrz avatar Aug 16 '23 20:08 philrz

A community user recently bumped in to a variation on this in a Slack thread:

Mmm I think I'm missing something obvious, what's the best way to where not status in ['inactive']

I ultimately offered the following:

$ cat data.zson 
{status: "active", num: 1}
{status: "inactive", num: 2}
{status: "ready", num: 3}

$ zq -version
Version: v1.9.0-10-g08fc271c

$ cat data.zson | zq 'where ! (status in ["active", "ready"])' -
{status:"inactive",num:2}

However, when working my way up to that, I was reminded of some of the subtleties described in this issue, e.g., this does not work:

$ cat data.zson | zq 'where not (status in ["active", "ready"])' -
zq: error parsing Zed at column 11:
where not (status in ["active", "ready"])
      === ^ ===

philrz avatar Sep 02 '23 19:09 philrz

Verified in Zed commit d55ca74.

Revisiting the comments from when this issue was opened, not true is now a valid expression whereas it wasn't before.

$ zq -version
Version: v1.9.0-25-gd55ca742

$ zq 'yield not true'
false

Similarly, the example shown by @henridf above now works with not where it didn't before.

$ echo '{id:1}{id:2}{id:3}' | zq -z 'where not (id in [1,2])' -
{id:3}

Also true for the community issue described in the comment above.

$ cat data.zson | zq 'where not (status in ["active", "ready"])' -
{status:"inactive",num:2}

The linked PR included the docs updates at https://zed.brimdata.io/docs/next/language/expressions#logic and https://zed.brimdata.io/docs/next/language/search-expressions#boolean-logic as well. The way things are now, I do find the remaining inconsistency of offering both not and ! a little strange, so I've opened #4782 as a reminder that we might revisit that topic in the future. But that doesn't seem at all urgent.

Thanks @mattnibs!

philrz avatar Sep 26 '23 19:09 philrz