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

chore: create ClickHouse override tables #25681

Merged
merged 30 commits into from
Oct 29, 2024
Merged

Conversation

daibhin
Copy link
Contributor

@daibhin daibhin commented Oct 18, 2024

Problem

Related to https://github.com/PostHog/product-internal/pull/662

Changes

We have decided to use the same overrides pattern as person distinct ids. This copies all the work done there to create the necessary tables in ClickHouse

@daibhin daibhin requested a review from a team as a code owner October 18, 2024 10:50
Comment on lines +46 to +75
KAFKA_ERROR_TRACKING_ISSUE_FINGERPRINT_OVERRIDES_TABLE_SQL = (
lambda: ERROR_TRACKING_ISSUE_FINGERPRINT_OVERRIDES_TABLE_BASE_SQL.format(
table_name="kafka_" + ERROR_TRACKING_ISSUE_FINGERPRINT_OVERRIDES_TABLE,
cluster=CLICKHOUSE_CLUSTER,
engine=kafka_engine(
KAFKA_ERROR_TRACKING_ISSUE_FINGERPRINT, group="clickhouse-error-tracking-issue-fingerprint-overrides"
),
extra_fields="",
)
)

ERROR_TRACKING_ISSUE_FINGERPRINT_OVERRIDES_MV_SQL = """
CREATE MATERIALIZED VIEW IF NOT EXISTS {table_name}_mv ON CLUSTER '{cluster}'
TO {database}.{table_name}
AS SELECT
team_id,
fingerprint,
issue_id,
is_deleted,
version,
_timestamp,
_offset,
_partition
FROM {database}.kafka_{table_name}
WHERE version > 0 -- only store updated rows, not newly inserted ones
""".format(
table_name=ERROR_TRACKING_ISSUE_FINGERPRINT_OVERRIDES_TABLE,
cluster=CLICKHOUSE_CLUSTER,
database=CLICKHOUSE_DATABASE,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't see where either of these two tables were being used for persons distinct id overrides... Is it legacy or necessary part of the table setup in CH? @tkaemming

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are both necessary — you'll want to only issue read requests against the error_tracking_issue_fingerprint_overrides table and use the Kafka topic (and table) added here to handle writing to the table versus running INSERT/UPDATEs manually. The Kafka table handles the Kafka consumer side, and the materialized view shuttles data from the Kafka table to the data table when there are rows ready to be written.

@daibhin daibhin requested a review from a team October 22, 2024 09:07
@daibhin daibhin merged commit 30cfe53 into master Oct 29, 2024
87 checks passed
@daibhin daibhin deleted the dn-feat/create-overrides-tables branch October 29, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants