2020-09-16 05:04:38 +02:00
|
|
|
from posthog.settings import CLICKHOUSE_ENABLE_STORAGE_POLICY, CLICKHOUSE_REPLICATION, KAFKA_HOSTS
|
2020-09-09 01:12:27 +02:00
|
|
|
|
|
|
|
STORAGE_POLICY = "SETTINGS storage_policy = 'hot_to_cold'" if CLICKHOUSE_ENABLE_STORAGE_POLICY else ""
|
|
|
|
TABLE_ENGINE = (
|
2020-09-22 14:41:08 +02:00
|
|
|
"ReplicatedReplacingMergeTree('/clickhouse/tables/{{shard}}/posthog.{table}', '{{replica}}', {ver})"
|
2020-09-09 01:12:27 +02:00
|
|
|
if CLICKHOUSE_REPLICATION
|
2020-09-22 14:41:08 +02:00
|
|
|
else "ReplacingMergeTree({ver})"
|
2020-09-09 01:12:27 +02:00
|
|
|
)
|
|
|
|
|
2020-09-16 05:04:38 +02:00
|
|
|
KAFKA_ENGINE = "Kafka('{kafka_host}', '{topic}', '{group}', '{serialization}')"
|
2020-09-15 21:40:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
GENERATE_UUID_SQL = """
|
|
|
|
SELECT generateUUIDv4()
|
|
|
|
"""
|
2020-09-16 05:04:38 +02:00
|
|
|
|
|
|
|
|
2020-09-22 14:41:08 +02:00
|
|
|
def table_engine(table: str, ver: str) -> str:
|
|
|
|
return TABLE_ENGINE.format(table=table, ver=ver)
|
2020-09-16 05:04:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
def kafka_engine(topic: str, kafka_host=KAFKA_HOSTS, group="group1", serialization="JSONEachRow"):
|
|
|
|
return KAFKA_ENGINE.format(topic=topic, kafka_host=kafka_host, group=group, serialization=serialization)
|