betodealmeida commented on a change in pull request #19055:
URL: https://github.com/apache/superset/pull/19055#discussion_r822119884
##########
File path: superset/sql_parse.py
##########
@@ -458,3 +460,178 @@ def validate_filter_clause(clause: str) -> None:
)
if open_parens > 0:
raise QueryClauseValidationException("Unclosed parenthesis in filter
clause")
+
+
+def has_table_query(statement: Statement) -> bool:
+ """
+ Return if a stament has a query reading from a table.
+
+ >>> has_table_query(sqlparse.parse("COUNT(*)")[0])
+ False
+ >>> has_table_query(sqlparse.parse("SELECT * FROM table")[0])
+ True
+
+ Note that queries reading from constant values return false:
+
+ >>> has_table_query(sqlparse.parse("SELECT * FROM (SELECT 1)")[0])
+ False
+
+ """
+ seen_source = False
+ tokens = statement.tokens[:]
+ while tokens:
+ token = tokens.pop(0)
+ if isinstance(token, TokenList):
+ tokens.extend(token.tokens)
+
+ if token.ttype == Keyword and token.value.lower() in ("from", "join"):
+ seen_source = True
+ elif seen_source and (
Review comment:
Yeah, in the `insert_rls` function I had to implement tree traversal to
get it right. Let me give it a try rewriting this one.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]