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(22.8) don't use ifnull for cardinality casting #5807

Merged
merged 2 commits into from
Apr 23, 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
8 changes: 2 additions & 6 deletions snuba/query/processors/logical/low_cardinality_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ def transform_expressions(exp: Expression) -> Expression:
exp.alias,
"cast",
(
FunctionCall(
None,
"ifNull",
(replace(exp, alias=None), Literal(None, "")),
),
Literal(None, "String"),
replace(exp, alias=None),
Literal(None, "Nullable(String)"),
),
)

Expand Down
13 changes: 8 additions & 5 deletions tests/test_snql_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,11 +1431,11 @@ def test_allocator_clickhouse_bug(self) -> None:
assert response.status_code == 200
data = json.loads(response.data)
assert (
"equals((cast(ifNull(release, ''), 'String') AS _snuba_release), '1123581321345589')"
"equals((cast(release, 'Nullable(String)') AS _snuba_release), '1123581321345589')"
in data["sql"]
)
assert (
"has(['prod', 'dev'], (cast(ifNull(environment, ''), 'String') AS _snuba_environment))"
"has(['prod', 'dev'], (cast(environment, 'Nullable(String)') AS _snuba_environment))"
in data["sql"]
)

Expand All @@ -1455,11 +1455,13 @@ def test_low_cardinality_processor(self) -> None:
project_id AS `project`,
title,
event_id AS `id`,
project_id AS `project.name`
project_id AS `project.name`,
platform AS `platform`
WHERE timestamp >= toDateTime('{self.base_time.isoformat()}')
AND timestamp < toDateTime('{self.next_time.isoformat()}')
AND project_id IN array({self.project_id})
AND environment IN array('dev', 'prod', 'staging')
AND platform IN tuple('snuba', 'sentry')
ORDER BY timestamp DESC LIMIT 51 OFFSET 0""",
"legacy": True,
"app_id": "legacy",
Expand All @@ -1475,9 +1477,10 @@ def test_low_cardinality_processor(self) -> None:
assert response.status_code == 200
data = json.loads(response.data)
assert (
"cast(ifNull(environment, ''), 'String') AS _snuba_environment"
in data["sql"]
"cast(environment, 'Nullable(String)') AS _snuba_environment" in data["sql"]
)
# platform is not nullable but can be cast to nullable
assert "cast(platform, 'Nullable(String)') AS _snuba_platform" in data["sql"]


@pytest.mark.clickhouse_db
Expand Down
Loading