You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/10/21 02:40:19 UTC

[GitHub] [incubator-superset] betodealmeida commented on a change in pull request #11348: fix: Allow "EXPLAIN" queries when "Allow DML" setting is False

betodealmeida commented on a change in pull request #11348:
URL: https://github.com/apache/incubator-superset/pull/11348#discussion_r508954085



##########
File path: superset/sql_parse.py
##########
@@ -111,7 +111,18 @@ def is_select(self) -> bool:
         return self._parsed[0].get_type() == "SELECT"
 
     def is_explain(self) -> bool:
-        return self.stripped().upper().startswith("EXPLAIN")
+        # Remove comments
+        statements_without_comments = [
+            statement.strip(" \t\n;")
+            for statement in self.stripped().upper().splitlines()
+            if not statement.startswith("--")
+        ]

Review comment:
       This will miss some edge cases like:
   
   ```sql
   -- This is a comment
    -- this is another comment but with a space in the front
   EXPLAIN SELECT * FROM TABLE
   ```
   
   You need to `lstrip()` each line as well before testing if it `startswith()`:
   
   ```python
           statements_without_comments = [
               statement.strip(" \t\n;")
               for statement in self.stripped().upper().splitlines()
               if not statement.lstrip().startswith("--")
           ]
   ```

##########
File path: superset/sql_parse.py
##########
@@ -111,7 +111,18 @@ def is_select(self) -> bool:
         return self._parsed[0].get_type() == "SELECT"
 
     def is_explain(self) -> bool:
-        return self.stripped().upper().startswith("EXPLAIN")
+        # Remove comments
+        statements_without_comments = [
+            statement.strip(" \t\n;")
+            for statement in self.stripped().upper().splitlines()
+            if not statement.startswith("--")
+        ]
+
+        # Explain statements will only be the first statement
+        if statements_without_comments[0].startswith("EXPLAIN"):
+            return True
+
+        return False

Review comment:
       You can simplify this:
   
   ```python
   return statements_without_comments[0].startswith("EXPLAIN")
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org