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

feat: Add projection on inserted_at #17466

Merged
merged 4 commits into from
Oct 6, 2023
Merged
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
from posthog.settings import CLICKHOUSE_CLUSTER

ADD_PROJECTION_SQL = """
ALTER TABLE sharded_events
ON CLUSTER '{cluster}'
ADD PROJECTION events_inserted_at_projection (
SELECT * ORDER BY (team_id, inserted_at, event, cityHash64(distinct_id), cityHash64(uuid))
);
"""

MATERIALIZE_PROJECTION_SQL = """
ALTER TABLE sharded_events
ON CLUSTER '{cluster}'
MATERIALIZE PROJECTION events_inserted_at_projection
IN PARTITION '202309';
"""

operations = [
run_sql_with_exceptions(ADD_PROJECTION_SQL.format(cluster=CLICKHOUSE_CLUSTER)),
run_sql_with_exceptions(MATERIALIZE_PROJECTION_SQL.format(cluster=CLICKHOUSE_CLUSTER)),
]