Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ODBC Server Side Parameters #201

Merged
merged 3 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

### Fixes
- Add pyodbc import error message to dbt.exceptions.RuntimeException to get more detailed information when running `dbt debug` ([#192](https:/dbt-labs/dbt-spark/pull/192))
- Add support for ODBC Server Side Parameters, allowing options that need to be set with the `SET` statement to be used ([#201](https:/dbt-labs/dbt-spark/pull/201))

### Contributors
- [@JCZuurmond](https:/JCZuurmond) ([#192](https:/fishtown-analytics/dbt-spark/pull/192))
- [@jethron](https:/jethron) ([#201](https:/fishtown-analytics/dbt-spark/pull/201))

## dbt-spark 0.21.0b1 (August 3, 2021)

Expand Down
13 changes: 11 additions & 2 deletions dbt/adapters/spark/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import sqlparams

from hologram.helpers import StrEnum
from dataclasses import dataclass
from typing import Optional
from dataclasses import dataclass, field
from typing import Any, Dict, Optional
try:
from thrift.transport.TSSLSocket import TSSLSocket
import thrift
Expand Down Expand Up @@ -72,6 +72,7 @@ class SparkCredentials(Credentials):
connect_retries: int = 0
connect_timeout: int = 10
use_ssl: bool = False
server_side_parameters: Dict[str, Any] = field(default_factory=dict)

@classmethod
def __pre_deserialize__(cls, data):
Expand Down Expand Up @@ -405,6 +406,12 @@ def open(cls, connection):
dbt_spark_version = __version__.version
user_agent_entry = f"fishtown-analytics-dbt-spark/{dbt_spark_version} (Databricks)" # noqa

# http://simba.wpengine.com/products/Spark/doc/ODBC_InstallGuide/unix/content/odbc/hi/configuring/serverside.htm
ssp = {
f"SSP_{k}": f"{{{v}}}"
for k, v in creds.server_side_parameters.items()
}

# https://www.simba.com/products/Spark/doc/v2/ODBC_InstallGuide/unix/content/odbc/options/driver.htm
connection_str = _build_odbc_connnection_string(
DRIVER=creds.driver,
Expand All @@ -418,6 +425,8 @@ def open(cls, connection):
ThriftTransport=2,
SSL=1,
UserAgentEntry=user_agent_entry,
LCaseSspKeyName=0 if ssp else 1,
**ssp,
)

conn = pyodbc.connect(connection_str, autocommit=True)
Expand Down