-
Notifications
You must be signed in to change notification settings - Fork 13.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Trino get_columns
#29566
fix: Trino get_columns
#29566
Conversation
993bc79
to
a1687c8
Compare
@@ -840,211 +1043,6 @@ def get_view_names( | |||
results = cursor.fetchall() | |||
return {row[0] for row in results} | |||
|
|||
@classmethod | |||
def _create_column_info( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods were moved to the base class, PrestoBaseEngineSpec
.
@@ -2224,6 +2217,23 @@ def denormalize_name(cls, dialect: Dialect, name: str) -> str: | |||
|
|||
return name | |||
|
|||
@classmethod | |||
def quote_table(cls, table: Table, dialect: Dialect) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -433,7 +437,17 @@ def get_columns( | |||
"schema_options", expand the schema definition out to show all | |||
subfields of nested ROWs as their appropriate dotted paths. | |||
""" | |||
base_cols = super().get_columns(inspector, table, options) | |||
# The Trino dialect raises `NoSuchTableError` on the inspection methods when the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate the comments 👍🏼
SUMMARY
This PR is a workaround to a weird bug we've encountered in Trino when adding a physical dataset.
When adding the dataset, Superset calls
get_columns
on the inspector. The Trino driver then does a check to see if the table exists, usinghas_table
:https://github.com/trinodb/trino-python-client/blob/505989a59e93f6319e8b6be89a16f81034a06404/trino/sqlalchemy/dialect.py#L176
The
has_table
method runs this query:And here's the weird part: even though the table DOES exist, the query can return nothing. Even weirder: running a
SHOW COLUMNS FROM :schema.:table
in that case returns data.The Trino DB engine spec already has a custom
get_indexes
method with the warning:superset/superset/db_engine_specs/trino.py
Lines 442 to 462 in 84a1cd2
So I suspect it's the same problem.
To fix this, I modified the Trino DB engine spec to first try the
inspector.get_columns
method, which queries theinformation_schema.table
. If this fails withNoSuchTableError
then it falls back to theSHOW COLUMNS FROM ...
approach.The Presto DB engine spec already implements a
get_columns
that usesSHOW COLUMNS FROM ...
, so I moved it toPrestoBaseEngineSpec
, so it can be used both byPrestoEngineSpec
andTrinoEngineSpec
.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION