- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2022 03:17 AM
Hey all,
My aim is to validate a given SQL string without actually running it.
I thought I could use the `EXPLAIN` statement to do so.
So I tried using the `databricks-sql-connector` for python to explain a query, and so determine whether it's valid or not. Example python code:
```
import databricks.sql
with databricks.sql.connect(...) as connection:
with connection.cursor() as cursor:
cursor.execute("EXPLAIN SELECT BAD-QUERY AS FOO")
r = cursor.fetchall()
```
The problem with that implementation is that the driver does not throws an error, but instead retrieves me a string containing the error details.
Why it's a problem? I need to parse the string result to distinguish if the explained query was valid or not.
So I was wondering if there some kind of setting / parameter / configuration or so I can use to change the described above result.
Many thanks in Advance!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2022 02:07 AM
Hi @Hubert Dudek, thanks for replying!
The optimal solution I was looking for was in the databricks-sql-connector.
Installing large package such pyspark for this specific feature seems too much for my project purposes.
Thank you very much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 01:05 PM
Please try in pyspark:
try:
spark.sql("SELECT BAD-QUERY AS FOO")._jdf.queryExecution().toString()
except:
print("incorrect query")
or just:
try:
spark.sql("SELECT BAD-QUERY AS FOO").explain()
except:
print("incorrect query")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2022 02:07 AM
Hi @Hubert Dudek, thanks for replying!
The optimal solution I was looking for was in the databricks-sql-connector.
Installing large package such pyspark for this specific feature seems too much for my project purposes.
Thank you very much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 01:04 AM
Hi' I'm still searching for a more suited solution to my use case.
Installing pyspark seems too much (build time and extra packages I don't really need).
Is there a way to make this a feature request?
![](/skins/images/582998B45490C7019731A5B3A872C751/responsive_peak/images/icon_anonymous_message.png)
![](/skins/images/582998B45490C7019731A5B3A872C751/responsive_peak/images/icon_anonymous_message.png)