Skip to content

Commit

Permalink
optimize query
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel Chen authored and Rachel Chen committed Dec 19, 2024
1 parent fe64d03 commit 9b4396c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
9 changes: 1 addition & 8 deletions snuba/manual_jobs/scrub_users_from_eap_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@ def _get_query(self, cluster_name: str | None) -> str:
on_cluster = f"ON CLUSTER '{cluster_name}'" if cluster_name else ""
return f"""ALTER TABLE eap_spans_2_local
{on_cluster}
UPDATE `attr_str_2` = mapApply((k, v) -> (k, if(k = 'user' AND startsWith(v, '{_IP_PREFIX}'), concat(
'{_IP_PREFIX}',
if(
isIPv4String(substring(v, 4)) OR isIPv6String(substring(v, 4)),
'{_SCRUBBED}',
substring(v, 4)
)
), v)), `attr_str_2`)
UPDATE `attr_str_2` = mapApply((k, v) -> (k, if(k = 'user' AND startsWith(v, '{_IP_PREFIX}') AND (isIPv4String(substring(v, 4)) OR isIPv6String(substring(v, 4))), 'ip:scrubbed', v)), `attr_str_2`)
WHERE organization_id IN [{organization_ids}]
AND _sort_timestamp >= toDateTime('{start_datetime}')
AND _sort_timestamp < toDateTime('{end_datetime}')"""
Expand Down
9 changes: 1 addition & 8 deletions tests/manual_jobs/test_scrub_users_from_eap_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,7 @@ def test_generate_query() -> None:
job._get_query(None)
== """ALTER TABLE eap_spans_2_local
UPDATE `attr_str_2` = mapApply((k, v) -> (k, if(k = 'user' AND startsWith(v, 'ip:'), concat(
'ip:',
if(
isIPv4String(substring(v, 4)) OR isIPv6String(substring(v, 4)),
'scrubbed',
substring(v, 4)
)
), v)), `attr_str_2`)
UPDATE `attr_str_2` = mapApply((k, v) -> (k, if(k = 'user' AND startsWith(v, 'ip:') AND (isIPv4String(substring(v, 4)) OR isIPv6String(substring(v, 4))), 'ip:scrubbed', v)), `attr_str_2`)
WHERE organization_id IN [1,3,5,6]
AND _sort_timestamp >= toDateTime('2024-12-01T00:00:00')
AND _sort_timestamp < toDateTime('2024-12-10T00:00:00')"""
Expand Down

0 comments on commit 9b4396c

Please sign in to comment.