Skip to content

Commit

Permalink
bind the group manager to a cluster for now
Browse files Browse the repository at this point in the history
  • Loading branch information
tkaemming committed Aug 2, 2024
1 parent c055882 commit 03509f6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions posthog/clickhouse/property_groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from collections.abc import Iterable, MutableMapping
from dataclasses import dataclass

from posthog import settings


@dataclass
class PropertyGroupDefinition:
Expand All @@ -9,7 +11,8 @@ class PropertyGroupDefinition:


class PropertyGroupManager:
def __init__(self, table: str, source_column: str) -> None:
def __init__(self, cluster: str, table: str, source_column: str) -> None:
self.__cluster = cluster
self.__table = table
self.__source_column = source_column
self.__groups: MutableMapping[str, PropertyGroupDefinition] = {}
Expand All @@ -25,13 +28,13 @@ def get_alter_table_statements(self, name: str) -> Iterable[str]:
column_name = f"{self.__source_column}_group_{name}"
definition = self.__groups[name]
return [
f"ALTER TABLE {self.__table} ADD COLUMN {column_name} Map(String, String) MATERIALIZED {self.__get_map_expression(definition)} CODEC({definition.codec})",
f"ALTER TABLE {self.__table} ADD INDEX {column_name}_keys_bf mapValues({column_name}) TYPE bloom_filter",
f"ALTER TABLE {self.__table} ADD INDEX {column_name}_values_bf mapValues({column_name}) TYPE bloom_filter",
f"ALTER TABLE {self.__table} ON CLUSTER {self.__cluster} ADD COLUMN {column_name} Map(String, String) MATERIALIZED {self.__get_map_expression(definition)} CODEC({definition.codec})",
f"ALTER TABLE {self.__table} ON CLUSTER {self.__cluster} ADD INDEX {column_name}_keys_bf mapValues({column_name}) TYPE bloom_filter",
f"ALTER TABLE {self.__table} ON CLUSTER {self.__cluster} ADD INDEX {column_name}_values_bf mapValues({column_name}) TYPE bloom_filter",
]


sharded_events_property_groups = PropertyGroupManager("sharded_events", "properties")
sharded_events_property_groups = PropertyGroupManager(settings.CLICKHOUSE_CLUSTER, "sharded_events", "properties")

ignore_custom_properties = [
# `token` & `distinct_id` properties are sent with ~50% of events and by
Expand Down

0 comments on commit 03509f6

Please sign in to comment.