-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved timeout for alter queries to config (#103)
- Loading branch information
1 parent
0ea863d
commit deeefdf
Showing
2 changed files
with
12 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,46 @@ | ||
from ch_tools.chadmin.internal.utils import execute_query | ||
|
||
DEFAULT_TIMEOUT = 600 | ||
|
||
|
||
def attach_partition(ctx, database, table, partition_id, dry_run=False): | ||
""" | ||
Attach the specified table partition. | ||
""" | ||
query = f"ALTER TABLE `{database}`.`{table}` ATTACH PARTITION ID '{partition_id}'" | ||
execute_query( | ||
ctx, | ||
query, | ||
timeout=DEFAULT_TIMEOUT, | ||
format_=None, | ||
echo=True, | ||
dry_run=dry_run, | ||
) | ||
_execute_query(ctx, query, dry_run) | ||
|
||
|
||
def detach_partition(ctx, database, table, partition_id, dry_run=False): | ||
""" | ||
Detach the specified table partition. | ||
""" | ||
query = f"ALTER TABLE `{database}`.`{table}` DETACH PARTITION ID '{partition_id}'" | ||
execute_query( | ||
ctx, | ||
query, | ||
timeout=DEFAULT_TIMEOUT, | ||
format_=None, | ||
echo=True, | ||
dry_run=dry_run, | ||
) | ||
_execute_query(ctx, query, dry_run) | ||
|
||
|
||
def drop_partition(ctx, database, table, partition_id, dry_run=False): | ||
""" | ||
Drop the specified table partition. | ||
""" | ||
query = f"ALTER TABLE `{database}`.`{table}` DROP PARTITION ID '{partition_id}'" | ||
execute_query( | ||
ctx, | ||
query, | ||
timeout=DEFAULT_TIMEOUT, | ||
format_=None, | ||
echo=True, | ||
dry_run=dry_run, | ||
) | ||
_execute_query(ctx, query, dry_run) | ||
|
||
|
||
def optimize_partition(ctx, database, table, partition_id, dry_run=False): | ||
""" | ||
Optimize the specified table partition. | ||
""" | ||
query = f"OPTIMIZE TABLE `{database}`.`{table}` PARTITION ID '{partition_id}'" | ||
execute_query( | ||
ctx, | ||
query, | ||
timeout=DEFAULT_TIMEOUT, | ||
format_=None, | ||
echo=True, | ||
dry_run=dry_run, | ||
) | ||
_execute_query(ctx, query, dry_run) | ||
|
||
|
||
def materialize_ttl_in_partition(ctx, database, table, partition_id, dry_run=False): | ||
""" | ||
Materialize TTL for the specified table partition. | ||
""" | ||
query = f"ALTER TABLE `{database}`.`{table}` MATERIALIZE TTL IN PARTITION ID '{partition_id}'" | ||
execute_query( | ||
ctx, | ||
query, | ||
timeout=DEFAULT_TIMEOUT, | ||
format_=None, | ||
echo=True, | ||
dry_run=dry_run, | ||
) | ||
_execute_query(ctx, query, dry_run) | ||
|
||
|
||
def _execute_query(ctx, query, dry_run): | ||
timeout = ctx.obj["config"]["clickhouse"]["alter_table_timeout"] | ||
execute_query(ctx, query, timeout=timeout, format_=None, echo=True, dry_run=dry_run) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters