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: support AND / OR operands in replay filters #22955

Merged
merged 39 commits into from
Jun 17, 2024

Conversation

daibhin
Copy link
Contributor

@daibhin daibhin commented Jun 13, 2024

Problem

Universal filtering does not support AND / OR predicates right now

Changes

Implicit assumption in here that this only works for the new HogQL filters. There's no reason to backport given they're enabled for most customers and haven't been causing issues

(Other comments inline)

Does this work well for both Cloud and self-hosted?

Yes

How did you test this code?

Added tests


// set the type on the nested child when only using a single filter group
const hasSingleGroup = universalFilters.filter_group.values.length === 1
if (hasSingleGroup) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given we have two levels of nesting (to make it easier to support multiple filter groups in future) it's necessary to update the operand at both levels if there is only a single filter because the UI makes it look like there is only one level of nesting

@@ -464,7 +465,7 @@ def _where_predicates(self) -> ast.Expr:

(event_where_exprs, _) = self._event_predicates
if event_where_exprs:
exprs.append(ast.Or(exprs=event_where_exprs))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +148 to +165
person_id_subquery = PersonsIdSubQuery(self._team, self._filter, self.ttl_days).get_query()
if person_id_subquery:
exprs.append(
ast.CompareOperation(
op=ast.CompareOperationOp.In,
left=ast.Field(chain=["s", "distinct_id"]),
right=person_id_subquery,
)
)

if self._filter.session_ids:
exprs.append(
ast.CompareOperation(
op=ast.CompareOperationOp.In,
left=ast.Field(chain=["session_id"]),
right=ast.Constant(value=self._filter.session_ids),
)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No changes, just pulled the mandatory expressions together

@@ -485,7 +486,7 @@ def _having_predicates(self) -> ast.Expr:

if event_names:
return ast.Call(
name="hasAll",
name="hasAll" if self._filter._operand == "AND" else "hasAny",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm assuming this is an optimisation. We cannot rely on every event being in the array when using OR conditions

@@ -473,7 +474,7 @@ def _where_predicates(self) -> ast.Expr:
exprs.append(
ast.CompareOperation(
op=ast.CompareOperationOp.In,
left=ast.Constant(value="`$session_id`"),
left=ast.Field(chain=["$session_id"]),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noticed this as a bug thanks to @robbie-c. It was comparing the value "$session" and wasn't being caught by any of our tests :/

Copy link
Member

Choose a reason for hiding this comment

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

should we have a test? (what's the error?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was using the constant (string value) not the field e.g. "$session_id" in ['uuid1', 'uuid2',...] instead of $session_id in ['uuid1', 'uuid2',...]

I think the effect is that pinned recordings weren't being shown in playlists for HogQL filters.

One of my new tests relies on the $session_id field so that should cover it

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

Copy link
Contributor

github-actions bot commented Jun 13, 2024

Size Change: +36 B (0%)

Total Size: 1.06 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 1.06 MB +36 B (0%)

compressed-size-action

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

3 snapshot changes in total. 0 added, 3 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

3 snapshot changes in total. 0 added, 3 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@daibhin daibhin requested a review from a team June 14, 2024 09:08
Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

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

didn't run it, assume you did 🙈

LGTM

@@ -473,7 +474,7 @@ def _where_predicates(self) -> ast.Expr:
exprs.append(
ast.CompareOperation(
op=ast.CompareOperationOp.In,
left=ast.Constant(value="`$session_id`"),
left=ast.Field(chain=["$session_id"]),
Copy link
Member

Choose a reason for hiding this comment

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

should we have a test? (what's the error?)

@@ -273,7 +278,7 @@ def _having_predicates(self) -> ast.And | Constant:
),
)

return ast.And(exprs=exprs) if exprs else Constant(value=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

exprs always has at least one value

@daibhin
Copy link
Contributor Author

daibhin commented Jun 17, 2024

@pauldambra yep, ran it locally and filters still seem to work

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@daibhin daibhin merged commit 7a32722 into master Jun 17, 2024
90 checks passed
@daibhin daibhin deleted the dn-feat/support-replay-operand branch June 17, 2024 13:18
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