Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(zql): Implement OR #56

Merged
merged 4 commits into from
Apr 3, 2024
Merged

feat(zql): Implement OR #56

merged 4 commits into from
Apr 3, 2024

Conversation

arv
Copy link
Contributor

@arv arv commented Apr 2, 2024

This supersedes #52

OR is implemented by branching the graph when an OR expression is encountered. Each OR branch is executed "in parallel" and then merged together. The merging is done using concat and then distinct.

For example if we have:

SELECT * FROM table WHERE (a=1 OR b=1) AND (a=2 OR b=2)

We get something like:

  graph TD;
      Root-->id1;
      Root-->id2;
      id1(a=1) --> c1;
      id2(b=1) --> c1;
      c1(Concat) --> d1;
      d1(Distinct) --> id3;
      d1 --> id4;
      id3(a=2) --> c2;
      id4(b=2) --> c2;
      c2(Concat) --> d2;
      d2(Distinct)


Loading

arv added 2 commits April 2, 2024 17:26
Extending OperatorBase is more code than implementing the interface
directly.
It is no longer used
@arv
Copy link
Contributor Author

arv commented Apr 2, 2024

I have builder changes but that can be reviewed in isolation.

@arv arv requested a review from tantaman April 2, 2024 16:05
@tantaman
Copy link

tantaman commented Apr 2, 2024

img

Will review this tonight. Very cool :)

src/zql/ast-to-ivm/pipeline-builder.test.ts Outdated Show resolved Hide resolved
src/zql/ivm/graph/operators/concat-operator.test.ts Outdated Show resolved Hide resolved
src/zql/ivm/graph/operators/distinct-operator.ts Outdated Show resolved Hide resolved
src/zql/ivm/graph/operators/distinct-operator.ts Outdated Show resolved Hide resolved
This commit adds the ability to use `and` and `or` in the query API.
Typical usage would be:

```ts
q.where(
  or(
    and(
      expression('owner', '=', 'arv'),
      expression('priority', '=', 'high'),
    ),
    expression('status', '=', 'open'),
  ),
)
```

I think we want to design the surface API further but this unblocks us.

This commit also contains a few fixes:

- MutableTreeView was incorrectly telling the AbstractView not to call
  the listeners when it got an update that didn't change the view. But,
  with branches in the graph we can have multiple calls to `_newData`.
- With branches in the graph we the Source can get
  the same `PullMsg` more than once. Switch to a set to avoid this.
import * as agg from './query/agg.js';
import {EntityQuery, expression, or} from './query/entity-query.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wooo.

Nit: I think your earlier idea of exp was a better starting point.

@arv arv merged commit 766162a into main Apr 3, 2024
4 checks passed
@arv arv deleted the arv/zql-or2 branch April 3, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants