Skip to content

Commit 745b53f

Browse files
authored
Merge pull request #115 from oracle/bugxfix-1.6/110
Custom `session_info` in dbt profile
2 parents 7a1176b + f428194 commit 745b53f

File tree

10 files changed

+52
-17
lines changed

10 files changed

+52
-17
lines changed

.github/workflows/oracle-xe-adapter-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- name: Install dbt-oracle with core dependencies
4949
run: |
5050
python -m pip install --upgrade pip
51-
pip install pytest dbt-tests-adapter~=1.6
51+
pip install pytest 'dbt-tests-adapter~=1.6,<1.7'
5252
pip install -r requirements.txt
5353
pip install -e .
5454

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Configuration variables
2-
VERSION=1.6.0
2+
VERSION=1.6.1
33
PROJ_DIR?=$(shell pwd)
44
VENV_DIR?=${PROJ_DIR}/.bldenv
55
BUILD_DIR=${PROJ_DIR}/build

dbt/adapters/oracle/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17-
version = "1.6.0"
17+
version = "1.6.7"

dbt/adapters/oracle/connections.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
from typing import List, Optional, Tuple, Any, Dict, Union
1818
from contextlib import contextmanager
1919
from dataclasses import dataclass, field
20+
import json
2021
import enum
2122
import time
2223
import uuid
24+
import platform
2325

2426
import dbt.exceptions
2527
from dbt.adapters.base import Credentials
@@ -112,6 +114,9 @@ class OracleAdapterCredentials(Credentials):
112114
# Base URL for ADB-S OML REST API
113115
oml_cloud_service_url: Optional[str] = None
114116

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

116121
_ALIASES = {
117122
'dbname': 'database',
@@ -136,7 +141,8 @@ def _connection_keys(self) -> Tuple[str]:
136141
'service', 'connection_string',
137142
'shardingkey', 'supershardingkey',
138143
'cclass', 'purity', 'retry_count',
139-
'retry_delay', 'oml_cloud_service_url'
144+
'retry_delay', 'oml_cloud_service_url',
145+
'session_info'
140146
)
141147

142148
@classmethod
@@ -174,6 +180,19 @@ def get_dsn(self) -> str:
174180
class OracleAdapterConnectionManager(SQLConnectionManager):
175181
TYPE = 'oracle'
176182

183+
@staticmethod
184+
def get_session_info(credentials):
185+
default_action = "DBT RUN"
186+
default_client_identifier = f'dbt-oracle-client-{uuid.uuid4()}'
187+
default_client_info = "_".join([platform.node(), platform.machine()])
188+
default_module = f'dbt-{dbt_version}'
189+
return {
190+
"action": credentials.session_info.get("action", default_action),
191+
"client_identifier": credentials.session_info.get("client_identifier", default_client_identifier),
192+
"clientinfo": credentials.session_info.get("client_info", default_client_info),
193+
"module": credentials.session_info.get("module", default_module)
194+
}
195+
177196
@classmethod
178197
def open(cls, connection):
179198
if connection.state == 'open':
@@ -219,8 +238,14 @@ def open(cls, connection):
219238
try:
220239
handle = oracledb.connect(**conn_config)
221240
# client_identifier and module are saved in corresponding columns in v$session
222-
handle.module = f'dbt-{dbt_version}'
223-
handle.client_identifier = f'dbt-oracle-client-{uuid.uuid4()}'
241+
session_info = cls.get_session_info(credentials=credentials)
242+
logger.info(f"Session info :{json.dumps(session_info)}")
243+
for k, v in session_info.items():
244+
try:
245+
setattr(handle, k, v)
246+
except AttributeError:
247+
logger.warning(f"Python driver does not support setting {k}")
248+
224249
connection.handle = handle
225250
connection.state = 'open'
226251
except oracledb.DatabaseError as e:

dbt_adbs_test_project/profiles.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ dbt_test:
1212
#database: "{{ env_var('DBT_ORACLE_DATABASE') }}"
1313
schema: "{{ env_var('DBT_ORACLE_SCHEMA') }}"
1414
oml_cloud_service_url: "{{ env_var('DBT_ORACLE_OML_CLOUD_SERVICE_URL')}}"
15+
session_info:
16+
action: "dbt run"
17+
client_identifier: "dbt-mac-abhisoms"
18+
client_info: "dbt Python3.9 thin driver"
19+
module: "dbt-module-1.5.2"
1520
retry_count: 1
1621
retry_delay: 5
1722
shardingkey:
@@ -42,6 +47,11 @@ dbt_test:
4247
database: "{{ env_var('DBT_ORACLE_DATABASE') }}"
4348
tns_name: "{{ env_var('DBT_ORACLE_TNS_NAME') }}"
4449
schema: "{{ env_var('DBT_ORACLE_SCHEMA') }}"
50+
session_info:
51+
action: "dbt run"
52+
client_identifier: "dbt-mac-abhisoms"
53+
client_info: "dbt Python3.9 thin driver"
54+
module: "dbt-module-1.5.2"
4555
shardingkey:
4656
- skey
4757
supershardingkey:

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
dbt-core~=1.6
1+
dbt-core~=1.6,<1.7
22
cx_Oracle==8.3.0
3-
oracledb==1.4.1
3+
oracledb==1.4.2

requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ tox
66
coverage
77
twine
88
pytest
9-
dbt-tests-adapter~=1.6
9+
dbt-tests-adapter~=1.6,<1.7

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = dbt-oracle
3-
version = 1.6.0
3+
version = 1.6.1
44
description = dbt (data build tool) adapter for the Oracle database
55
long_description = file: README.md
66
long_description_content_type = text/markdown
@@ -32,9 +32,9 @@ zip_safe = False
3232
packages = find_namespace:
3333
include_package_data = True
3434
install_requires =
35-
dbt-core~=1.6
35+
dbt-core~=1.6,<1.7
3636
cx_Oracle==8.3.0
37-
oracledb==1.4.1
37+
oracledb==1.4.2
3838
test_suite=tests
3939
test_requires =
4040
dbt-tests-adapter~=1.6

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040

4141

4242
requirements = [
43-
"dbt-core~=1.6",
43+
"dbt-core~=1.6,<1.7",
4444
"cx_Oracle==8.3.0",
45-
"oracledb==1.4.1"
45+
"oracledb==1.4.2"
4646
]
4747

4848
test_requirements = [
49-
"dbt-tests-adapter~=1.6",
49+
"dbt-tests-adapter~=1.6,<1.7",
5050
"pytest"
5151
]
5252

@@ -60,7 +60,7 @@
6060

6161
url = 'https://github.com/oracle/dbt-oracle'
6262

63-
VERSION = '1.6.0'
63+
VERSION = '1.6.1'
6464
setup(
6565
author="Oracle",
6666
python_requires='>=3.8',

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ passenv =
1515

1616
deps =
1717
-rrequirements.txt
18-
dbt-tests-adapter~=1.6
18+
dbt-tests-adapter~=1.6,<1.7
1919
pytest
2020

2121
commands = pytest

0 commit comments

Comments
 (0)