Skip to content

Commit

Permalink
[sql lab] fixes issues specific to Sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Apr 12, 2017
1 parent b448394 commit d68c925
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions superset/db_engine_specs.py
Expand Up @@ -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):
Expand Down Expand Up @@ -271,13 +275,37 @@ 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', ' ')
if '.' not in iso:
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'
Expand Down
3 changes: 2 additions & 1 deletion superset/models/core.py
Expand Up @@ -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:
Expand Down

0 comments on commit d68c925

Please sign in to comment.