ashb commented on a change in pull request #4584: [AIRFLOW-3741] Add extra 
config to Oracle hook
URL: https://github.com/apache/airflow/pull/4584#discussion_r251025326
 
 

 ##########
 File path: airflow/hooks/oracle_hook.py
 ##########
 @@ -50,20 +50,61 @@ def get_conn(self):
         as in ``{ "dsn":"some.host.address" , 
"service_name":"some.service.name" }``
         """
         conn = self.get_connection(self.oracle_conn_id)
+        conn_config = {
+            'user': conn.login,
+            'password': conn.password or ''
+        }
         dsn = conn.extra_dejson.get('dsn', None)
         sid = conn.extra_dejson.get('sid', None)
         mod = conn.extra_dejson.get('module', None)
 
         service_name = conn.extra_dejson.get('service_name', None)
         if dsn and sid and not service_name:
-            dsn = cx_Oracle.makedsn(dsn, conn.port, sid)
-            conn = cx_Oracle.connect(conn.login, conn.password, dsn=dsn)
+            conn_config['dsn'] = cx_Oracle.makedsn(dsn, conn.port, sid)
         elif dsn and service_name and not sid:
-            dsn = cx_Oracle.makedsn(dsn, conn.port, service_name=service_name)
-            conn = cx_Oracle.connect(conn.login, conn.password, dsn=dsn)
+            conn_config['dsn'] = cx_Oracle.makedsn(dsn, conn.port, 
service_name=service_name)
         else:
-            conn = cx_Oracle.connect(conn.login, conn.password, conn.host)
+            conn_config['dsn'] = conn.host
 
+        if conn.extra_dejson.get('encoding', None):
+            conn_config['encoding'] = conn.extra_dejson.get('encoding')
+            # if `encoding` is specific but `nencoding` is not
+            # `nencoding` should use same values as `encoding` to set 
encoding, inspired by
+            # 
https://github.com/oracle/python-cx_Oracle/issues/157#issuecomment-371877993
+            if not conn.extra_dejson.get('nencoding', None):
+                conn_config['nencoding'] = conn.extra_dejson.get('encoding')
+        if conn.extra_dejson.get('nencoding', None):
+            conn_config['nencoding'] = conn.extra_dejson.get('nencoding')
+        mode = conn.extra_dejson.get('mode', None)
+        if mode:
+            if mode.lower() == 'sysdba':
+                conn_config['mode'] = cx_Oracle.SYSDBA
+            elif mode.lower() == 'sysasm':
+                conn_config['mode'] = cx_Oracle.SYSASM
+            elif mode.lower() == 'sysoper':
+                conn_config['mode'] = cx_Oracle.SYSOPER
+            elif mode.lower() == 'sysbkp':
+                conn_config['mode'] = cx_Oracle.SYSBKP
+            elif mode.lower() == 'sysdgd':
+                conn_config['mode'] = cx_Oracle.SYSDGD
+            elif mode.lower() == 'syskmt':
+                conn_config['mode'] = cx_Oracle.SYSKMT
+            elif mode.lower() == 'sysrac':
+                conn_config['mode'] = cx_Oracle.SYSRAC
+        if conn.extra_dejson.get('threaded', None):
+            conn_config['threaded'] = True
 
 Review comment:
   I wouldn't worry about that. More confusing would be a user specifying 
`"threaded": false` and have it turn on!
   
   Just document it (or point at the oracle docs) as boolean and keep it simple 
on our side

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to