airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject incubator-airflow git commit: [AIRFLOW-926] Fix JDBC Hook
Date Sun, 22 Oct 2017 18:05:00 GMT
Repository: incubator-airflow
Updated Branches:
  refs/heads/master cd3ad3f2e -> 21257e8f0


[AIRFLOW-926] Fix JDBC Hook

JayDeBeApi made a backwards incompatible change
This updates the JDBC Hook's implementation
and changes the required JayDeBeApi to >= 1.1.1

Closes #2651 from r-richmond/AIRFLOW-926


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/21257e8f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/21257e8f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/21257e8f

Branch: refs/heads/master
Commit: 21257e8f0643335d09c41f324c1d83ad1a8fc485
Parents: cd3ad3f
Author: r-richmond <rrichmond.gh@gmail.com>
Authored: Sun Oct 22 20:04:26 2017 +0200
Committer: Bolke de Bruin <bolke@xs4all.nl>
Committed: Sun Oct 22 20:04:30 2017 +0200

----------------------------------------------------------------------
 airflow/hooks/jdbc_hook.py            |  7 ++--
 setup.py                              |  2 +-
 tests/contrib/hooks/test_jdbc_hook.py | 51 ++++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/21257e8f/airflow/hooks/jdbc_hook.py
----------------------------------------------------------------------
diff --git a/airflow/hooks/jdbc_hook.py b/airflow/hooks/jdbc_hook.py
index bc1f352..dcc6cd2 100644
--- a/airflow/hooks/jdbc_hook.py
+++ b/airflow/hooks/jdbc_hook.py
@@ -52,9 +52,10 @@ class JdbcHook(DbApiHook):
         jdbc_driver_loc = conn.extra_dejson.get('extra__jdbc__drv_path')
         jdbc_driver_name = conn.extra_dejson.get('extra__jdbc__drv_clsname')
 
-        conn = jaydebeapi.connect(jdbc_driver_name,
-                                  [str(host), str(login), str(psw)],
-                                  jdbc_driver_loc,)
+        conn = jaydebeapi.connect(jclassname=jdbc_driver_name,
+                                  url=str(host),
+                                  driver_args=[str(login), str(psw)],
+                                  jars=jdbc_driver_loc.split(","))
         return conn
 
     def set_autocommit(self, conn, autocommit):

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/21257e8f/setup.py
----------------------------------------------------------------------
diff --git a/setup.py b/setup.py
index d520445..4f1f20a 100644
--- a/setup.py
+++ b/setup.py
@@ -144,7 +144,7 @@ hive = [
     'impyla>=0.13.3',
     'unicodecsv>=0.14.1'
 ]
-jdbc = ['jaydebeapi>=0.2.0']
+jdbc = ['jaydebeapi>=1.1.1']
 mssql = ['pymssql>=2.1.1', 'unicodecsv>=0.14.1']
 mysql = ['mysqlclient>=1.3.6']
 rabbitmq = ['librabbitmq>=1.6.1']

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/21257e8f/tests/contrib/hooks/test_jdbc_hook.py
----------------------------------------------------------------------
diff --git a/tests/contrib/hooks/test_jdbc_hook.py b/tests/contrib/hooks/test_jdbc_hook.py
new file mode 100644
index 0000000..3e8ac12
--- /dev/null
+++ b/tests/contrib/hooks/test_jdbc_hook.py
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import unittest
+
+from mock import Mock
+from mock import patch
+
+from airflow import configuration
+from airflow.hooks.jdbc_hook import JdbcHook
+from airflow import models
+from airflow.utils import db
+
+jdbc_conn_mock = Mock(
+        name="jdbc_conn"
+)
+
+
+class TestJdbcHook(unittest.TestCase):
+    def setUp(self):
+        configuration.load_test_config()
+        db.merge_conn(
+                models.Connection(
+                        conn_id='jdbc_default', conn_type='jdbc',
+                        host='jdbc://localhost/', port=443,
+                        extra='{"extra__jdbc__drv_path": "/path1/test.jar,/path2/t.jar2",
"extra__jdbc__drv_clsname": "com.driver.main"}'))
+
+    @patch("airflow.hooks.jdbc_hook.jaydebeapi.connect", autospec=True,
+           return_value=jdbc_conn_mock)
+    def test_jdbc_conn_connection(self, jdbc_mock):
+        jdbc_hook = JdbcHook()
+        jdbc_conn = jdbc_hook.get_conn()
+        self.assertTrue(jdbc_mock.called)
+        self.assertIsInstance(jdbc_conn, Mock)
+        self.assertEqual(jdbc_conn.name, jdbc_mock.return_value.name)
+
+
+if __name__ == '__main__':
+    unittest.main()


Mime
View raw message