airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlo...@apache.org
Subject incubator-airflow git commit: [AIRFLOW-278] Support utf-8 ecoding for SQL
Date Mon, 27 Jun 2016 15:21:57 GMT
Repository: incubator-airflow
Updated Branches:
  refs/heads/master 3b84bcb3e -> 5db7ec70f


[AIRFLOW-278] Support utf-8 ecoding for SQL

Support utf-8 encoding for SQL queries, needed for Python 2
users who have unicode strings inside the queries

Closes #1622 from biln/master


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

Branch: refs/heads/master
Commit: 5db7ec70f8b45bc4872ae64901d2829efa0e4081
Parents: 3b84bcb
Author: Nikolay Bilev <bilevn@gmail.com>
Authored: Mon Jun 27 11:20:36 2016 -0400
Committer: jlowin <jlowin@users.noreply.github.com>
Committed: Mon Jun 27 11:20:41 2016 -0400

----------------------------------------------------------------------
 airflow/hooks/dbapi_hook.py | 9 +++++++++
 1 file changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/5db7ec70/airflow/hooks/dbapi_hook.py
----------------------------------------------------------------------
diff --git a/airflow/hooks/dbapi_hook.py b/airflow/hooks/dbapi_hook.py
index f6e86b6..55f2d95 100644
--- a/airflow/hooks/dbapi_hook.py
+++ b/airflow/hooks/dbapi_hook.py
@@ -17,6 +17,7 @@ from past.builtins import basestring
 from datetime import datetime
 import numpy
 import logging
+import sys
 
 from airflow.hooks.base_hook import BaseHook
 from airflow.exceptions import AirflowException
@@ -66,6 +67,8 @@ class DbApiHook(BaseHook):
         :param parameters: The parameters to render the SQL query with.
         :type parameters: mapping or iterable
         '''
+        if sys.version_info[0] < 3:
+            sql = sql.encode('utf-8')
         import pandas.io.sql as psql
         conn = self.get_conn()
         df = psql.read_sql(sql, con=conn, params=parameters)
@@ -82,6 +85,8 @@ class DbApiHook(BaseHook):
         :param parameters: The parameters to render the SQL query with.
         :type parameters: mapping or iterable
         '''
+        if sys.version_info[0] < 3:
+            sql = sql.encode('utf-8')
         conn = self.get_conn()
         cur = self.get_cursor()
         if parameters is not None:
@@ -103,6 +108,8 @@ class DbApiHook(BaseHook):
         :param parameters: The parameters to render the SQL query with.
         :type parameters: mapping or iterable
         '''
+        if sys.version_info[0] < 3:
+            sql = sql.encode('utf-8')
         conn = self.get_conn()
         cur = conn.cursor()
         if parameters is not None:
@@ -138,6 +145,8 @@ class DbApiHook(BaseHook):
 
         cur = conn.cursor()
         for s in sql:
+            if sys.version_info[0] < 3:
+                s = s.encode('utf-8')
             logging.info(s)
             if parameters is not None:
                 cur.execute(s, parameters)


Mime
View raw message