Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sql lab] fix CREATE TABLE AS #2719

Merged
merged 1 commit into from
May 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
4 changes: 3 additions & 1 deletion superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down