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

fix: user paths url selector search #23872

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions posthog/api/test/__snapshots__/test_event.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
AND timestamp >= '2020-01-13 00:00:00'
AND timestamp <= '2020-01-20 23:59:59'
AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%qw%'
order by length(replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', ''))
LIMIT 10
'''
# ---
Expand All @@ -34,6 +35,7 @@
AND timestamp >= '2020-01-13 00:00:00'
AND timestamp <= '2020-01-20 23:59:59'
AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%QW%'
order by length(replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', ''))
LIMIT 10
'''
# ---
Expand All @@ -47,6 +49,7 @@
AND timestamp >= '2020-01-13 00:00:00'
AND timestamp <= '2020-01-20 23:59:59'
AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%6%'
order by length(replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', ''))
LIMIT 10
'''
# ---
Expand All @@ -61,6 +64,7 @@
AND timestamp <= '2020-01-20 23:59:59'
AND (event = 'random event')
AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%6%'
order by length(replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', ''))
LIMIT 10
'''
# ---
Expand All @@ -76,6 +80,7 @@
AND (event = 'foo'
OR event = 'random event')
AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%6%'
order by length(replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', ''))
LIMIT 10
'''
# ---
Expand All @@ -90,6 +95,7 @@
AND timestamp <= '2020-01-20 23:59:59'
AND (event = '404_i_dont_exist')
AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%qw%'
order by length(replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', ''))
LIMIT 10
'''
# ---
Expand All @@ -115,6 +121,7 @@
AND timestamp >= '2020-01-13 00:00:00'
AND timestamp <= '2020-01-20 23:59:59'
AND "mat_random_prop" ILIKE '%qw%'
order by length("mat_random_prop")
LIMIT 10
'''
# ---
Expand All @@ -128,6 +135,7 @@
AND timestamp >= '2020-01-13 00:00:00'
AND timestamp <= '2020-01-20 23:59:59'
AND "mat_random_prop" ILIKE '%QW%'
order by length("mat_random_prop")
LIMIT 10
'''
# ---
Expand All @@ -141,6 +149,7 @@
AND timestamp >= '2020-01-13 00:00:00'
AND timestamp <= '2020-01-20 23:59:59'
AND "mat_random_prop" ILIKE '%6%'
order by length("mat_random_prop")
LIMIT 10
'''
# ---
Expand All @@ -155,6 +164,7 @@
AND timestamp <= '2020-01-20 23:59:59'
AND (event = 'random event')
AND "mat_random_prop" ILIKE '%6%'
order by length("mat_random_prop")
LIMIT 10
'''
# ---
Expand All @@ -170,6 +180,7 @@
AND (event = 'foo'
OR event = 'random event')
AND "mat_random_prop" ILIKE '%6%'
order by length("mat_random_prop")
LIMIT 10
'''
# ---
Expand All @@ -184,6 +195,7 @@
AND timestamp <= '2020-01-20 23:59:59'
AND (event = '404_i_dont_exist')
AND "mat_random_prop" ILIKE '%qw%'
order by length("mat_random_prop")
LIMIT 10
'''
# ---
1 change: 1 addition & 0 deletions posthog/models/event/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
{parsed_date_to}
{event_filter}
{value_filter}
{order_by_clause}
LIMIT 10
"""

Expand Down
4 changes: 4 additions & 0 deletions posthog/queries/property_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def get_property_values_for_key(
property_exists_filter = ""
event_filter = ""
value_filter = ""
order_by_clause = ""
extra_params = {}

if mat_column_exists:
Expand All @@ -48,6 +49,8 @@ def get_property_values_for_key(
value_filter = "AND {} ILIKE %(value)s".format(property_field)
extra_params["value"] = "%{}%".format(value)

order_by_clause = f"order by length({property_field})"

return insight_sync_execute(
SELECT_PROP_VALUES_SQL_WITH_FILTER.format(
parsed_date_from=parsed_date_from,
Expand All @@ -56,6 +59,7 @@ def get_property_values_for_key(
event_filter=event_filter,
value_filter=value_filter,
property_exists_filter=property_exists_filter,
order_by_clause=order_by_clause,
),
{"team_id": team.pk, "key": key, **extra_params},
query_type="get_property_values_with_value",
Expand Down
Loading