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

chengpan 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 d3e17680f [KYUUBI #6485] Fix the Presto TABLE NOT FOUND error message 
that failed to match
d3e17680f is described below

commit d3e17680f58601bf526929f82fd6f732f4d1644e
Author: Bruce Wong <[email protected]>
AuthorDate: Mon Aug 12 08:38:09 2024 +0000

    [KYUUBI #6485] Fix the Presto TABLE NOT FOUND error message that failed to 
match
    
    # :mag: Description
    ## Issue References ๐Ÿ”—
    
    This pull request fixes #6485
    
    ## Describe Your Solution ๐Ÿ”ง
    
    Ignore uppercase and lowercase letters in table names when using regular 
expressions to match.
    
    ## Types of changes :bookmark:
    
    - [x] Bugfix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
    
    ## Test Plan ๐Ÿงช
    
    Added unit tests when table names have capital letters.
    
    ---
    
    # Checklist ๐Ÿ“
    
    - [x] This patch was not authored or co-authored using [Generative 
Tooling](https://www.apache.org/legal/generative-tooling.html)
    
    **Be nice. Be informative.**
    
    Closes #6605 from BruceWong96/fix-presto-regex.
    
    Closes #6485
    
    06f737f24 [Bruce Wong] Fix typos
    93071754a [Bruce Wong] Added unit tests for table names with both upper and 
lower case letters
    9837030a1 [Bruce Wong] fix table not found
    
    Authored-by: Bruce Wong <[email protected]>
    Signed-off-by: Cheng Pan <[email protected]>
---
 python/pyhive/sqlalchemy_presto.py            |  2 +-
 python/pyhive/tests/test_sqlalchemy_presto.py | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/python/pyhive/sqlalchemy_presto.py 
b/python/pyhive/sqlalchemy_presto.py
index bfe1ba047..33a41bae3 100644
--- a/python/pyhive/sqlalchemy_presto.py
+++ b/python/pyhive/sqlalchemy_presto.py
@@ -143,7 +143,7 @@ class PrestoDialect(default.DefaultDialect):
                 else None
             )
             regex = r"Table\ \'.*{}\'\ does\ not\ 
exist".format(re.escape(table_name))
-            if msg and re.search(regex, msg):
+            if msg and re.search(regex, msg, re.IGNORECASE):
                 raise exc.NoSuchTableError(table_name)
             else:
                 raise
diff --git a/python/pyhive/tests/test_sqlalchemy_presto.py 
b/python/pyhive/tests/test_sqlalchemy_presto.py
index 58a5c034e..336dd12e2 100644
--- a/python/pyhive/tests/test_sqlalchemy_presto.py
+++ b/python/pyhive/tests/test_sqlalchemy_presto.py
@@ -1,6 +1,11 @@
 from __future__ import absolute_import
 from __future__ import unicode_literals
+
+import re
 from builtins import str
+
+import sqlalchemy
+
 from pyhive.tests.sqlalchemy_test_case import SqlAlchemyTestCase
 from pyhive.tests.sqlalchemy_test_case import with_engine_connection
 from sqlalchemy import types
@@ -87,3 +92,14 @@ class TestSqlAlchemyPresto(unittest.TestCase, 
SqlAlchemyTestCase):
         self.assertIn('"current_timestamp"', query)
         self.assertNotIn('`select`', query)
         self.assertNotIn('`current_timestamp`', query)
+
+    @with_engine_connection
+    def test_hash_table(self, engine, connection):
+        sqlalchemy_version = float(re.search(r"^([\d]+\.[\d]+)\..+", 
sqlalchemy.__version__).group(1))
+        if sqlalchemy_version >= 1.4:
+            insp = sqlalchemy.inspect(engine)
+            self.assertFalse(insp.has_table("THIS_TABLE_DOSE_NOT_EXIST"))
+            self.assertFalse(insp.has_table("THIS_TABLE_DOSE_not_exist"))
+        else:
+            self.assertFalse(Table('THIS_TABLE_DOSE_NOT_EXIST', 
MetaData(bind=engine)).exists())
+            self.assertFalse(Table('THIS_TABLE_DOSE_not_exits', 
MetaData(bind=engine)).exists())
\ No newline at end of file

Reply via email to