Skip to content

Commit

Permalink
Support Postgres (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwreeves committed Oct 28, 2023
1 parent fbb61d8 commit 8d42ab9
Show file tree
Hide file tree
Showing 47 changed files with 229 additions and 97 deletions.
66 changes: 40 additions & 26 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,47 @@ on:
branches:
- main
jobs:
test:
test-duckdb:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
dbt_core: [1.3.*, 1.4.*, 1.5.*, 1.6.*]
dbt_core: [1.4.*, 1.6.*]
db_target: [dbt-duckdb, dbt-postgres]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: "3.10"
architecture: x64
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install
chmod +x ./run
./run setup
pip install -U "dbt-core==$DBT_CORE_VERSION" "dbt-duckdb"
env:
DBT_CORE_VERSION: ${{ matrix.dbt_core }}
- name: Lint
run: ./run lint
- name: Test
run: ./run test
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: "3.10"
architecture: x64
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install
chmod +x ./run
./run setup
pip install -U "dbt-core==$DBT_CORE_VERSION" "${DBT_PROVIDER_PACKAGE}"
env:
DBT_CORE_VERSION: ${{ matrix.dbt_core }}
DBT_PROVIDER_PACKAGE: ${{ matrix.db_target }}
- name: Lint
run: ./run lint
- name: Test
run: ./run test "${DBT_TARGET}"
env:
DBT_TARGET: ${{ matrix.db_target }}
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ repos:
hooks:
- id: shellcheck
args: [-x, run]

- repo: https://github.com/rhysd/actionlint
rev: v1.6.26
hooks:
- id: actionlint
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### `0.2.3`

- Added Postgres support in integration tests + fixed bugs that prevented Postgres from working.

### `0.2.2`

- Added dbt documentation of the `ols()` macro.
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Add this the `packages:` list your dbt project's `packages.yml`:

```yaml
- package: "dwreeves/dbt_linreg"
version: "0.2.2"
version: "0.2.3"
```
The full file will look something like this:
Expand All @@ -41,7 +41,7 @@ packages:
# Other packages here
# ...
- package: "dwreeves/dbt_linreg"
version: "0.2.2"
version: "0.2.3"
```
# Examples
Expand All @@ -64,7 +64,7 @@ select * from {{
format='long',
format_options={'round': 5}
)
}}
}} as linreg
```

Output:
Expand Down Expand Up @@ -168,6 +168,7 @@ group by
**dbt_linreg** should work with most SQL databases, but so far, testing has been done for the following database tools:

- Snowflake
- Postgres
- DuckDB

If `dbt_linreg` does not work in your database tool, please let me know in a bug report and I can make sure it is supported.
Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "dbt_linreg"
version: "0.2.2"
version: "0.2.3"

# 1.2 is required because of modules.itertools.
require-dbt-version: [">=1.2.0", "<2.0.0"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
add_constant=False
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ select * from {{
format='long',
add_constant=False
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
add_constant=False
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
add_constant=False
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
add_constant=False
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
add_constant=False
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ select * from {{
format='long',
add_constant=False
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
method='chol'
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ select * from {{
method='chol',
method_options={'subquery_optimization': False}
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
method='fwl'
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ select * from {{
alpha=0.01,
method='chol'
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ select * from {{
method='chol',
method_options={'subquery_optimization': False}
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ select * from {{
alpha=0.01,
method='fwl'
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/groups_matrix_regression_chol.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ select * from {{
format='long',
method='chol'
)
}}
}} as linreg
order by gb_var, variable_name
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ select * from {{
method='chol',
method_options={'subquery_optimization': False}
)
}}
}} as linreg
order by gb_var, variable_name
2 changes: 1 addition & 1 deletion integration_tests/models/groups_matrix_regression_fwl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ select * from {{
format='long',
method='fwl'
)
}}
}} as linreg
order by gb_var, variable_name
4 changes: 2 additions & 2 deletions integration_tests/models/long_format_options.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ select
'strip_quotes': True
}
)
}}
}} as linreg1

union all

Expand All @@ -37,4 +37,4 @@ select
'strip_quotes': False
}
)
}}
}} as linreg2
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ select * from {{
endog='y',
exog=['xa', 'xb']
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
format_options={'round': 5}
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
format_options={'round': 5}
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/simple_0var_regression_wide.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='wide',
format_options={'round': 5}
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/simple_10var_regression_long.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ select * from {{
format='long',
format_options={'round': 5}
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
format_options={'round': 5}
)
}}
}} as linreg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
format_options={'round': 5}
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/simple_1var_regression_wide.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='wide',
format_options={'round': 5}
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/simple_2var_regression_long.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
format_options={'round': 5}
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/simple_2var_regression_wide.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='wide',
format_options={'round': 5}
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/simple_3var_regression_long.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
format_options={'round': 5}
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/simple_3var_regression_wide.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='wide',
format_options={'round': 5}
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/simple_4var_regression_long.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
format_options={'round': 5}
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/simple_4var_regression_wide.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='wide',
format_options={'round': 5}
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/simple_5var_regression_long.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='long',
format_options={'round': 5}
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/simple_5var_regression_wide.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ select * from {{
format='wide',
format_options={'round': 5}
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/simple_8var_regression_wide.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ select * from {{
exog=['xa', 'xb', 'xc', 'xd', 'xe', 'xf', 'xg', 'xh'],
format='wide',
)
}}
}} as linreg
2 changes: 1 addition & 1 deletion integration_tests/models/wide_format_options.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ select
'constant_name': 'constant_term'
}
)
}}
}} as linreg
21 changes: 14 additions & 7 deletions integration_tests/profiles/profiles.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
dbt_linreg_profile:
target: dev
target: dbt-duckdb
outputs:
dev:
type: duckdb
path: dbt.duckdb
dev-memory:
type: duckdb
path: ":memory:"
dbt-duckdb:
type: duckdb
path: dbt.duckdb
dbt-postgres:
# This is configured for Github Actions.
# For local configuration, set env vars.
type: postgres
user: '{{ env_var("POSTGRES_USER", "postgres") }}'
password: '{{ env_var("POSTGRES_PASSWORD", "postgres") }}'
host: '{{ env_var("POSTGRES_HOST", "postgres") }}'
port: '{{ env_var("POSTGRES_PORT", "5432") | as_number }}'
dbname: '{{ env_var("POSTGRES_DB", "postgres") }}'
schema: '{{ env_var("POSTGRES_SCHEMA", "public") }}'
Loading

0 comments on commit 8d42ab9

Please sign in to comment.