@@ -30,12 +30,12 @@ class HiveInputPlugin(BaseInputPlugin):
3030 def is_correct_input (
3131 self , input_item : Any , table_name : str , format : str = None , ** kwargs
3232 ):
33- is_sqlalchemy_hive = sqlalchemy and isinstance (
34- input_item , sqlalchemy .engine .base .Connection
35- )
3633 is_hive_cursor = hive and isinstance (input_item , hive .Cursor )
3734
38- return is_sqlalchemy_hive or is_hive_cursor or format == "hive"
35+ return self .is_sqlalchemy_hive (input_item ) or is_hive_cursor or format == "hive"
36+
37+ def is_sqlalchemy_hive (self , input_item : Any ):
38+ return sqlalchemy and isinstance (input_item , sqlalchemy .engine .base .Connection )
3939
4040 def to_dc (
4141 self ,
@@ -201,7 +201,11 @@ def _parse_hive_table_description(
201201 of the DESCRIBE FORMATTED call, which is unfortunately
202202 in a format not easily readable by machines.
203203 """
204- cursor .execute (f"USE { schema } " )
204+ cursor .execute (
205+ sqlalchemy .text (f"USE { schema } " )
206+ if self .is_sqlalchemy_hive (cursor )
207+ else f"USE { schema } "
208+ )
205209 if partition :
206210 # Hive wants quoted, comma separated list of partition keys
207211 partition = partition .replace ("=" , '="' )
@@ -283,7 +287,11 @@ def _parse_hive_partition_description(
283287 """
284288 Extract all partition informaton for a given table
285289 """
286- cursor .execute (f"USE { schema } " )
290+ cursor .execute (
291+ sqlalchemy .text (f"USE { schema } " )
292+ if self .is_sqlalchemy_hive (cursor )
293+ else f"USE { schema } "
294+ )
287295 result = self ._fetch_all_results (cursor , f"SHOW PARTITIONS { table_name } " )
288296
289297 return [row [0 ] for row in result ]
@@ -298,7 +306,9 @@ def _fetch_all_results(
298306 The former has the fetchall method on the cursor,
299307 whereas the latter on the executed query.
300308 """
301- result = cursor .execute (sql )
309+ result = cursor .execute (
310+ sqlalchemy .text (sql ) if self .is_sqlalchemy_hive (cursor ) else sql
311+ )
302312
303313 try :
304314 return result .fetchall ()
0 commit comments