mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
[sql lab] fix CREATE TABLE AS (#2719)
This commit is contained in:
committed by
GitHub
parent
46d7a925bb
commit
a6e1e18244
@@ -162,24 +162,25 @@ class BaseEngineSpec(object):
|
||||
|
||||
@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)
|
||||
|
||||
@@ -602,11 +602,11 @@ class Database(Model, AuditMixinNullable):
|
||||
|
||||
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 = (
|
||||
|
||||
@@ -166,7 +166,9 @@ def get_sql_results(self, query_id, return_results=True, store_results=False):
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user