diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index ec0689642ffdd..ffcfcec1084e5 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -162,24 +162,25 @@ def where_latest_partition( @classmethod def select_star(cls, my_db, table_name, schema=None, limit=100, - show_cols=False, indent=True): + show_cols=False, indent=True, latest_partition=True): fields = '*' - table = my_db.get_table(table_name, schema=schema) + cols = [] + if show_cols or latest_partition: + cols = my_db.get_table(table_name, schema=schema).columns + if show_cols: - fields = [my_db.get_quoter()(c.name) for c in table.columns] + fields = [my_db.get_quoter()(c.name) for c in cols] full_table_name = table_name if schema: full_table_name = schema + '.' + table_name - qry = select(fields) + qry = select(fields).select_from(text(full_table_name)) if limit: qry = qry.limit(limit) - partition_query = cls.where_latest_partition( - table_name, schema, my_db, qry, columns=table.columns) - # if not partition_query condition fails. - if partition_query == False: # noqa - qry = qry.select_from(text(full_table_name)) - else: - qry = partition_query + if latest_partition: + partition_query = cls.where_latest_partition( + table_name, schema, my_db, qry, columns=cols) + if partition_query != False: # noqa + qry = partition_query sql = my_db.compile_sqla_query(qry) if indent: sql = sqlparse.format(sql, reindent=True) diff --git a/superset/models/core.py b/superset/models/core.py index af76b26ce2261..f7412fbc1173e 100644 --- a/superset/models/core.py +++ b/superset/models/core.py @@ -602,11 +602,11 @@ def compile_sqla_query(self, qry, schema=None): def select_star( self, table_name, schema=None, limit=100, show_cols=False, - indent=True): + indent=True, latest_partition=True): """Generates a ``select *`` statement in the proper dialect""" return self.db_engine_spec.select_star( self, table_name, schema=schema, limit=limit, show_cols=show_cols, - indent=indent) + indent=indent, latest_partition=latest_partition) def wrap_sql_limit(self, sql, limit=1000): qry = ( diff --git a/superset/sql_lab.py b/superset/sql_lab.py index 9491c5f546c3e..bb3c4304f834a 100644 --- a/superset/sql_lab.py +++ b/superset/sql_lab.py @@ -166,7 +166,9 @@ def handle_error(msg): query.select_sql = '{}'.format(database.select_star( query.tmp_table_name, limit=query.limit, - schema=database.force_ctas_schema + schema=database.force_ctas_schema, + show_cols=False, + latest_partition=False, )) query.end_time = utils.now_as_float() session.merge(query)