Skip to content

Commit 14fff40

Browse files
authored
Handle external tables in get_tables_by_pattern_sql (#351)
1 parent 8fb77b1 commit 14fff40

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ If you were relying on the position to match up your optional arguments, this ma
5050

5151
## Fixes
5252
* Handle booleans gracefully in the unpivot macro ([#305](https://github.com/fishtown-analytics/dbt-utils/pull/305) [@avishalom](https://github.com/avishalom))
53+
* Fix a bug in `get_relation_by_prefix` that happens with Snowflake external tables. Now the macro will retrieve tables that match the prefix which are external tables ([#350](https://github.com/fishtown-analytics/dbt-utils/issues/350))
5354

5455

5556
# dbt-utils v0.6.4

README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -1088,9 +1088,10 @@ We welcome contributions to this repo! To contribute a new feature or a fix, ple
10881088

10891089
### Dispatch macros
10901090

1091-
**Note:** This is primarily relevant to users and maintainers of community-supported
1092-
database plugins. If you use Postgres, Redshift, Snowflake, or Bigquery, this likely
1093-
does not apply to you.
1091+
**Note:** This is primarily relevant to:
1092+
- Users and maintainers of community-supported [adapter plugins](https://docs.getdbt.com/docs/available-adapters)
1093+
- Users who wish to override a low-lying `dbt_utils` macro with a custom implementation, and have that implementation used by other `dbt_utils` macros
1094+
If you use Postgres, Redshift, Snowflake, or Bigquery, this likely does not apply to you.
10941095

10951096
dbt v0.18.0 introduces `adapter.dispatch()`, a reliable way to define different implementations of the same macro
10961097
across different databases.
@@ -1101,15 +1102,17 @@ variable in your project, when dbt searches for implementations of a dispatched
11011102
`dbt_utils` macro, it will search through your listed packages _before_ using
11021103
the implementations defined in `dbt_utils`.
11031104

1104-
Set the variable:
1105+
Set a variable in your `dbt_project.yml`:
11051106
```yml
11061107
vars:
11071108
dbt_utils_dispatch_list:
1108-
- first_package_to_search # likely the name of your root project
1109+
- first_package_to_search # likely the name of your root project (only the root folder)
11091110
- second_package_to_search # likely an "add-on" package, such as spark_utils
11101111
# dbt_utils is always the last place searched
11111112
```
11121113

1114+
If overriding a dispatched macro with a custom implementation in your own project's `macros/` directory, you must name your custom macro with a prefix: either `default__` (note the two underscores), or the name of your adapter followed by two underscores. For example, if you're running on Postgres and wish to override the behavior of `dbt_utils.datediff` (such that `dbt_utils.date_spine` will use your version instead), you can do this by defining a macro called either `default__datediff` or `postgres__datediff`.
1115+
11131116
When running on Spark, if dbt needs to dispatch `dbt_utils.datediff`, it will search for the following in order:
11141117
```
11151118
first_package_to_search.spark__datediff

macros/sql/get_tables_by_pattern_sql.sql

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
table_name as "table_name",
1111
case table_type
1212
when 'BASE TABLE' then 'table'
13+
when 'EXTERNAL TABLE' then 'external'
14+
when 'MATERIALIZED VIEW' then 'materializedview'
1315
else lower(table_type)
1416
end as "table_type"
1517
from {{ database }}.information_schema.tables

0 commit comments

Comments
 (0)