diff --git a/dbt/adapters/impala/connections.py b/dbt/adapters/impala/connections.py index 4c301e5..60bed61 100644 --- a/dbt/adapters/impala/connections.py +++ b/dbt/adapters/impala/connections.py @@ -329,7 +329,8 @@ def add_query( # re-raise query exception so that it propogates to dbt if (query_exception): - raise query_exception + if (sql.find("invalidate metadata") < 0): # ignore errors for invalidate metadata + raise query_exception fire_event( SQLQueryStatus( diff --git a/dbt/include/impala/macros/adapters.sql b/dbt/include/impala/macros/adapters.sql index 501ec31..1258a90 100644 --- a/dbt/include/impala/macros/adapters.sql +++ b/dbt/include/impala/macros/adapters.sql @@ -206,6 +206,7 @@ {% call statement('drop_relation_if_exists_view') %} drop view if exists {{ relation }} {% endcall %} + {{ invalidate_metadata(relation) }} {% endmacro %} {% macro is_relation_present(relation) -%} @@ -248,6 +249,12 @@ {% do return(rel_type) %} {% endmacro %} +{% macro invalidate_metadata(relation) %} + {% call statement('invalidate_metadata') %} + invalidate metadata {{ relation.include(schema=True) }} + {% endcall %} +{% endmacro %} + {% macro impala__rename_relation(from_relation, to_relation) -%} {% set from_rel_type = get_relation_type(from_relation) %} @@ -255,8 +262,12 @@ drop table if exists {{ to_relation }} {% endcall %} {% call statement('drop_relation_if_exists_view') %} - drop view if exists {{ to_relation }}; + drop view if exists {{ to_relation }} {% endcall %} + + {{ invalidate_metadata(to_relation) }} + {{ invalidate_metadata(from_relation) }} + {% call statement('rename_relation') -%} {% if not from_rel_type %} {% do exceptions.raise_database_error("Cannot rename a relation with a blank type: " ~ from_relation.identifier) %} diff --git a/dbt/include/impala/macros/incremental.sql b/dbt/include/impala/macros/incremental.sql index 436432f..a09d893 100644 --- a/dbt/include/impala/macros/incremental.sql +++ b/dbt/include/impala/macros/incremental.sql @@ -111,6 +111,7 @@ {% do to_drop.append(backup_relation) %} {% do to_drop.append(intermediate_relation) %} {% else %} + {{ drop_relation_if_exists(tmp_relation) }} {% do run_query(create_table_as(True, tmp_relation, sql)) %} {% do adapter.expand_target_column_types( from_relation=tmp_relation, @@ -125,6 +126,8 @@ {#-- set build_sql = get_delete_insert_merge_sql(target_relation, tmp_relation, unique_key, dest_columns) --#} {% set build_sql = get_insert_overwrite_sql(target_relation, tmp_relation, dest_columns) %} + + {% do to_drop.append(tmp_relation) %} {% endif %} @@ -133,7 +136,9 @@ {% endcall %} {% if need_swap %} + {{ drop_relation_if_exists(backup_relation) }} {% do adapter.rename_relation(target_relation, backup_relation) %} + {{ drop_relation_if_exists(target_relation) }} {% do adapter.rename_relation(intermediate_relation, target_relation) %} {% endif %} @@ -149,7 +154,7 @@ {% do adapter.commit() %} {% for rel in to_drop %} - {% do adapter.drop_relation(rel) %} + {{ drop_relation_if_exists(rel) }} {% endfor %} {{ run_hooks(post_hooks, inside_transaction=False) }}