Skip to content

Commit

Permalink
[KYUUBI #6485] Fix the Presto TABLE NOT FOUND error message that fail…
Browse files Browse the repository at this point in the history
…ed to match

# 🔍 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 🔖

- [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

06f737f [Bruce Wong] Fix typos
9307175 [Bruce Wong] Added unit tests for table names with both upper and lower case letters
9837030 [Bruce Wong] fix table not found

Authored-by: Bruce Wong <[email protected]>
Signed-off-by: Cheng Pan <[email protected]>
  • Loading branch information
BruceWong96 authored and pan3793 committed Aug 12, 2024
1 parent f58f21f commit d3e1768
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/pyhive/sqlalchemy_presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _get_table_columns(self, connection, table_name, schema):
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
Expand Down
16 changes: 16 additions & 0 deletions python/pyhive/tests/test_sqlalchemy_presto.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -87,3 +92,14 @@ def test_reserved_words(self, engine, connection):
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())

0 comments on commit d3e1768

Please sign in to comment.