Skip to content

Commit c78e2a5

Browse files
authored
Make hive macros py3 compatible (#8598)
Co-authored-by: Ace Haidrey <[email protected]>
1 parent d6e5e7c commit c78e2a5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

airflow/providers/apache/hive/hooks/hive.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ def _get_max_partition_from_part_specs(part_specs, partition_key, filter_map):
685685
pairs will be considered as candidates of max partition.
686686
:type filter_map: map
687687
:return: Max partition or None if part_specs is empty.
688+
:rtype: basestring
688689
"""
689690
if not part_specs:
690691
return None
@@ -708,7 +709,7 @@ def _get_max_partition_from_part_specs(part_specs, partition_key, filter_map):
708709
if not candidates:
709710
return None
710711
else:
711-
return max(candidates).encode('utf-8')
712+
return max(candidates)
712713

713714
def max_partition(self, schema, table_name, field=None, filter_map=None):
714715
"""

tests/providers/apache/hive/hooks/test_hive.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def test_get_max_partition_from_valid_part_specs_and_none_filter_map(self):
363363
None)
364364

365365
# No partition will be filtered out.
366-
self.assertEqual(max_partition, b'value3')
366+
self.assertEqual(max_partition, 'value3')
367367

368368
def test_get_max_partition_from_valid_part_specs(self):
369369
max_partition = \
@@ -372,7 +372,16 @@ def test_get_max_partition_from_valid_part_specs(self):
372372
{'key1': 'value3', 'key2': 'value4'}],
373373
'key1',
374374
self.VALID_FILTER_MAP)
375-
self.assertEqual(max_partition, b'value1')
375+
self.assertEqual(max_partition, 'value1')
376+
377+
def test_get_max_partition_from_valid_part_specs_return_type(self):
378+
max_partition = \
379+
HiveMetastoreHook._get_max_partition_from_part_specs(
380+
[{'key1': 'value1', 'key2': 'value2'},
381+
{'key1': 'value3', 'key2': 'value4'}],
382+
'key1',
383+
self.VALID_FILTER_MAP)
384+
self.assertIsInstance(max_partition, str)
376385

377386
@mock.patch("airflow.providers.apache.hive.hooks.hive.HiveMetastoreHook.get_connection",
378387
return_value=[Connection(host="localhost", port="9802")])
@@ -523,7 +532,7 @@ def test_max_partition(self):
523532
table_name=self.table,
524533
field=self.partition_by,
525534
filter_map=filter_map)
526-
self.assertEqual(partition, DEFAULT_DATE_DS.encode('utf-8'))
535+
self.assertEqual(partition, DEFAULT_DATE_DS)
527536

528537
metastore.get_table.assert_called_with(
529538
dbname=self.database, tbl_name=self.table)

0 commit comments

Comments
 (0)