Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oracle adapter support #94

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ One of the advantages of the `doc` approach over the `meta` approach is that it

✅ Snowflake

✅ Oracle

✅ SQL Server

❌ Apache Spark
Expand Down
19 changes: 18 additions & 1 deletion macros/cross_db_utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
varchar
{%- endmacro -%}

{%- macro oracle__type_string() -%}
varchar(1000)
{%- endmacro -%}

{%- macro bigquery__type_string() -%}
string
{%- endmacro -%}
Expand Down Expand Up @@ -80,6 +84,10 @@
{{ relation.information_schema() }}
{%- endmacro -%}

{%- macro oracle__information_schema(relation) -%}
ALL_TAB_COLUMNS
{%- endmacro -%}

{%- macro bigquery__information_schema(relation) -%}
{{ adapter.quote(relation.database) }}.{{ adapter.quote(relation.schema) }}.INFORMATION_SCHEMA
{%- endmacro -%}
Expand All @@ -100,6 +108,15 @@
order by ordinal_position asc
{%- endmacro -%}

{%- macro oracle__select_from_information_schema_columns(relation) -%}
select
*
from {{ dbt_profiler.information_schema(relation) }}
where lower(owner) = lower('{{ relation.schema }}')
and lower(table_name) = lower('{{ relation.identifier }}')
order by column_id asc
{%- endmacro -%}

{%- macro redshift__select_from_information_schema_columns(relation) -%}
select
attr.attname::varchar as column_name,
Expand All @@ -113,4 +130,4 @@
where lower(table_schema) = lower('{{ relation.schema }}')
and lower(table_name) = lower('{{ relation.identifier }}')
and attr.attnum > 0
{%- endmacro -%}
{%- endmacro -%}
32 changes: 29 additions & 3 deletions macros/measures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
{%- endmacro -%}

{%- macro default__measure_row_count(column_name, data_type) -%}
cast(count(*) as {{ dbt.type_int() }})
cast(count(*) as {{ dbt.type_bigint() }})
{%- endmacro -%}

{%- macro oracle__measure_row_count(column_name, data_type) -%}
cast(count(*) as {{ dbt.type_numeric() }})
{%- endmacro -%}

{# measure_not_null_proportion ------------------------------------------------- #}

Expand All @@ -19,6 +22,11 @@ cast(count(*) as {{ dbt.type_int() }})
sum(case when {{ adapter.quote(column_name) }} is null then 0 else 1 end) / cast(count(*) as {{ dbt.type_numeric() }})
{%- endmacro -%}

{%- macro oracle__measure_not_null_proportion(column_name, data_type) -%}
case when cast(count(*) as {{ dbt.type_numeric() }}) != 0 THEN
sum(case when {{ adapter.quote(column_name) }} is null then 0 else 1 end) / cast(count(*) as {{ dbt.type_numeric() }})
ELSE 0 END
{%- endmacro -%}

{# measure_distinct_proportion ------------------------------------------------- #}

Expand All @@ -34,6 +42,16 @@ sum(case when {{ adapter.quote(column_name) }} is null then 0 else 1 end) / cast
{%- endif -%}
{%- endmacro -%}

{%- macro oracle__measure_distinct_proportion(column_name, data_type) -%}
{%- if not dbt_profiler.is_struct_dtype(data_type) -%}
CASE WHEN cast(count(*) as {{ dbt.type_numeric() }}) != 0 THEN
count(distinct {{ adapter.quote(column_name) }}) / cast(count(*) as {{ dbt.type_numeric() }})
ELSE 0 END
{%- else -%}
cast(null as {{ dbt.type_numeric() }})
{%- endif -%}
{%- endmacro -%}

{# measure_distinct_count ------------------------------------------------- #}

{%- macro measure_distinct_count(column_name, data_type) -%}
Expand Down Expand Up @@ -62,6 +80,14 @@ sum(case when {{ adapter.quote(column_name) }} is null then 0 else 1 end) / cast
{%- endif -%}
{%- endmacro -%}

{%- macro oracle__measure_is_unique(column_name, data_type) -%}
{%- if not dbt_profiler.is_struct_dtype(data_type) -%}
CASE WHEN count(distinct {{ adapter.quote(column_name) }}) = count(*) THEN 'Y' ELSE 'N' END
{%- else -%}
null
{%- endif -%}
{%- endmacro -%}

{%- macro sqlserver__measure_is_unique(column_name, data_type) -%}
case when count(distinct {{ adapter.quote(column_name) }}) = count(*) then 1 else 0 end
{%- endmacro -%}
Expand Down Expand Up @@ -183,7 +209,7 @@ case when count(distinct {{ adapter.quote(column_name) }}) = count(*) then 1 els

{%- endmacro -%}

{%- macro sql_server__measure_median(column_name, data_type, cte_name) -%}
{%- macro sqlserver__measure_median(column_name, data_type, cte_name) -%}

{%- if dbt_profiler.is_numeric_dtype(data_type) and not dbt_profiler.is_struct_dtype(data_type) -%}
percentile_cont({{ adapter.quote(column_name) }}, 0.5) over ()
Expand Down Expand Up @@ -246,4 +272,4 @@ case when count(distinct {{ adapter.quote(column_name) }}) = count(*) then 1 els
cast(null as {{ dbt.type_numeric() }})
{%- endif -%}

{%- endmacro -%}
{%- endmacro -%}
6 changes: 6 additions & 0 deletions macros/relation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@

{% do run_query("select top(0) * from " ~ relation ~ "") %}

{% endmacro %}

{% macro oracle__assert_relation_exists(relation) %}

{% do run_query("select * from " ~ relation ~ " where rownum < 0") %}

{% endmacro %}