From 358f94de3dff0fea6fcc8e7a212156e10e921734 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Tue, 30 Apr 2019 11:57:36 -0400 Subject: [PATCH] Better _is_relation logic --- macros/cross_db_utils/_is_relation.sql | 6 +++--- macros/sql/get_tables_by_prefix_sql.sql | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/macros/cross_db_utils/_is_relation.sql b/macros/cross_db_utils/_is_relation.sql index 8c52d42f..bee6db97 100644 --- a/macros/cross_db_utils/_is_relation.sql +++ b/macros/cross_db_utils/_is_relation.sql @@ -1,5 +1,5 @@ -{% macro _is_relation(arg, macro) %} - {%- if execute and arg.name is none -%} - {%- do exceptions.raise_compiler_error("Macro " ~ macro ~ " expected a Relation but received the value: " ~ arg) -%} +{% macro _is_relation(obj, macro) %} + {%- if not (obj is mapping and obj.get('metadata', {}).get('type', '').endswith('Relation')) -%} + {%- do exceptions.raise_compiler_error("Macro " ~ macro ~ " expected a Relation but received the value: " ~ obj) -%} {%- endif -%} {% endmacro %} diff --git a/macros/sql/get_tables_by_prefix_sql.sql b/macros/sql/get_tables_by_prefix_sql.sql index c26d06e5..3c27c825 100644 --- a/macros/sql/get_tables_by_prefix_sql.sql +++ b/macros/sql/get_tables_by_prefix_sql.sql @@ -6,7 +6,7 @@ select distinct table_schema as "table_schema", table_name as "table_name" - from {{adapter.quote(database)}}.information_schema.tables + from {{database}}.information_schema.tables where table_schema = '{{ schema }}' and table_name ilike '{{ prefix }}%' and table_name not ilike '{{ exclude }}'