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

yao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new c19d923b85 [KYUUBI #7048] Fix KeyError when parsing unknown Hive 
type_id in schema inspection
c19d923b85 is described below

commit c19d923b85847bcd9ae45c20c9d45360396379b6
Author: John Zhang <[email protected]>
AuthorDate: Tue Apr 29 10:41:16 2025 +0800

    [KYUUBI #7048] Fix KeyError when parsing unknown Hive type_id in schema 
inspection
    
    This patch adds try/except block to prevent `KeyError` when mapping unknown 
`type_id` in Hive schema parsing. Now, if a `type_id` is not recognized, 
`type_code` is set to `None` instead of raising an exception.
    
    ### Why are the changes needed?
    
    Previously, when parsing Hive table schemas, the code attempts to map each 
`type_id` to a human-readable type name via 
`ttypes.TTypeId._VALUES_TO_NAMES[type_id]`. If Hive introduced an unknown or 
custom type (e.g. some might using an non-standard version or data pumping from 
a totally different data source like *Oracle* into *Hive* databases), a 
`KeyError` was raised, interrupting the entire SQL query process. This patch 
adds a `try/except` block so that unrecognized `type_id`s will s [...]
    
    ### How was this patch tested?
    
    The patch was tested by running schema inspection on tables containing both 
standard and unknown/custom Hive column types. For known types, parsing behaves 
as before. For unknown types, the parser sets `type_code` to `None` without 
raising an exception, and the rest of the process completes successfully. No 
unit test was added since this is an edge case dependent on unreachable or 
custom Hive types, but was tested on typical use cases.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No. 😂 It's a minor patch.
    
    Closes #7048 from ZsgsDesign/patch-1.
    
    Closes #7048
    
    4d246d0ec [John Zhang] fix: handle KeyError when parsing Hive type_id 
mapping
    
    Authored-by: John Zhang <[email protected]>
    Signed-off-by: Kent Yao <[email protected]>
---
 python/pyhive/hive.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/python/pyhive/hive.py b/python/pyhive/hive.py
index e199dc25da..f813e1f637 100644
--- a/python/pyhive/hive.py
+++ b/python/pyhive/hive.py
@@ -434,7 +434,10 @@ class Cursor(common.DBAPICursor):
                     type_code = 
ttypes.TTypeId._VALUES_TO_NAMES[ttypes.TTypeId.STRING_TYPE]
                 else:
                     type_id = primary_type_entry.primitiveEntry.type
-                    type_code = ttypes.TTypeId._VALUES_TO_NAMES[type_id]
+                    try:
+                        type_code = ttypes.TTypeId._VALUES_TO_NAMES[type_id]
+                    except KeyError:
+                        type_code = None
                 self._description.append((
                     col.columnName.decode('utf-8') if sys.version_info[0] == 2 
else col.columnName,
                     type_code.decode('utf-8') if sys.version_info[0] == 2 else 
type_code,

Reply via email to