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

ref(deletes): add ConditionsType #6511

Merged
merged 2 commits into from
Nov 5, 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
5 changes: 2 additions & 3 deletions snuba/web/bulk_delete_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from snuba.utils.streams.configuration_builder import build_kafka_producer_configuration
from snuba.utils.streams.topics import Topic
from snuba.web.delete_query import (
ConditionsType,
DeletesNotEnabledError,
_construct_condition,
_enforce_max_rows,
Expand All @@ -36,8 +37,6 @@
metrics = MetricsWrapper(environment.metrics, "snuba.delete")
logger = logging.getLogger(__name__)

ConditionsType = Mapping[str, Sequence[str | int | float]]


class DeleteQueryMessage(TypedDict):
rows_to_delete: int
Expand Down Expand Up @@ -219,7 +218,7 @@ def delete_from_tables(
return result


def construct_or_conditions(conditions: Sequence[Dict[str, Any]]) -> Expression:
def construct_or_conditions(conditions: Sequence[ConditionsType]) -> Expression:
"""
Combines multiple AND conditions: (equals(project_id, 1) AND in(group_id, (2, 3, 4, 5))
into OR conditions for a bulk delete
Expand Down
10 changes: 6 additions & 4 deletions snuba/web/delete_query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import typing
import uuid
from typing import Any, Dict, Mapping, MutableMapping, Optional, Sequence
from typing import Any, Mapping, MutableMapping, Optional, Sequence

from snuba import settings
from snuba.attribution import get_app_id
Expand Down Expand Up @@ -35,6 +35,8 @@
from snuba.web import QueryException, QueryExtraData, QueryResult
from snuba.web.db_query import _apply_allocation_policies_quota

ConditionsType = Mapping[str, Sequence[str | int | float]]


class DeletesNotEnabledError(Exception):
pass
Expand All @@ -47,7 +49,7 @@ class TooManyOngoingMutationsError(Exception):
@with_span()
def delete_from_storage(
storage: WritableTableStorage,
columns: Dict[str, list[Any]],
columns: ConditionsType,
attribution_info: Mapping[str, Any],
) -> dict[str, Result]:
"""
Expand Down Expand Up @@ -108,7 +110,7 @@ def delete_from_storage(
def _delete_from_table(
storage: WritableTableStorage,
table: str,
conditions: Dict[str, Any],
conditions: ConditionsType,
attribution_info: AttributionInfo,
) -> Result:
cluster_name = storage.get_cluster().get_clickhouse_cluster_name()
Expand Down Expand Up @@ -345,7 +347,7 @@ def _execute_query(
)


def _construct_condition(columns: Dict[str, Any]) -> Expression:
def _construct_condition(columns: ConditionsType) -> Expression:
and_conditions = []
for col, values in columns.items():
if len(values) == 1:
Expand Down
Loading