generated from brabster/dbt_bigquery_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Roll in updates from template, clean up documentation, add example qu…
…ery and associated contract test
- Loading branch information
Showing
9 changed files
with
152 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
PIP_REQUIRE_VIRTUALENV=true # have pip abort if we try to install outside a venv | ||
PROJECT_DIR=$(dirname "$0")/.. # script directory | ||
VENV_PATH=${PROJECT_DIR}/.venv | ||
IS_RUNNING_IN_VENV="$(python -c 'import sys; print(sys.prefix != sys.base_prefix)')" | ||
|
||
if [ "${IS_RUNNING_IN_VENV}" == 'False' ]; then | ||
echo 'Not in virtualenv, setting up'; | ||
python -m venv ${VENV_PATH} | ||
source ${VENV_PATH}/bin/activate | ||
fi | ||
|
||
echo "install or upgrade system packages" | ||
pip install --upgrade pip setuptools | ||
|
||
echo "install safety for vulnerability check; it prints its own messages about noncommercial use" | ||
pip install --upgrade safety | ||
|
||
echo "install or upgrade project-specific dependencies" | ||
pip install -U -r ${PROJECT_DIR}/requirements.txt | ||
|
||
echo "install or upgrade dbt dependencies" | ||
dbt deps | ||
|
||
echo "check for vulnerabilities" | ||
safety check | ||
|
||
echo "load user environment, if present" | ||
ENV_PATH=${PROJECT_DIR}/.env | ||
if [ -f "${ENV_PATH}" ]; then | ||
source ${ENV_PATH} | ||
echo "check dbt setup" | ||
dbt debug | ||
else | ||
echo "Unable to check dbt setup until .env file is set up and suitable data warehouse credentials are available" | ||
fi | ||
|
||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,15 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "ensure_pip_version", | ||
"type": "shell", | ||
"command": "pip install --upgrade pip" | ||
}, | ||
{ | ||
"label": "ensure_python_deps_updated", | ||
"type": "shell", | ||
"command": "pip install -U -r ${workspaceFolder}/requirements.txt" | ||
}, | ||
{ | ||
"label": "load_user_env", | ||
"type": "shell", | ||
"command": ". ${workspaceFolder}/.env" | ||
}, | ||
{ | ||
"label": "ensure_dbt_packages_updated", | ||
"type": "shell", | ||
"command": "dbt", | ||
"args": ["deps", "--upgrade"], | ||
"dependsOn": ["ensure_python_deps_updated", "load_user_env"] | ||
}, | ||
{ | ||
"label": "ensure_updated", | ||
"dependsOn": [ | ||
"ensure_pip_version", | ||
"ensure_python_deps_updated", | ||
"ensure_dbt_packages_updated" | ||
], | ||
"runOptions": { | ||
"runOn": "folderOpen" | ||
} | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "init_and_update", | ||
"type": "shell", | ||
"command": "${workspaceFolder}/.dev_scripts/init_and_update.sh", | ||
"runOptions": { | ||
"runOn": "folderOpen" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
version: 2 | ||
|
||
macros: | ||
- name: ensure_target_dataset_exists | ||
description: Creates the specified dataset if it does not exist and the executor has permission |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
version: 2 | ||
|
||
macros: | ||
- name: ensure_udfs | ||
description: Creates UDFs specified in the macro. Does not clean up any UDFs that are removed. |
15 changes: 15 additions & 0 deletions
15
tests/contracts/docs/assert_top_ten_packages_by_vulnerable_downloads.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
WITH test AS ( | ||
SELECT | ||
package, | ||
downloads_with_known_vulnerabilities, | ||
downloads_without_known_vulnerabilities, | ||
proportion_vulnerable_downloads | ||
FROM `pypi-vulnerabilities.pypi_vulnerabilities_us.vulnerable_downloads_by_package` | ||
ORDER BY downloads_with_known_vulnerabilities DESC | ||
LIMIT 10 | ||
) | ||
|
||
SELECT | ||
COUNT(1) row_count | ||
FROM test | ||
HAVING row_count != 10 |