Skip to content

Commit

Permalink
Merge pull request #9 from mpcarter/add-tests
Browse files Browse the repository at this point in the history
Add tests (in preparation for v1 upgrade)
  • Loading branch information
andyreagan authored Feb 11, 2022
2 parents ad9d315 + f58f239 commit 0e84ef9
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 28 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,27 @@ your-profile:
By default, `dbt-vertica` will request `ConnectionLoadBalance=true` (which is generally a good thing), and set a session label of `dbt_your-username`.

There are three options for SSL: `ssl`, `ssl_env_cafile`, and `ssl_uri`.
See their use in the code [here](https://github.com/mpcarter/dbt-vertica/blob/d15f925049dabd2833b4d88304edd216e3f654ed/dbt/adapters/vertica/connections.py#L72-L87).

## Reach out!

First off, I would not have been able to make this adapater if the smart folks at Fishtown Analytics didn't make it so easy. That said, it seems every database has its own little quirks. I ran into several different issues when adapting the macros to Vertica. If you find something not working right, please open an issue (assuming it has to do with the adapter and not dbt itself).

Also, I would be excited to hear about anyone who is able to benefit from using dbt with Vertica. (Just open an issue to leave me a comment.)

## Develop

Run a local Vertica instance like:

docker run -p 5433:5433 jbfavre/vertica:9.2.0-7_centos-7

You need the pytest dbt adapter:

pip3 install pytest-dbt-adapter==0.5.0

Run tests via:

pytest tests/integration.dbtspec
# run an individual test with increased logging:
pytest tests/integration.dbtspec::test_dbt_base -xs --ff
48 changes: 24 additions & 24 deletions dbt/include/vertica/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

{% macro vertica__drop_schema(relation) -%}
{% call statement('drop_schema') -%}
drop schema {{ relation.without_identifier().include(database=False) }} cascade
drop schema if exists {{ relation.without_identifier().include(database=False) }} cascade
{% endcall %}
{% endmacro %}

Expand Down Expand Up @@ -67,36 +67,36 @@

{% macro vertica__get_columns_in_relation(relation) -%}
{% call statement('get_columns_in_relation', fetch_result=True) %}
select
select
column_name
, data_type
, character_maximum_length
, numeric_precision
, character_maximum_length
, numeric_precision
, numeric_scale
from (
select
select
column_name
, data_type
, character_maximum_length
, numeric_precision
, numeric_scale
, ordinal_position
, character_maximum_length
, numeric_precision
, numeric_scale
, ordinal_position
from v_catalog.columns
where table_schema = '{{ relation.schema }}'
and table_name = '{{ relation.identifier }}'
union all
select
select
column_name
, data_type
, character_maximum_length
, numeric_precision
, numeric_scale
, ordinal_position
, character_maximum_length
, numeric_precision
, numeric_scale
, ordinal_position
from v_catalog.view_columns
where table_schema = '{{ relation.schema }}'
and table_name = '{{ relation.identifier }}'
) t
order by ordinal_position
order by ordinal_position
{% endcall %}
{% set table = load_result('get_columns_in_relation').table %}
{{ return(sql_convert_columns_in_relation(table)) }}
Expand Down Expand Up @@ -137,20 +137,20 @@

{% macro vertica__get_catalog(information_schema, schemas) -%}
{% call statement('get_catalog', fetch_result=True) %}
select

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.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
join v_catalog.columns col on tab.table_id = col.table_id
left join v_catalog.comments on tab.table_id = object_id
where not(tab.is_system_table) and
(
Expand All @@ -159,28 +159,28 @@
{%- endfor -%}
)
union all
select
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.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
join v_catalog.view_columns col on vw.table_id = col.table_id
left join v_catalog.comments on vw.table_id = object_id
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
order by table_schema, table_name, column_index

{% endcall %}
{{ return(load_result('get_catalog').table) }}
{% endmacro %}
Expand Down
13 changes: 9 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pathlib

package_name = "dbt-vertica"
package_version = "0.21.0"
package_version = "0.21.1"
description = """The vertica adapter plugin for dbt (data build tool)"""

HERE = pathlib.Path(__file__).parent
Expand All @@ -19,7 +19,7 @@
license='MIT',
author='Matthew Carter (original), Andrew Hedengren, Andy Reagan',
author_email='[email protected], [email protected]',
url='https://github.com/andyreagan/dbt-vertica',
url='https://github.com/mpcarter/dbt-vertica',
packages=find_packages(),
package_data={
'dbt': [
Expand All @@ -29,7 +29,12 @@
]
},
install_requires=[
'dbt-core>=0.21.0',
'dbt-core>=0.21.0,<1.0.0',
'vertica-python>=0.10.0',
]
],
extras_require={
'dev': [
'pytest-dbt-adapter==0.5.0',
]
}
)
19 changes: 19 additions & 0 deletions tests/integration.dbtspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
target:
type: vertica
host: localhost
username: dbadmin
password: ''
database: docker
schema: "dbt_test_{{ var('_dbt_random_suffix') }}"
port: 5433
threads: 1
sequences:
test_dbt_empty: empty
test_dbt_base: base
test_dbt_ephemeral: ephemeral
# test_dbt_incremental: incremental
# test_dbt_snapshot_strategy_timestamp: snapshot_strategy_timestamp
# test_dbt_snapshot_strategy_check_cols: snapshot_strategy_check_cols
test_dbt_data_test: data_test
test_dbt_schema_test: schema_test
test_dbt_ephemeral_data_tests: data_test_ephemeral_models
5 changes: 5 additions & 0 deletions tests/unit/test_connections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dbt.adapters.vertica import *


def test_empty() -> None:
pass

0 comments on commit 0e84ef9

Please sign in to comment.