villebro commented on a change in pull request #12188:
URL:
https://github.com/apache/incubator-superset/pull/12188#discussion_r548447560
##########
File path: superset/sql_lab.py
##########
@@ -337,6 +331,32 @@ def execute_sql_statements( # pylint:
disable=too-many-arguments, too-many-loca
query.start_running_time = now_as_float()
session.commit()
+ # Should we create a table or view from the select?
+ if (
+ query.select_as_cta
+ and query.ctas_method == CtasMethod.TABLE
+ and not parsed_query.is_valid_ctas()
+ ):
+ raise SqlLabException(
+ _(
+ "CTAS (create table as select) can only be run with a query
where "
+ "the last statement is a SELECT. Please make sure your query
has "
+ "a SELECT as its last statement. Then, try running your query
again."
+ )
+ )
+ if (
+ query.select_as_cta
+ and query.ctas_method == CtasMethod.VIEW
+ and not parsed_query.is_valid_cvas()
+ ):
+ raise SqlLabException(
+ _(
+ "CVAS (create view as select) can only be run with a query
with "
+ "a single SELECT statement. Please make sure your query has
only "
+ "a SELECT statement. Then, try running your query again."
+ )
+ )
Review comment:
As the error messages imply a deep understanding of how
`is_valid_ctas()` and `is_valid_cvas()` work, I wonder if these should be moved
into `ParsedQuery` as something like `assert_is_valid_ctas()` and
`assert_is_valid_cvas()` and have the error messages there?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]