You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2020/06/22 18:30:48 UTC

[airflow] 02/05: Make hive macros py3 compatible (#8598)

This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 8405787b6915d67be09ed3a0b18bacb2d130d03e
Author: Ace Haidrey <ah...@pandora.com>
AuthorDate: Tue Jun 16 13:19:41 2020 -0700

    Make hive macros py3 compatible (#8598)
    
    Co-authored-by: Ace Haidrey <ah...@pinterest.com>
    
    (cherry-picked from c78e2a5)
---
 airflow/hooks/hive_hooks.py   |  3 ++-
 tests/hooks/test_hive_hook.py | 15 ++++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/airflow/hooks/hive_hooks.py b/airflow/hooks/hive_hooks.py
index 4e41834..ec37dfb 100644
--- a/airflow/hooks/hive_hooks.py
+++ b/airflow/hooks/hive_hooks.py
@@ -691,6 +691,7 @@ class HiveMetastoreHook(BaseHook):
                            pairs will be considered as candidates of max partition.
         :type filter_map: map
         :return: Max partition or None if part_specs is empty.
+        :rtype: basestring
         """
         if not part_specs:
             return None
@@ -714,7 +715,7 @@ class HiveMetastoreHook(BaseHook):
         if not candidates:
             return None
         else:
-            return max(candidates).encode('utf-8')
+            return max(candidates)
 
     def max_partition(self, schema, table_name, field=None, filter_map=None):
         """
diff --git a/tests/hooks/test_hive_hook.py b/tests/hooks/test_hive_hook.py
index 98c024f..011038a 100644
--- a/tests/hooks/test_hive_hook.py
+++ b/tests/hooks/test_hive_hook.py
@@ -362,7 +362,7 @@ class TestHiveMetastoreHook(TestHiveEnvironment):
                 None)
 
         # No partition will be filtered out.
-        self.assertEqual(max_partition, b'value3')
+        self.assertEqual(max_partition, 'value3')
 
     def test_get_max_partition_from_valid_part_specs(self):
         max_partition = \
@@ -371,7 +371,16 @@ class TestHiveMetastoreHook(TestHiveEnvironment):
                  {'key1': 'value3', 'key2': 'value4'}],
                 'key1',
                 self.VALID_FILTER_MAP)
-        self.assertEqual(max_partition, b'value1')
+        self.assertEqual(max_partition, 'value1')
+
+    def test_get_max_partition_from_valid_part_specs_return_type(self):
+        max_partition = \
+            HiveMetastoreHook._get_max_partition_from_part_specs(
+                [{'key1': 'value1', 'key2': 'value2'},
+                 {'key1': 'value3', 'key2': 'value4'}],
+                'key1',
+                self.VALID_FILTER_MAP)
+        self.assertIsInstance(max_partition, str)
 
     @patch("airflow.hooks.hive_hooks.HiveMetastoreHook.get_connection",
            return_value=[Connection(host="localhost", port="9802")])
@@ -522,7 +531,7 @@ class TestHiveMetastoreHook(TestHiveEnvironment):
                                             table_name=self.table,
                                             field=self.partition_by,
                                             filter_map=filter_map)
-        self.assertEqual(partition, DEFAULT_DATE_DS.encode('utf-8'))
+        self.assertEqual(partition, DEFAULT_DATE_DS)
 
         metastore.get_table.assert_called_with(
             dbname=self.database, tbl_name=self.table)