Skip to content

Commit

Permalink
add to management command
Browse files Browse the repository at this point in the history
  • Loading branch information
tkaemming committed Nov 27, 2024
1 parent ffc0d3c commit 1c0d495
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ee/clickhouse/materialized_columns/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def materialize_properties_task(
backfill_period_days: int = MATERIALIZE_COLUMNS_BACKFILL_PERIOD_DAYS,
dry_run: bool = False,
team_id_to_analyze: Optional[int] = None,
is_nullable: bool = False,
) -> None:
"""
Creates materialized columns for event and person properties based off of slow queries
Expand Down Expand Up @@ -203,7 +204,7 @@ def materialize_properties_task(
logger.info(f"Materializing column. table={table}, property_name={property_name}")

if not dry_run:
materialize(table, property_name, table_column=table_column)
materialize(table, property_name, table_column=table_column, is_nullable=is_nullable)
properties[table].append((property_name, table_column))

if backfill_period_days > 0 and not dry_run:
Expand Down
3 changes: 2 additions & 1 deletion ee/clickhouse/materialized_columns/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def materialize(
column_name: ColumnName | None = None,
table_column: TableColumn = DEFAULT_TABLE_COLUMN,
create_minmax_index=not TEST,
is_nullable: bool = False,
) -> ColumnName | None:
if (property, table_column) in get_materialized_columns(table):
if TEST:
Expand All @@ -253,7 +254,7 @@ def materialize(
property_name=property,
is_disabled=False,
),
is_nullable=False, # TODO
is_nullable=is_nullable,
)

table_info.map_data_nodes(
Expand Down
11 changes: 10 additions & 1 deletion ee/management/commands/materialize_columns.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import logging

from django.core.management.base import BaseCommand
Expand Down Expand Up @@ -69,8 +70,14 @@ def add_arguments(self, parser):
default=MATERIALIZE_COLUMNS_MAX_AT_ONCE,
help="Max number of columns to materialize via single invocation. Same as MATERIALIZE_COLUMNS_MAX_AT_ONCE env variable.",
)
parser.add_argument(
"--nullable",
action=argparse.BooleanOptionalAction,
default=True,
dest="is_nullable",
)

def handle(self, *args, **options):
def handle(self, *, is_nullable: bool, **options):
logger.setLevel(logging.INFO)

if options["dry_run"]:
Expand All @@ -90,6 +97,7 @@ def handle(self, *args, **options):
],
backfill_period_days=options["backfill_period"],
dry_run=options["dry_run"],
is_nullable=is_nullable,
)
else:
materialize_properties_task(
Expand All @@ -99,4 +107,5 @@ def handle(self, *args, **options):
backfill_period_days=options["backfill_period"],
dry_run=options["dry_run"],
team_id_to_analyze=options["analyze_team_id"],
is_nullable=is_nullable,
)

0 comments on commit 1c0d495

Please sign in to comment.