diff --git a/superset/db_engine_specs/databricks.py b/superset/db_engine_specs/databricks.py index d67370be7..deb9a3543 100644 --- a/superset/db_engine_specs/databricks.py +++ b/superset/db_engine_specs/databricks.py @@ -14,6 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License.o + from superset.db_engine_specs.hive import HiveEngineSpec @@ -21,3 +22,4 @@ class DatabricksHiveEngineSpec(HiveEngineSpec): engine = "databricks" engine_name = "Databricks Hive" driver = "pyhive" + _show_functions_column = "function" diff --git a/superset/db_engine_specs/hive.py b/superset/db_engine_specs/hive.py index 4234ddc63..9ceb1e587 100644 --- a/superset/db_engine_specs/hive.py +++ b/superset/db_engine_specs/hive.py @@ -84,6 +84,10 @@ class HiveEngineSpec(PrestoEngineSpec): allows_alias_to_source_column = True allows_hidden_ordeby_agg = False + # When running `SHOW FUNCTIONS`, what is the name of the column with the + # function names? + _show_functions_column = "tab_name" + # pylint: disable=line-too-long _time_grain_expressions = { None: "{col}", @@ -530,7 +534,23 @@ class HiveEngineSpec(PrestoEngineSpec): :param database: The database to get functions for :return: A list of function names useable in the database """ - return database.get_df("SHOW FUNCTIONS")["tab_name"].tolist() + df = database.get_df("SHOW FUNCTIONS") + if cls._show_functions_column in df: + return df[cls._show_functions_column].tolist() + + columns = df.columns.values.tolist() + logger.error( + "Payload from `SHOW FUNCTIONS` has the incorrect format. " + "Expected column `%s`, found: %s.", + cls._show_functions_column, + ", ".join(columns), + ) + # if the results have a single column, use that + if len(columns) == 1: + return df[columns[0]].tolist() + + # otherwise, return no function names to prevent errors + return [] @classmethod def is_readonly_query(cls, parsed_query: ParsedQuery) -> bool: