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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add projection for batch exports on inserted_at #21839

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.conf import settings

from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
from posthog.models.event.sql import EVENTS_DATA_TABLE

EVENTS_TABLE_INSERTED_AT_PROJECTION_SQL = """
ALTER TABLE {table_name} ON CLUSTER {cluster}
ADD PROJECTION `inserted_at_batch_exports_projection` (
SELECT
_timestamp,
created_at,
distinct_id,
elements_chain,
event,
inserted_at,
person_created_at,
person_id,
person_properties,
properties,
team_id,
timestamp,
uuid
ORDER BY (team_id, COALESCE(`inserted_at`, `_timestamp`), event, cityHash64(distinct_id), cityHash64(uuid))
)
""".format(table_name=EVENTS_DATA_TABLE(), cluster=settings.CLICKHOUSE_CLUSTER)

operations = [
run_sql_with_exceptions(EVENTS_TABLE_INSERTED_AT_PROJECTION_SQL),
]