From fc7bd630399c9f4f936b59be347d5d4d0e516744 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Thu, 13 Apr 2017 15:19:58 -0700 Subject: [PATCH] [sql lab] fixes issues specific to Sqlite (#2606) --- superset/db_engine_specs.py | 28 ++++++++++++++++++++++++++++ superset/models/core.py | 3 ++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index 5fb3836ebe1af..bb211d92fa9f0 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -149,6 +149,10 @@ def sql_preprocessor(cls, sql): def patch(cls): pass + @classmethod + def get_table_names(cls, schema, inspector): + return sorted(inspector.get_table_names(schema)) + @classmethod def where_latest_partition( cls, table_name, schema, database, qry, columns=None): @@ -271,6 +275,25 @@ class SqliteEngineSpec(BaseEngineSpec): def epoch_to_dttm(cls): return "datetime({col}, 'unixepoch')" + @classmethod + @cache_util.memoized_func( + timeout=600, + key=lambda *args, **kwargs: 'db:{}:{}'.format(args[0].id, args[1])) + def fetch_result_sets(cls, db, datasource_type, force=False): + schemas = db.inspector.get_schema_names() + result_sets = {} + all_result_sets = [] + schema = schemas[0] + if datasource_type == 'table': + result_sets[schema] = sorted(db.inspector.get_table_names()) + elif datasource_type == 'view': + result_sets[schema] = sorted(db.inspector.get_view_names()) + all_result_sets += [ + '{}.{}'.format(schema, t) for t in result_sets[schema]] + if all_result_sets: + result_sets[""] = all_result_sets + return result_sets + @classmethod def convert_dttm(cls, target_type, dttm): iso = dttm.isoformat().replace('T', ' ') @@ -278,6 +301,11 @@ def convert_dttm(cls, target_type, dttm): iso += '.000000' return "'{}'".format(iso) + @classmethod + def get_table_names(cls, inspector, schema): + """Need to disregard the schema for Sqlite""" + return sorted(inspector.get_table_names()) + class MySQLEngineSpec(BaseEngineSpec): engine = 'mysql' diff --git a/superset/models/core.py b/superset/models/core.py index 0cbcd15c4b413..9e046865f0c10 100644 --- a/superset/models/core.py +++ b/superset/models/core.py @@ -626,7 +626,8 @@ def all_table_names(self, schema=None, force=False): tables_dict = self.db_engine_spec.fetch_result_sets( self, 'table', force=force) return tables_dict.get("", []) - return sorted(self.inspector.get_table_names(schema)) + return sorted( + self.db_engine_spec.get_table_names(self.inspector, schema)) def all_view_names(self, schema=None, force=False): if not schema: