PyHive icon indicating copy to clipboard operation
PyHive copied to clipboard

can not raise NoSuchTableError for has_table method

Open hkklearn opened this issue 6 years ago • 4 comments

     regex = r"Table\ \'.*{}\'\ does\ not\ exist".format(re.escape(table_name))
            
     if msg and re.search(regex, msg):
            raise exc.NoSuchTableError(table_name)
        else:
            raise

with presto and Oracle, Oracle has table name with upper case, but table name in error message which return from presto is with lower case, so re.search method will return None, then has_table method will exit with uncaught exception.

maybe we should use re.IGNORECASE in re.search method

hkklearn avatar Oct 14 '19 07:10 hkklearn

hitting the same issue with the memory catalog. Maybe you should update the title of the issue to:

"Presto TABLE_NOT_FOUND returns lower case table name causing has_table regex to fail"

dmateusp avatar May 25 '20 13:05 dmateusp

Just upvoting this because I hit it as well. This causes the has_table method to throw an unexpected error, which can be quite painful. For example, pandas df.to_sql relies on has_table, which means you can't create tables with mixed case names

Here's a simple repro:

conn_str = 'presto://localhost:8080/memory?schema=default'
engine = sa.create_engine(conn_str)
inspector = sa.inspect(engine)
inspector.has_table("Foo", schema="default")

apkendall10 avatar Jun 19 '24 17:06 apkendall10

Hi, everyone ! This bug has been fixed, please check for details KYUUBI 6485.

Thanks.

BruceWong96 avatar Aug 12 '24 09:08 BruceWong96

Unfortunately a similar situation happens with Hive. The table name in the exception is qualified by the database name (default.test in this case):

"(pyhive.exc.OperationalError) TExecuteStatementResp(status=TStatus(statusCode=3, infoMessages=['Server-side error; please check HS2 logs.'], sqlState='42S02', errorCode=10001, errorMessage='Error while compiling statement: FAILED: SemanticException [Error 10001]: Table not found default.test; Query ID: chris_20250808153810_842dd749-91db-43f8-8bd8-9bdbac6aad9a'), operationHandle=None)"

But the one I queried was not:

(Pdb) p regex
'TExecuteStatementResp.*SemanticException.*Table not found test'

So the regex doesn't match. I think I can work around it by passing schema='default' to has_table(), but I shouldn't need to do that?

qris avatar Aug 08 '25 14:08 qris