diff --git a/.circleci/config.yml b/.circleci/config.yml index 3efe84aa..64d32051 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,6 +15,10 @@ jobs: MSSQL_IP_ADDRESS: 0.0.0.0 executor: python/default steps: + - run: &install-git + name: "TEMP: install Git" + command: | + apt-get install -y git - checkout - run: name: wait for SQL Server container to set up @@ -30,6 +34,7 @@ jobs: connection-sqlserver: <<: *sqlserver steps: + - run: *install-git - checkout - python/install-packages: pkg-manager: pip @@ -71,6 +76,7 @@ jobs: - image: dataders/pyodbc:1.4 executor: python/default steps: + - run: *install-git - checkout - python/install-packages: pkg-manager: pip @@ -87,6 +93,7 @@ jobs: - image: dataders/pyodbc:1.4 executor: python/default steps: + - run: *install-git - checkout - python/install-packages: pkg-manager: pip diff --git a/dbt/adapters/sqlserver/__version__.py b/dbt/adapters/sqlserver/__version__.py index 6a7765be..c5d79de0 100644 --- a/dbt/adapters/sqlserver/__version__.py +++ b/dbt/adapters/sqlserver/__version__.py @@ -1 +1 @@ -version = '0.18.1' \ No newline at end of file +version = '0.19.0rc2' \ No newline at end of file diff --git a/dbt/adapters/sqlserver/connections.py b/dbt/adapters/sqlserver/connections.py index 35027fab..cbb86905 100644 --- a/dbt/adapters/sqlserver/connections.py +++ b/dbt/adapters/sqlserver/connections.py @@ -10,6 +10,7 @@ import dbt.exceptions from dbt.adapters.base import Credentials from dbt.adapters.sql import SQLConnectionManager +from dbt.contracts.connection import AdapterResponse from azure.core.credentials import AccessToken from azure.identity import AzureCliCredential, DefaultAzureCredential @@ -258,6 +259,9 @@ def open(cls, connection): if getattr(credentials, "trust_cert", False) is True: con_str.append(f"TrustServerCertificate=Yes") + application_name = f"dbt-{credentials.type}" + con_str.append(f"APP={application_name}") + con_str_concat = ';'.join(con_str) index = [] @@ -347,7 +351,7 @@ def add_query(self, sql, auto_begin=True, bindings=None, abridge_sql_log=False): logger.debug( "SQL status: {} in {:0.2f} seconds".format( - self.get_status(cursor), (time.time() - pre) + self.get_response(cursor), (time.time() - pre) ) ) @@ -358,16 +362,26 @@ def get_credentials(cls, credentials): return credentials @classmethod - def get_status(cls, cursor): - if cursor.rowcount == -1: - status = "OK" - else: - status = str(cursor.rowcount) - return status + def get_response(cls, cursor) -> AdapterResponse: + #message = str(cursor.statusmessage) + message = 'OK' + rows = cursor.rowcount + #status_message_parts = message.split() if message is not None else [] + #status_messsage_strings = [ + # part + # for part in status_message_parts + # if not part.isdigit() + #] + #code = ' '.join(status_messsage_strings) + return AdapterResponse( + _message=message, + #code=code, + rows_affected=rows + ) def execute(self, sql, auto_begin=True, fetch=False): _, cursor = self.add_query(sql, auto_begin) - status = self.get_status(cursor) + status = self.get_response(cursor) if fetch: table = self.get_result_from_cursor(cursor) else: diff --git a/dbt/include/sqlserver/macros/materializations/snapshot/strategies.sql b/dbt/include/sqlserver/macros/materializations/snapshot/strategies.sql index 812f63fc..b728adb0 100644 --- a/dbt/include/sqlserver/macros/materializations/snapshot/strategies.sql +++ b/dbt/include/sqlserver/macros/materializations/snapshot/strategies.sql @@ -4,41 +4,3 @@ {% endfor %}), 2) {% endmacro %} -{% macro snapshot_check_strategy(node, snapshotted_rel, current_rel, config, target_exists) %} - {% set check_cols_config = config['check_cols'] %} - {% set primary_key = config['unique_key'] %} - {% set updated_at = snapshot_get_time() %} - - {% if check_cols_config == 'all' %} - {% set check_cols = get_columns_in_query(node['injected_sql']) %} - {% elif check_cols_config is iterable and (check_cols_config | length) > 0 %} - {% set check_cols = check_cols_config %} - {% else %} - {% do exceptions.raise_compiler_error("Invalid value for 'check_cols': " ~ check_cols_config) %} - {% endif %} - - {% set row_changed_expr -%} - ( - {% for col in check_cols %} - {{ snapshotted_rel }}.{{ col }} != {{ current_rel }}.{{ col }} - or - ( - (({{ snapshotted_rel }}.{{ col }} is null) and not ({{ current_rel }}.{{ col }} is null)) - or - ((not {{ snapshotted_rel }}.{{ col }} is null) and ({{ current_rel }}.{{ col }} is null)) - ) - {%- if not loop.last %} or {% endif %} - - {% endfor %} - ) - {%- endset %} - - {% set scd_id_expr = sqlserver__snapshot_hash_arguments([primary_key, updated_at]) %} - - {% do return({ - "unique_key": primary_key, - "updated_at": updated_at, - "row_changed": row_changed_expr, - "scd_id": scd_id_expr - }) %} -{% endmacro %} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3d44b029..ce397cdd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ -dbt-core~=0.18.0 +dbt-core==0.19.0rc2 pyodbc>=4.0.27 azure-identity>=1.4.0 black~=20.8b1 -pytest-dbt-adapter~=0.3.0 +pytest-dbt-adapter~=0.4.0 tox==3.2.0 flake8>=3.5.0 certifi==2020.6.20 diff --git a/setup.py b/setup.py index 6fdce2d3..996eeaaf 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ def _dbt_sqlserver_version(): package_version = _dbt_sqlserver_version() description = """A sqlserver adapter plugin for dbt (data build tool)""" -dbt_version = '0.18.1' +dbt_version = '0.19.0' # the package version should be the dbt version, with maybe some things on the # ends of it. (0.18.1 vs 0.18.1a1, 0.18.1.1, ...) if not package_version.startswith(dbt_version): @@ -56,5 +56,9 @@ def _dbt_sqlserver_version(): "include/sqlserver/macros/**/**/*.sql", ] }, - install_requires=["dbt-core~=0.18.0", "pyodbc>=4.0.27", "azure-identity>=1.4.0"], + install_requires=[ + 'dbt-core==0.19.0rc2', + "pyodbc>=4.0.27", + "azure-identity>=1.4.0", + ] ) \ No newline at end of file