Skip to content
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
38 changes: 28 additions & 10 deletions dbt/adapters/oracle/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import enum
import time
import uuid
import platform

import dbt.exceptions
from dbt.adapters.base import Credentials
Expand Down Expand Up @@ -113,6 +114,9 @@ class OracleAdapterCredentials(Credentials):
# Base URL for ADB-S OML REST API
oml_cloud_service_url: Optional[str] = None

# session info is stored in v$session for each dbt run
session_info: Optional[Dict[str, str]] = field(default_factory=dict)


_ALIASES = {
'dbname': 'database',
Expand All @@ -137,7 +141,8 @@ def _connection_keys(self) -> Tuple[str]:
'service', 'connection_string',
'shardingkey', 'supershardingkey',
'cclass', 'purity', 'retry_count',
'retry_delay', 'oml_cloud_service_url'
'retry_delay', 'oml_cloud_service_url',
'session_info'
)

@classmethod
Expand Down Expand Up @@ -175,6 +180,20 @@ def get_dsn(self) -> str:
class OracleAdapterConnectionManager(SQLConnectionManager):
TYPE = 'oracle'

@staticmethod
def get_session_info(credentials):
default_action = "DBT RUN"
default_client_identifier = f'dbt-oracle-client-{uuid.uuid4()}'
default_client_info = "_".join([platform.node(), platform.machine()])
default_module = f'dbt-{dbt_version}'
return {
"action": credentials.session_info.get("action", default_action),
"client_identifier": credentials.session_info.get("client_identifier", default_client_identifier),
"clientinfo": credentials.session_info.get("client_info", default_client_info),
"module": credentials.session_info.get("module", default_module)
}


@classmethod
def open(cls, connection):
if connection.state == 'open':
Expand Down Expand Up @@ -219,15 +238,14 @@ def open(cls, connection):

try:
handle = oracledb.connect(**conn_config)
# client_identifier and module are saved in corresponding columns in v$session
action = "dbt run"
client_identifier = f'dbt-oracle-client-{uuid.uuid4()}'
module = f'dbt-{dbt_version}'
client_info = {"action": action, "client_identifier": client_identifier, "module": module}
logger.info(f"Session info :{json.dumps(client_info)}")
handle.module = module
handle.client_identifier = client_identifier
handle.action = action
# session_info is stored in v$session
session_info = cls.get_session_info(credentials=credentials)
logger.info(f"Session info :{json.dumps(session_info)}")
for k, v in session_info.items():
try:
setattr(handle, k, v)
except AttributeError:
logger.warning(f"Python driver does not support setting {k}")
connection.handle = handle
connection.state = 'open'
except oracledb.DatabaseError as e:
Expand Down
10 changes: 10 additions & 0 deletions dbt_adbs_test_project/profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ dbt_test:
#database: "{{ env_var('DBT_ORACLE_DATABASE') }}"
schema: "{{ env_var('DBT_ORACLE_SCHEMA') }}"
oml_cloud_service_url: "{{ env_var('DBT_ORACLE_OML_CLOUD_SERVICE_URL')}}"
session_info:
action: "dbt run"
client_identifier: "dbt-mac-abhisoms"
client_info: "dbt Python3.9 thin driver"
module: "dbt-module-1.5.2"
retry_count: 1
retry_delay: 5
shardingkey:
Expand Down Expand Up @@ -42,6 +47,11 @@ dbt_test:
database: "{{ env_var('DBT_ORACLE_DATABASE') }}"
tns_name: "{{ env_var('DBT_ORACLE_TNS_NAME') }}"
schema: "{{ env_var('DBT_ORACLE_SCHEMA') }}"
session_info:
action: "dbt run"
client_identifier: "dbt-mac-abhisoms"
client_info: "dbt Python3.9 thin driver"
module: "dbt-module-1.5.2"
shardingkey:
- skey
supershardingkey:
Expand Down