Comments (3)
@PedroMartinSteenstrup Hello there! I'm here to help you with any bugs, questions, or contributions you have in mind. Let's squash those bugs together! π
The issue you're encountering with SQL queries containing inline comments has been addressed in several pull requests, including #27725, #28363, #28567, and #29248. These changes ensure that comments are not stripped when executing SQL statements, which should resolve the errors you're seeing in both the dashboards' "view query" and SQL Lab.
To fix the issue, ensure you are using the latest version of Superset where these fixes have been merged. Specifically, the changes in pull request #29248 should address the problem you're facing with inline comments starting with --
[1].
If you are already on the latest version and still experiencing issues, double-check your sql_mutator
function implementation and ensure it aligns with the updated handling of SQL comments. Here is a simplified example of how you might define the sql_mutator
function:
def sql_mutator(sql, security_manager, database):
from superset.utils.core import get_username
user_name = get_username()
q_suffix = f'Superset query context \'{{"user": "{user_name}"}}\''
return f"{sql} -- {q_suffix}"
Make sure your Superset configuration includes this function and that MUTATE_AFTER_SPLIT
is set according to your needs:
SQL_QUERY_MUTATOR = sql_mutator
MUTATE_AFTER_SPLIT = False
This should help resolve the errors related to inline comments in your SQL queries.
To continue talking to Dosu, mention @dosu.
from superset.
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:
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 [1].
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 [1].
To further troubleshoot and resolve the issue, you can:
-
Verify the
ParsedQuery
Class: Ensure that theParsedQuery
class and itsget_statements
method correctly parse the SQL statements, especially handling inline comments and semicolons. -
Check for Known Issues: Be aware of the known issues with the
sqlparse
library and ensure that any necessary workarounds are applied. -
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.
To continue talking to Dosu, mention @dosu.
from superset.
good bot @dosu, setting MUTATE_AFTER_SPLIT = True
helped with the dashboards at least.
Sadly, still a problem in sqllab, and I can now even more precisely point it out:
That will work:
select * from reporting.dim_date limit 100
-- select * from information_schema.functions limit 10;
That will not work:
select * from reporting.dim_date limit 100;
-- select * from information_schema.functions limit 10;
The difference? Statement ending with semicolon.
from superset.
Related Issues (20)
- Cannot get back asyncquery result HOT 3
- Dev-server page isn't rendered HOT 14
- Garbled characters on the agent page in the development environment HOT 4
- Labels of Advanced analytics stats in the chart legend can't be changed
- Ephemeral instances no longer have any example data HOT 5
- cannot use a string pattern on a bytes-like object HOT 4
- Fatal error when creating a chart from a saved_query via API call HOT 6
- Elasticsearch integration with superst (Arrays are not supported) HOT 1
- Slack Invite is Broken HOT 2
- RLS form does not show all available datasets when searching by mask HOT 1
- 4.1.0rc1 celery issue - Received unregistered task of type 'reports.scheduler'. HOT 5
- Public role is too strong by default HOT 4
- On the chart editing screen, the icon of dataset should be similar to those used on the βDatasetβ screen. HOT 2
- The description of a chart indicate "deprecated" but the graphical tag is not present
- Unuseful column in export Excel HOT 1
- Upon download as PDF, charts on a long dashboard render as loading image HOT 7
- Docker image does not have mysqlclient HOT 7
- 4.1.0rc1 migration fails if there is unreachable database. HOT 4
- 4.1.0rc1 Druid queries with CURRENT_TIMETAMP fails HOT 8
- Applicable driver not found; attempting to install with Selenium Manager (Beta) HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from superset.