Skip to content

Commit 55fbd86

Browse files
vamshikolanuVamshi Kolanu
andauthored
handle_list_relations_without_caching_failure (#190)
Co-authored-by: Vamshi Kolanu <[email protected]>
1 parent c429927 commit 55fbd86

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

dbt/adapters/impala/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
version = "1.4.2"
15+
version = "1.4.3"

dbt/adapters/impala/impl.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
LIST_SCHEMAS_MACRO_NAME = "list_schemas"
3737
LIST_RELATIONS_MACRO_NAME = "list_relations_without_caching"
38+
LIST_TABLES_IN_RELATION_MACRO_NAME = "list_tables_in_relation"
39+
GET_RELATIONSHIP_TYPE_MACRO_NAME = "get_relation_type"
3840

3941
KEY_TABLE_OWNER = "Owner"
4042
KEY_TABLE_STATISTICS = "Statistics"
@@ -95,31 +97,35 @@ def list_schemas(self, database: str) -> List[str]:
9597

9698
return schemas
9799

100+
def fetch_relation_type(self, relation: Relation) -> str:
101+
try:
102+
kwargs = {"relation": relation}
103+
relation_type = self.execute_macro(GET_RELATIONSHIP_TYPE_MACRO_NAME, kwargs=kwargs)
104+
except dbt.exceptions.DbtRuntimeError as e:
105+
logger.error(
106+
f"Unable to fetch relation type {relation.schema}.{relation.identifier}: {e.msg}"
107+
)
108+
return None
109+
return relation_type
110+
98111
def list_relations_without_caching(
99112
self, schema_relation: ImpalaRelation
100113
) -> List[ImpalaRelation]:
101-
kwargs = {"schema_relation": schema_relation}
102-
103114
try:
104-
results = self.execute_macro(LIST_RELATIONS_MACRO_NAME, kwargs=kwargs)
115+
kwargs = {"relation": schema_relation}
116+
table_relations = self.execute_macro(LIST_TABLES_IN_RELATION_MACRO_NAME, kwargs=kwargs)
105117
except dbt.exceptions.DbtRuntimeError as e:
106118
errmsg = getattr(e, "msg", "")
107-
if f"Database '{schema_relation}' not found" in errmsg:
119+
if f"Database does not exist" in errmsg:
108120
return []
109121
else:
110-
description = "Error while retrieving information about"
111-
logger.error(f"{description} {schema_relation}: {e.msg}")
122+
logger.error(f"Unable to extract tables in relation {schema_relation}: {errmsg}")
112123
raise e
113124

114125
relations = []
115-
for row in results:
116-
if len(row) != 2:
117-
raise dbt.exceptions.DbtRuntimeError(
118-
f'Invalid value from "show table extended ...", '
119-
f"got {len(row)} values, expected 4"
120-
)
121-
_identifier = row[0]
122-
_rel_type = row[1]
126+
for table_relation in table_relations:
127+
_rel_type = self.fetch_relation_type(table_relation)
128+
_identifier = table_relation.identifier
123129

124130
relation = self.Relation.create(
125131
database=None,

dbt/include/impala/macros/adapters.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@
125125
{{ return(load_result('list_schemas').table) }}
126126
{% endmacro %}
127127

128+
{% macro list_tables_in_relation(relation) %}
129+
{% set result_set = run_query('show tables in ' ~ relation) %}
130+
131+
{% set tables = [] %}
132+
133+
{% if execute %}
134+
{%- for rs in result_set -%}
135+
{% do tables.append(relation.new_copy(relation.schema, rs[0])) %}
136+
{%- endfor -%}
137+
{% endif %}
138+
139+
{{ return(tables) }}
140+
{% endmacro %}
141+
142+
128143
{# Note: This function currently needs to query each object to determine its type. Depending on the schema, this function could be expensive. #}
129144
{% macro impala__list_relations_without_caching(relation) %}
130145
{% set result_set = run_query('show tables in ' ~ relation) %}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _get_dbt_core_version():
4646

4747
package_name = "dbt-impala"
4848
# make sure this always matches dbt/adapters/dbt_impala/__version__.py
49-
package_version = "1.4.2"
49+
package_version = "1.4.3"
5050
description = """The Impala adapter plugin for dbt"""
5151

5252
dbt_core_version = _get_dbt_core_version()

0 commit comments

Comments
 (0)