-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix: re2 dot all flag for non-hogql filters #19487
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a2e8c7f
fix: re2 dot all flag for non-hogql filters
pauldambra 1bde0fd
add for hogql here?
pauldambra c756fda
some tests
pauldambra 3d4c1af
Update query snapshots
github-actions[bot] 9c351b7
add tests for old query building
fuziontech fdae0df
Update query snapshots
github-actions[bot] 3a512ab
failing tests
pauldambra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
153 changes: 0 additions & 153 deletions
153
ee/clickhouse/models/test/__snapshots__/test_property.ambr
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1511,6 +1511,20 @@ def test_events(db, team) -> List[UUID]: | |
"date_exact_including_seconds_and_milliseconds": f"{datetime(2021, 3, 31, 23, 59, 59, 12):%d/%m/%Y %H:%M:%S.%f}" | ||
}, | ||
), | ||
_create_event( | ||
event="$pageview", | ||
team=team, | ||
distinct_id="whatever", | ||
# new line character shouldn't be matched by a single regex dot | ||
properties={"email": "test@post\nhog.com"}, | ||
), | ||
_create_event( | ||
event="$pageview", | ||
team=team, | ||
distinct_id="whatever", | ||
# not a new line character - instead a single character - should match | ||
properties={"email": "[email protected]"}, | ||
), | ||
] | ||
|
||
|
||
|
@@ -1749,6 +1763,9 @@ def clean_up_materialised_columns(): | |
[20, 21], | ||
id="can match before date only values", | ||
), | ||
# Regression test, we were previously matching on newline characters | ||
# this should match one of two possibles (how are you supposed to figure out the expected index 🙈) | ||
pytest.param(Property(key="email", value=r"[email protected]", operator="regex"), [28]), | ||
] | ||
|
||
|
||
|
2 changes: 1 addition & 1 deletion
2
ee/clickhouse/views/test/__snapshots__/test_clickhouse_experiment_secondary_results.ambr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,6 +277,63 @@ def test_event_property_filter(self): | |
response = self.client.post(f"/api/projects/{self.team.id}/query/", {"query": query.dict()}).json() | ||
self.assertEqual(len(response["results"]), 1) | ||
|
||
@also_test_with_materialized_columns(event_properties=["example_value"]) | ||
@snapshot_clickhouse_queries | ||
def test_event_property_regex_is_patched_for_dotall_setting(self): | ||
with freeze_time("2020-01-10 12:00:00"): | ||
_create_person( | ||
properties={"email": "[email protected]"}, | ||
distinct_ids=["2", "some-random-uid"], | ||
team=self.team, | ||
immediate=True, | ||
) | ||
_create_event( | ||
team=self.team, | ||
event="demonstrate dot all", | ||
distinct_id="2", | ||
properties={ | ||
"example_value": """a | ||
b""" | ||
}, | ||
) | ||
with freeze_time("2020-01-10 12:11:00"): | ||
_create_event( | ||
team=self.team, | ||
event="demonstrate dot all", | ||
distinct_id="2", | ||
# should match /a.b/ | ||
properties={"example_value": "aab"}, | ||
) | ||
with freeze_time("2020-01-10 12:11:00"): | ||
_create_event( | ||
team=self.team, | ||
event="demonstrate dot all", | ||
distinct_id="2", | ||
# should match /a.b/ | ||
properties={"example_value": "abb"}, | ||
) | ||
with freeze_time("2020-01-10 12:11:00"): | ||
_create_event( | ||
team=self.team, | ||
event="demonstrate dot all", | ||
distinct_id="2", | ||
# won't match /a.b/ | ||
properties={"example_value": "abc"}, | ||
) | ||
flush_persons_and_events() | ||
|
||
with freeze_time("2020-01-10 12:14:00"): | ||
query = EventsQuery( | ||
event="demonstrate dot all", | ||
select=[ | ||
"properties.example_value", | ||
], | ||
properties=[{"key": "example_value", "value": "a.b", "operator": "regex", "type": "event"}], | ||
) | ||
response = self.client.post(f"/api/projects/{self.team.id}/query/", {"query": query.dict()}).json() | ||
assert "(?-s)" in response["hogql"] | ||
assert [x[0] for x in response["results"]] == ["aab", "abb"] | ||
|
||
@also_test_with_materialized_columns(event_properties=["key"], person_properties=["email"]) | ||
@snapshot_clickhouse_queries | ||
def test_person_property_filter(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -489,7 +489,13 @@ def prop_filter_json_extract( | |
|
||
params = { | ||
"k{}_{}".format(prepend, idx): prop.key, | ||
"v{}_{}".format(prepend, idx): prop.value, | ||
# we follow re2 regex syntax and so does ClickHouse **except** | ||
# For example, the string a\nb shouldn't match the pattern a.b, but it does in CH | ||
# this is because According to the re2 docs, the s flag is false by default, | ||
# but in CH it seems to be true by default. | ||
# prepending (?-s) to the regex string will make it work as expected | ||
# see https://github.com/ClickHouse/ClickHouse/issues/34603 | ||
"v{}_{}".format(prepend, idx): f"(?-s){prop.value}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pretty sure this is right |
||
} | ||
|
||
return ( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definitely looks correct.