Skip to content

Commit

Permalink
adding
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachin-Thakur committed Dec 15, 2023
1 parent b16f518 commit 565f207
Show file tree
Hide file tree
Showing 10 changed files with 1,931 additions and 48 deletions.
75 changes: 37 additions & 38 deletions dbt/include/vertica/macros/adapters/catalog.sql
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
{% 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 (
),
columns as (
{{ vertica__get_catalog_columns_sql(information_schema) }}
{{ vertica__get_catalog_schemas_where_clause_sql(schemas) }}

)
vertica__get_catalog_results_sql()

{{vertica__get_catalog_results_sql ()}}

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



{%- endmacro %}


Expand All @@ -30,14 +34,13 @@
with tables as (
{{ vertica__get_catalog_tables_sql(information_schema) }}
{{ vertica__get_catalog_relations_where_clause_sql(relations) }}
),
column as (
),
columns as (
{{ vertica__get_catalog_columns_sql(information_schema) }}
{{ vertica__get_catalog_relations_where_clause_sql(relations) }}

)
vertica__get_catalog_results_sql()

{{vertica__get_catalog_results_sql ()}}
{%- endset -%}

{{ return(run_query(query)) }}
Expand All @@ -52,7 +55,7 @@


{% macro vertica__get_catalog_tables_sql(information_schema) -%}
select * from (
select
'{{ information_schema.database }}' table_database
, tab.table_schema
Expand Down Expand Up @@ -83,46 +86,42 @@
join v_catalog.view_columns col on vw.table_id = col.table_id
left join v_catalog.comments on vw.table_id = object_id


) anything
{%- 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
select * from ( select
'{{ information_schema.database }}' table_database ,
table_schema
,table_name,
column_name
, ordinal_position column_index
, data_type column_type


from v_catalog.columns

union all

select
'{{ information_schema.database }}' table_database ,
table_schema
,table_name
, column_name
, ordinal_position column_index
, data_type column_type

from v_catalog.view_columns
) y
{%- endmacro %}

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

{%- endmacro %}

{% macro vertica__get_catalog_schemas_where_clause_sql(schemas) -%}
Expand Down
18 changes: 8 additions & 10 deletions dbt/include/vertica/macros/materializations/clone.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@



{% macro vertica__can_clone_table() %}
{{ return(True) }}
{% endmacro %}


{% macro vertica__create_or_replace_clone(this_relation, defer_relation) %}


DROP TABLE IF EXISTS {{this_relation}};
create table
{{ this_relation }} as select * from
{{ defer_relation }}



SELECT COPY_TABLE ( {{ "'"+defer_relation|replace('"','')+"'"}}, {{ "'"+this_relation|replace('"','')+"'"}} );


{% endmacro %}
46 changes: 46 additions & 0 deletions dbt/include/vertica/macros/utils/date_spine.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% macro vertica__date_spine(datepart, start_date, end_date) %}


{# call as follows:

date_spine(
"day",
"to_date('01/01/2016', 'mm/dd/yyyy')",
"dbt.dateadd(week, 1, current_date)"
) #}


with rawdata as (

{{dbt_utils.generate_series(
dbt_utils.get_intervals_between(start_date, end_date, datepart)
)}}

),

all_periods as (

select (
{{
dbt.dateadd(
datepart,
"row_number() over (order by 1) - 1",
"cast(cast(" ~ start_date ~ " as date) as timestamp)"
)
}}
) as date_{{datepart}}
from rawdata

),

filtered as (

select *
from all_periods
where date_{{datepart}} <= cast(cast({{ end_date }} as date) as timestamp)

)

select * from filtered

{% endmacro %}
13 changes: 13 additions & 0 deletions tests/functional/adapter/dbt-show/test_dbt_show.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@



from dbt.tests.adapter.dbt_show.test_dbt_show import BaseShowSqlHeader, BaseShowLimit


#pass
class TestVerticaShowLimit(BaseShowLimit):
pass

#pass
class TestVerticaShowSqlHeader(BaseShowSqlHeader):
pass
12 changes: 12 additions & 0 deletions tests/functional/adapter/dbt_clone/test_dbt_target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@



from dbt.tests.adapter.dbt_clone.test_dbt_clone import TestCloneSameTargetAndState


import pytest

#pass
class TestVerticaCloneSameTargetAndState(TestCloneSameTargetAndState):
pass

Loading

0 comments on commit 565f207

Please sign in to comment.