Skip to content

Commit

Permalink
Add support for ODBC Server Side Parameters (#201)
Browse files Browse the repository at this point in the history
* Add support for ODBC Server Side Parameters

* Update CHANGELOG
  • Loading branch information
jethron authored Aug 11, 2021
1 parent da358d2 commit 3a66285
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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://github.com/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://github.com/dbt-labs/dbt-spark/pull/201))

### Contributors
- [@JCZuurmond](https://github.com/JCZuurmond) ([#192](https://github.com/fishtown-analytics/dbt-spark/pull/192))
- [@jethron](https://github.com/jethron) ([#201](https://github.com/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

0 comments on commit 3a66285

Please sign in to comment.