Skip to content

Commit

Permalink
MINOR: Databricks view TableType fix (#17124)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulixius9 authored and harshach committed Jul 24, 2024
1 parent ff1b33d commit 105d462
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,35 @@ def get_table_ddl(
return None


@reflection.cache
def get_table_names(
self, connection, schema=None, **kw
): # pylint: disable=unused-argument
query = "SHOW TABLES"
if schema:
query += " IN " + self.identifier_preparer.quote_identifier(schema)
tables_in_schema = connection.execute(query)
tables = []
for row in tables_in_schema:
# check number of columns in result
# if it is > 1, we use spark thrift server with 3 columns in the result (schema, table, is_temporary)
# else it is hive with 1 column in the result
if len(row) > 1:
tables.append(row[1])
else:
tables.append(row[0])
# "SHOW TABLES" command in hive also fetches view names
# Below code filters out view names from table names
views = self.get_view_names(connection, schema)
return [table for table in tables if table not in views]


DatabricksDialect.get_table_comment = get_table_comment
DatabricksDialect.get_view_names = get_view_names
DatabricksDialect.get_columns = get_columns
DatabricksDialect.get_schema_names = get_schema_names
DatabricksDialect.get_view_definition = get_view_definition
DatabricksDialect.get_table_names = get_table_names
DatabricksDialect.get_all_view_definitions = get_all_view_definitions
reflection.Inspector.get_schema_names = get_schema_names_reflection
reflection.Inspector.get_table_ddl = get_table_ddl
Expand Down

0 comments on commit 105d462

Please sign in to comment.