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

fix: vacuum more runs needed error #703

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dbt/adapters/athena/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,13 +1344,13 @@ def format_value_for_partition(self, value: Any, column_type: str) -> Tuple[str,
raise ValueError(f"Unsupported column type: {column_type}")

@available
def run_optimize_with_partition_limit_catching(self, optimize_query: str) -> None:
def run_operation_with_potential_multiple_runs(self, query: str, op: str) -> None:
while True:
try:
self._run_query(optimize_query, catch_partitions_limit=False)
self._run_query(query, catch_partitions_limit=False)
break
except OperationalError as e:
if "ICEBERG_OPTIMIZE_MORE_RUNS_NEEDED" not in str(e):
if f"ICEBERG_{op.upper()}_MORE_RUNS_NEEDED" not in str(e):
raise e

def _run_query(self, sql: str, catch_partitions_limit: bool) -> AthenaCursor:
Expand Down
4 changes: 3 additions & 1 deletion dbt/include/athena/macros/materializations/hooks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
{% set rendered = render(hook.get('sql')) | trim %}
{% if (rendered | length) > 0 %}
{%- if re.match("optimize\W+\S+\W+rewrite data using bin_pack", rendered.lower(), re.MULTILINE) -%}
{%- do adapter.run_optimize_with_partition_limit_catching(rendered) -%}
{%- do adapter.run_operation_with_potential_multiple_runs(rendered, "optimize") -%}
{%- elif re.match("vacuum\W+\S+", rendered.lower(), re.MULTILINE) -%}
{%- do adapter.run_operation_with_potential_multiple_runs(rendered, "vacuum") -%}
{%- else -%}
{% call statement(auto_begin=inside_transaction) %}
{{ rendered }}
Expand Down
Loading