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

Restrict event references in windowed select queries and add 'emit_empty_windows` setting #828

Merged
merged 20 commits into from
Mar 17, 2021

Conversation

mfelsche
Copy link
Member

@mfelsche mfelsche commented Mar 11, 2021

Pull request

Description

  • Forbid references to event or $ in the select target expression (select --> event <-- from ...) if this is a select query with a window, because we cannot access a single event in the select target, in that context we operate on the whole window. A freestanding event reference has always been evaluating to the last event of the window, but we have aggr::win::last(...) for that, and since 0.10 it is possible to have windows without an event (for time based windows), where query execution would error out.
    • We allow those references inside aggregate functions and if they are used in the group by clause.
    • Example:
select {
  "ok": event.foo, // allowed because used in group by
  "ok2": aggr::win::first(event.timestamp), // allowed because in aggregation function
  "bad": event.snot + 2 // not allowed anymore
} from in[my_window]
group by set(event.foo, event.bar)
into out;
  • Add the setting emit_empty_windows for windows, which is false if not explicitly set to true. If set to true, time based tumbling windows will emit a window event on every interval if they received an event or not. Some aggregations might return null in this case.

This fixes some unintended edge cases in the window handling changes introduced in 0.10.

Related

Checklist

  • The RFC, if required, has been submitted and approved
  • Any user-facing impact of the changes is reflected in docs.tremor.rs
  • The code is tested
  • Use of unsafe code is reasoned about in a comment
  • Update CHANGELOG.md appropriately, recording any changes, bug fixes, or other observable changes in behavior
  • The performance impact of the change is measured (see below)

Performance

Copy link
Member

@Licenser Licenser left a comment

Choose a reason for hiding this comment

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

Nice improvement :) I left a few inline comments

@coveralls
Copy link
Collaborator

coveralls commented Mar 11, 2021

Coverage Status

Coverage increased (+0.04%) to 81.657% when pulling 065aaf5 on window-select-target into 7b72766 on main.

@mfelsche mfelsche force-pushed the window-select-target branch 2 times, most recently from a2980f0 to b5888af Compare March 15, 2021 18:43
@mfelsche mfelsche marked this pull request as ready for review March 15, 2021 20:51
@mfelsche mfelsche force-pushed the window-select-target branch 3 times, most recently from 107dbdb to 79da0f8 Compare March 16, 2021 15:14
.params
.get("emit_empty_windows")
.and_then(Value::as_bool)
.unwrap_or(WindowImpl::DEFAULT_EMIT_EMPTY_WINDOWS);
Copy link
Member

Choose a reason for hiding this comment

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

we should emit a warning here if emit_empty_windows is set and max_groups is not set

@Licenser
Copy link
Member

I love the ast walker :D that's going to be so handy over time! I left a few comments inline most just questions otherwise 👍

Matthias Wahl added 7 commits March 16, 2021 21:23
…'emit_empty_windows'

Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Matthias Wahl added 13 commits March 16, 2021 21:23
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
…be waiting longer than configured.

Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
Signed-off-by: Matthias Wahl <mwahl@wayfair.com>
@mfelsche mfelsche force-pushed the window-select-target branch from e99b189 to 065aaf5 Compare March 16, 2021 20:24
Copy link
Member

@Licenser Licenser left a comment

Choose a reason for hiding this comment

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

Woooh! Nice job :D

@Licenser Licenser merged commit c819dcb into main Mar 17, 2021
@Licenser Licenser deleted the window-select-target branch March 17, 2021 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants