mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
Add force_ctas_schema to query model when enabled (#1825)
* Add force_ctas_schema to query model when enabled * Add schema to temp_table_name * Remove extra arg in create_table_as
This commit is contained in:
parent
b6cba13293
commit
e06a0cd89b
@ -129,7 +129,10 @@ class QueryTable extends React.PureComponent {
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
q.output = [q.schema, q.tempTable].filter((v) => (v)).join('.');
|
||||
// if query was run using ctas and force_ctas_schema was set
|
||||
// tempTable will have the schema
|
||||
const schemaUsed = q.ctas && q.tempTable.includes('.') ? '' : q.schema;
|
||||
q.output = [schemaUsed, q.tempTable].filter((v) => (v)).join('.');
|
||||
}
|
||||
q.progress = (
|
||||
<ProgressBar
|
||||
|
@ -40,7 +40,7 @@ def dedup(l, suffix='__'):
|
||||
return new_l
|
||||
|
||||
|
||||
def create_table_as(sql, table_name, schema=None, override=False):
|
||||
def create_table_as(sql, table_name, override=False):
|
||||
"""Reformats the query into the create table as query.
|
||||
|
||||
Works only for the single select SQL statements, in all other cases
|
||||
@ -55,8 +55,6 @@ def create_table_as(sql, table_name, schema=None, override=False):
|
||||
# TODO(bkyryliuk): drop table if allowed, check the namespace and
|
||||
# the permissions.
|
||||
# TODO raise if multi-statement
|
||||
if schema:
|
||||
table_name = schema + '.' + table_name
|
||||
exec_sql = ''
|
||||
if override:
|
||||
exec_sql = 'DROP TABLE IF EXISTS {table_name};\n'
|
||||
@ -105,7 +103,7 @@ def get_sql_results(self, query_id, return_results=True, store_results=False):
|
||||
query.user_id,
|
||||
start_dttm.strftime('%Y_%m_%d_%H_%M_%S'))
|
||||
executed_sql = create_table_as(
|
||||
executed_sql, query.tmp_table_name, database.force_ctas_schema)
|
||||
executed_sql, query.tmp_table_name)
|
||||
query.select_as_cta_used = True
|
||||
elif (
|
||||
query.limit and superset_query.is_select() and
|
||||
|
@ -2392,6 +2392,14 @@ class Superset(BaseSupersetView):
|
||||
get_datasource_access_error_msg('{}'.format(rejected_tables)))
|
||||
session.commit()
|
||||
|
||||
select_as_cta = request.form.get('select_as_cta') == 'true'
|
||||
tmp_table_name = request.form.get('tmp_table_name')
|
||||
if select_as_cta and mydb.force_ctas_schema:
|
||||
tmp_table_name = '{}.{}'.format(
|
||||
mydb.force_ctas_schema,
|
||||
tmp_table_name
|
||||
)
|
||||
|
||||
query = models.Query(
|
||||
database_id=int(database_id),
|
||||
limit=int(app.config.get('SQL_MAX_ROW', None)),
|
||||
@ -2402,7 +2410,7 @@ class Superset(BaseSupersetView):
|
||||
tab_name=request.form.get('tab'),
|
||||
status=QueryStatus.PENDING if async else QueryStatus.RUNNING,
|
||||
sql_editor_id=request.form.get('sql_editor_id'),
|
||||
tmp_table_name=request.form.get('tmp_table_name'),
|
||||
tmp_table_name=tmp_table_name,
|
||||
user_id=int(g.user.get_id()),
|
||||
client_id=request.form.get('client_id'),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user