dosubot[bot] commented on issue #29466: URL: https://github.com/apache/superset/issues/29466#issuecomment-2205947244
<!-- Answer --> The issue with SQL Lab in Apache Superset when a SQL statement containing inline comments ends with a semicolon can be resolved by ensuring that the SQL statement is properly parsed and executed. The `ParsedQuery` class's `get_statements` method is responsible for splitting SQL queries into individual statements. It ensures that each statement is cleaned and separated properly before being added to the list of statements. Here is the specific logic used in the `get_statements` method: ```python def get_statements(self) -> list[str]: """Returns a list of SQL statements as strings, stripped""" statements = [] for statement in self._parsed: if statement: sql = str(statement).strip(" \n;\t") if sql: statements.append(sql) return statements ``` This method strips any leading or trailing whitespace, newline characters, semicolons, and tabs from each statement, ensuring they are correctly parsed <sup>[[1]](https://github.com/apache/superset/blob/master/superset/sql_parse.py)</sup>. Additionally, there are known issues with the `sqlparse` library used by Superset for parsing SQL queries, particularly with handling inline comments and semicolons. A workaround has been implemented in Superset's code to address these issues <sup>[[1]](https://github.com/apache/superset/blob/master/superset/sql_parse.py)</sup>. To further troubleshoot and resolve the issue, you can: 1. **Verify the `ParsedQuery` Class**: Ensure that the `ParsedQuery` class and its `get_statements` method correctly parse the SQL statements, especially handling inline comments and semicolons. 2. **Check for Known Issues**: Be aware of the known issues with the `sqlparse` library and ensure that any necessary workarounds are applied. 3. **Update Superset**: Make sure you are using the latest version of Superset where fixes for handling comments and semicolons have been merged. By following these steps, you should be able to resolve the issue with SQL Lab when a SQL statement containing inline comments ends with a semicolon. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* -- 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: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org