Skip to content

Commit

Permalink
adding
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachin-Thakur committed Dec 8, 2023
1 parent 25d922c commit b16f518
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 3 deletions.
170 changes: 170 additions & 0 deletions dbt/include/vertica/macros/adapters/catalog.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{% macro vertica__get_catalog(information_schema, schemas) -%}

{% set query %}

with tables as (
{{ vertica__get_catalog_tables_sql(information_schema) }}
{{ vertica__get_catalog_schemas_where_clause_sql(schemas) }}
),
column as (
{{ vertica__get_catalog_columns_sql(information_schema) }}
{{ vertica__get_catalog_schemas_where_clause_sql(schemas) }}

)
vertica__get_catalog_results_sql()

{%- endset -%}
{{ return(run_query(query)) }}

{%- endmacro %}






{% macro vertica__get_catalog_relations(information_schema, relations) -%}
{% set query %}


with tables as (
{{ vertica__get_catalog_tables_sql(information_schema) }}
{{ vertica__get_catalog_relations_where_clause_sql(relations) }}
),
column as (
{{ vertica__get_catalog_columns_sql(information_schema) }}
{{ vertica__get_catalog_relations_where_clause_sql(relations) }}

)
vertica__get_catalog_results_sql()

{%- endset -%}

{{ return(run_query(query)) }}

{%- endmacro %}








{% macro vertica__get_catalog_tables_sql(information_schema) -%}

select
'{{ information_schema.database }}' table_database
, tab.table_schema
, tab.table_name
, 'TABLE' table_type
, comment table_comment
, tab.owner_name table_owner
, col.column_name
, col.ordinal_position column_index
, col.data_type column_type
, nullif('','') column_comment
from v_catalog.tables tab
join v_catalog.columns col on tab.table_id = col.table_id
left join v_catalog.comments on tab.table_id = object_id
union all
select
'{{ information_schema.database }}' table_database
, vw.table_schema
, vw.table_name
, 'VIEW' table_type
, comment table_comment
, vw.owner_name table_owner
, col.column_name
, col.ordinal_position column_index
, col.data_type column_type
, nullif('','') column_comment
from v_catalog.views vw
join v_catalog.view_columns col on vw.table_id = col.table_id
left join v_catalog.comments on vw.table_id = object_id


{%- endmacro %}



{% macro vertica__get_catalog_columns_sql(information_schema) -%}
select
'{{ information_schema.database }}' table_database
, tab.table_schema as "table_schema"
, tab.table_name
, 'TABLE' table_type
, comment table_comment
, tab.owner_name table_owner
, col.column_name
, col.ordinal_position column_index
, col.data_type column_type
, nullif('','') column_comment
from {{ information_schema }}.columns

union all

select
'{{ information_schema.database }}' table_database
, vw.table_schema
, vw.table_name
, 'VIEW' table_type
, comment table_comment
, vw.owner_name table_owner
, col.column_name
, col.ordinal_position column_index
, col.data_type column_type
, nullif('','') column_comment
from v_catalog.views vw
{%- endmacro %}

{% macro vertica__get_catalog_results_sql() -%}
select *
from tables
join columns using ("table_database", "table_schema", "table_name")
order by "column_index"
{%- endmacro %}

{% macro vertica__get_catalog_schemas_where_clause_sql(schemas) -%}
where not(tab.is_system_table) and
(
{%- for schema in schemas -%}
lower(tab.table_schema) = lower('{{ schema }}') {%- if not loop.last %} or {% endif %}
{%- endfor -%}
)
where not(vw.is_system_view) and


(
{%- for schema in schemas -%}
lower(vw.table_schema) = lower('{{ schema }}') {%- if not loop.last %} or {% endif %}
{%- endfor -%}
)

order by table_schema, table_name, column_index

{%- endmacro %}


{% macro vertica__get_catalog_relations_where_clause_sql(relations) -%}
where (
{%- for relation in relations -%}
{% if relation.schema and relation.identifier %}
(
upper("table_schema") = upper('{{ relation.schema }}')
and upper("table_name") = upper('{{ relation.identifier }}')
)
{% elif relation.schema %}
(
upper("table_schema") = upper('{{ relation.schema }}')
)
{% else %}
{% do exceptions.raise_compiler_error(
'`get_catalog_relations` requires a list of relations, each with a schema'
) %}
{% endif %}

{%- if not loop.last %} or {% endif -%}
{%- endfor -%}
)
{%- endmacro %}
6 changes: 3 additions & 3 deletions dbt/include/vertica/macros/adapters/metadata.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% macro vertica__get_catalog(information_schema, schemas) -%}
{% call statement('get_catalog', fetch_result=True) %}
{% macro d__get_catalog99(information_schema, schemas) -%}
{% call statement('get_catalog99', fetch_result=True) %}

select
'{{ information_schema.database }}' table_database
Expand Down Expand Up @@ -45,7 +45,7 @@
order by table_schema, table_name, column_index

{% endcall %}
{{ return(load_result('get_catalog').table) }}
{{ return(load_result('get_catalog00').table) }}
{% endmacro %}


Expand Down

0 comments on commit b16f518

Please sign in to comment.