-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathschema_exists.sql
More file actions
66 lines (60 loc) · 2.22 KB
/
schema_exists.sql
File metadata and controls
66 lines (60 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{#
Per-adapter schema existence check, scoped to a given database.
Uses SQL queries instead of adapter.check_schema_exists() because that
method is not available in dbt's run-operation context
(RuntimeDatabaseWrapper does not expose it).
#}
{% macro edr_schema_exists(database, schema_name) %}
{% do return(
adapter.dispatch("edr_schema_exists", "elementary_tests")(
database, schema_name
)
) %}
{% endmacro %}
{% macro default__edr_schema_exists(database, schema_name) %}
{% set safe_db = database | replace("'", "''") %}
{% set safe_schema = schema_name | replace("'", "''") %}
{% set result = run_query(
"SELECT schema_name FROM information_schema.schemata WHERE lower(catalog_name) = lower('"
~ safe_db
~ "') AND lower(schema_name) = lower('"
~ safe_schema
~ "')"
) %}
{% do return(result | length > 0) %}
{% endmacro %}
{% macro bigquery__edr_schema_exists(database, schema_name) %}
{% set safe_db = database | replace("`", "\`") %}
{% set safe_schema = schema_name | replace("'", "''") %}
{% set result = run_query(
"SELECT schema_name FROM `"
~ safe_db
~ "`.INFORMATION_SCHEMA.SCHEMATA WHERE lower(schema_name) = lower('"
~ safe_schema
~ "')"
) %}
{% do return(result | length > 0) %}
{% endmacro %}
{% macro fabric__edr_schema_exists(database, schema_name) %}
{% set safe_schema = schema_name | replace("'", "''") %}
{% set result = run_query(
"SELECT name FROM sys.schemas WHERE lower(name) = lower('"
~ safe_schema
~ "')"
) %}
{% do return(result | length > 0) %}
{% endmacro %}
{% macro clickhouse__edr_schema_exists(database, schema_name) %}
{% set safe_schema = schema_name | replace("'", "''") %}
{% set result = run_query(
"SELECT 1 FROM system.databases WHERE name = '"
~ safe_schema
~ "' LIMIT 1"
) %}
{% do return(result | length > 0) %}
{% endmacro %}
{% macro spark__edr_schema_exists(database, schema_name) %}
{% set safe_schema = schema_name | replace("'", "''") %}
{% set result = run_query("SHOW DATABASES LIKE '" ~ safe_schema ~ "'") %}
{% do return(result | length > 0) %}
{% endmacro %}