From 04f4d824e0534584da15cca374e17f2c350ed9a3 Mon Sep 17 00:00:00 2001 From: Mayur Singal <39544459+ulixius9@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:11:24 +0530 Subject: [PATCH] MINOR: Databricks view TableType fix (#17124) --- .../source/database/databricks/metadata.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ingestion/src/metadata/ingestion/source/database/databricks/metadata.py b/ingestion/src/metadata/ingestion/source/database/databricks/metadata.py index 682cb95db7a..0ccfbad2a0a 100644 --- a/ingestion/src/metadata/ingestion/source/database/databricks/metadata.py +++ b/ingestion/src/metadata/ingestion/source/database/databricks/metadata.py @@ -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