This repository has been archived by the owner on Mar 3, 2021. It is now read-only.
forked from norton120/dbt-mssql
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed issue jacobm001#6. This issue was caused by the `package_data` variable being setup incorrectly in `setup.py`. Apparently the file listing is **not** recursive, which caused the `sdist` files to lack several macro overrides needed to function. * Added a note about the ODBC driver As noted in issue jacobm001#5, the use of the `driver` variable was not particularly clear. I've added some info to try and explain that configuration better. * altered mssql__create_view_as macros Looks like this issue is being caused by the `mssql__create_view_as` macro. It works fine if the sql it's provided does not contain a CTE. If it does, sql server considers it a syntax error. This commit removes the parenthesis wrapping the `{{ sql }}` portion. * Fixed CTEs with insert into statements SQL Server's `insert into` syntax isn't nearly as forgiving as in other databases. In the previous version I had created a cte as apart of the into statement that could later be referenced. This worked so long as your source model didn't contain a CTE of its own. If it did, that put a CTE declaration inside another CTE which broke everything. I've taken a que from the dbt-sqlserver package and am now creating a "temporary" view to handle the issue. Thanks @mikaelene for the example. * incremented version number * Update README.md * updated .gitignore * delt with empty column names It appears that issue jacobm001#10 is caused by MSSQL not returning default column names for aggregate functions through the odbc library. When the `''` column name hits the agate library, an error is thrown. To handle this behavior, I've overridden the class method, `get_result_from_cursor()`. The new method loops through all the column names and replaces any instances of `''` with `unnamed_column-{i}`. This should provide a simple work around that the user doesn't really see, but is also very easy for the user to avoid if it's undesired behaivor. * incremented version * Update README.md * initial commit * added catalog * added work from https://github.com/norton120/dbt-azuredatawarehouse * moved to explicit varchar size per https://docs.microsoft.com/en-us/azure/sql-data-warehouse/sql-data-warehouse-tables-data-types * handle empty string column name from scalar * update README to match dockerfile * added sample profile.yml * clean up git conflict noise in readme * known issues in readme * added process_results class method and updated sql connection type Co-authored-by: Jacob Mastel <[email protected]> Co-authored-by: Isaac Chavez <[email protected]> Co-authored-by: Ethan Knox <[email protected]>
- Loading branch information
1 parent
1b91eb9
commit 2bc09cb
Showing
17 changed files
with
359 additions
and
332 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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
# Compiled python modules. | ||
*.pyc | ||
|
||
.idea | ||
# Setuptools distribution folder. | ||
/dist/ | ||
/build/ | ||
|
||
# Python egg metadata, regenerated from source files by setuptools. | ||
/*.egg-info | ||
.vscode/settings.json | ||
env/ | ||
|
||
## editor files | ||
*.swp | ||
.vscode/ |
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,47 +1,61 @@ | ||
# dbt-mssql | ||
# dbt-azuredw | ||
|
||
dbt-mssql is a custom adapter for [dbt](https://github.com/fishtown-analytics/dbt) that adds support for Microsoft SQL Server versions 2008 R2 and later. pyodbc is used as the connection driver as that is what is [suggested by Microsoft](https://docs.microsoft.com/en-us/sql/connect/python/python-driver-for-sql-server). The adapter supports both windows auth, and specified user accounts. | ||
dbt-azuredw is a custom adapter for [dbt](https://github.com/fishtown-analytics/dbt) that adds support for Azure SQL Data Warehouse.. pyodbc is used as the connection driver as that is what is [suggested by Microsoft](https://docs.microsoft.com/en-us/sql/connect/python/python-driver-for-sql-server). The adapter supports both windows auth, and specified user accounts. | ||
|
||
dbt-mssql is currently in a beta release. It is passing all of the [dbt integration tests](https://github.com/fishtown-analytics/dbt-integration-tests/) on SQL Server 2008 R2. Considering Microsoft's legendary backwards compatibility, it should work on newer versions, but that testing will come in the near future. | ||
dbt-azuredw is currently in a beta release. | ||
|
||
## Connecting to SQL Server | ||
## Connecting to Azure SQL Data Warehouse | ||
|
||
Your user profile (located in `~/.dbt/profile`) will need an appropriate entry for your package. | ||
## building your `profiles.yml` | ||
Use the profiles.yml file included as a guide, updating with your creds. You can find all the creds you need under _Home > dbname (account/dbname) - Connection strings_ in Azure, along with the username and password for authentication. | ||
|
||
Required parameters are: | ||
## Getting Started | ||
1. Run this to keep your profiles.yml from tracking: | ||
|
||
- driver | ||
- host | ||
- database | ||
- schema | ||
- one of the login options: | ||
- SQL Server authentication | ||
- username | ||
- password | ||
- Windows Login | ||
- windows_login: true | ||
``` | ||
git update-index --skip-worktree profiles.yml | ||
``` | ||
|
||
2. Update profiles.yml with your actual Azure Data Warehouse creds. | ||
3. Build the docker image. From the repo root: | ||
|
||
``` | ||
docker build . -t dbt-azure-dw | ||
``` | ||
|
||
4. Run a bash shell in the container: | ||
|
||
``` | ||
docker run -v $(PWD):/dbt_development/plugins -it dbt-azure-dw /bin/bash | ||
``` | ||
|
||
you can then jump into `jaffle_shop (mssql)` and work on making it run against your ADW! | ||
|
||
**Example profile:** | ||
|
||
The example below configures a seperate dev and prod environment for the package, _foo_. | ||
**Sample profiles.yml** | ||
|
||
```yaml | ||
foo: | ||
target: dev | ||
outputs: | ||
dev: | ||
type: mssql | ||
driver: 'ODBC Driver 17 for SQL Server' | ||
host: sqlserver.mydomain.com | ||
database: dbt_test | ||
schema: foo_dev | ||
windows_login: True | ||
prod: | ||
type: mssql | ||
driver: 'ODBC Driver 17 for SQL Server' | ||
host: sqlserver.mydomain.com | ||
database: dbt_test | ||
schema: foo | ||
username: dbt_user | ||
|
||
default: | ||
target: dev | ||
outputs: | ||
dev: | ||
type: azuredw | ||
driver: 'ODBC Driver 17 for SQL Server' | ||
host: account.database.windows.net | ||
database: dbt_test | ||
schema: foo | ||
username: dbt_user | ||
password: super_secret_dbt_password | ||
authentication: ActiveDirectoryPassword | ||
``` | ||
## Known Issues | ||
- At this time dbt-azuredw supports only `table`, `view` and `incremental` materializations (no `ephemeral`) | ||
- Only top-level (model) CTEs are supported, ie CTEs in macros are not supported (this is a sqlserver thing) | ||
|
||
|
||
|
||
## Jaffle Shop | ||
|
||
Fishtown Analytic's [jaffle shop](https://github.com/fishtown-analytics/jaffle_shop) package is currently unsupported by this adapter. At the time of this writing, jaffle shop uses the `using()` join, and `group by [ordinal]` notation which is not supported in T-SQL. An alternative version has been forked by the author of dbt-mssql [here](https://github.com/jacobm001/jaffle_shop_mssql). |
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,12 @@ | ||
from dbt.adapters.azuredw.connections import AzureDWConnectionManager | ||
from dbt.adapters.azuredw.connections import AzureDWCredentials | ||
from dbt.adapters.azuredw.impl import AzureDWAdapter | ||
|
||
from dbt.adapters.base import AdapterPlugin | ||
from dbt.include import azuredw | ||
|
||
|
||
Plugin = AdapterPlugin( | ||
adapter=AzureDWAdapter, | ||
credentials=AzureDWCredentials, | ||
include_path=azuredw.PACKAGE_PATH) |
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,14 +1,14 @@ | ||
from dbt.adapters.sql import SQLAdapter | ||
from dbt.adapters.mssql import MSSQLConnectionManager | ||
from dbt.adapters.azuredw import AzureDWConnectionManager | ||
|
||
|
||
class MSSQLAdapter(SQLAdapter): | ||
ConnectionManager = MSSQLConnectionManager | ||
class AzureDWAdapter(SQLAdapter): | ||
ConnectionManager = AzureDWConnectionManager | ||
|
||
@classmethod | ||
def date_function(cls): | ||
return 'get_date()' | ||
|
||
@classmethod | ||
def convert_text_type(cls, agate_table, col_idx): | ||
return 'varchar(max)' | ||
return 'varchar(8000)' |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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 @@ | ||
|
||
name: dbt_azuredw | ||
version: 0.0.1 | ||
|
||
macro-paths: ["macros"] |
Oops, something went wrong.