Comments (8)
Thanks for opening this issue and apologies for the late response. I've added a ticket for this to our development backlog. Will update this ticket once I have further information (should be next week).
from databricks-sql-python.
Okay I've investigated this a bit further. There is no bug in databricks-sql-connector
here.
The problem with that implementation is that the driver does not throws an error, but instead retrieves me a string containing the error details, so I need to parse the string result to distinguish if the explained query was valid or not.
This is expected behaviour. EXPLAIN
only raises an exception if there was an problem during execution. In all other cases it returns rows of strings. It is left to the end-user to reason with these outputs. A common pattern is to simply display the output to the end user (this is what Databricks SQL does, so does Redash).
If you need to programmatically handle the output of an EXPLAIN
command, then you will need to parse the rows of strings as you said or choose a different method of verification. One option is to instead SELECT
the query with a LIMIT 0
clause. Doing so does raise an Exception.
INPUT
SELECT BAD-QUERY AS FOO LIMIT 0
OUTPUT
Exception has occurred: ServerOperationError
[MISSING_COLUMN] Column 'BAD' does not exist. Did you mean one of the following? []; line 1 pos 7
File "databricks-sql-connector/src/databricks/sql/thrift_backend.py", line 484, in _check_command_not_in_error_or_closed_state
"diagnostic-info": get_operations_resp.diagnosticInfo,
File "databricks-sql-connector/src/databricks/sql/thrift_backend.py", line 751, in _wait_until_command_done
op_handle, initial_operation_status_resp
File "databricks-sql-connector/src/databricks/sql/thrift_backend.py", line 908, in _handle_execute_response
resp.directResults and resp.directResults.operationStatus,
File "databricks-sql-connector/src/databricks/sql/thrift_backend.py", line 814, in execute_command
return self._handle_execute_response(resp, cursor)
File "databricks-sql-connector/src/databricks/sql/client.py", line 321, in execute
cursor=self,
File "databricks-sql-connector/main.py", line 18, in <module>
cursor.execute("SELECT BAD-QUERY AS FOO LIMIT 0")
from databricks-sql-python.
Makes sense. The answer for our connector is the same: we won't raise an exception unless the SQL warehouse / cluster raises one. But I'm passing this feedback onto that team within Databricks. It's unusual that SQL warehouses don't raise a standard error in this case.
from databricks-sql-python.
Thanks for opening this issue and apologies for the late response. I've added a ticket for this to our development backlog. Will update this ticket once I have further information (should be next week).
Sweet thanks a lot!
from databricks-sql-python.
@susodapop Thanks for your reply & time checking this out!
Guess I was used to other outcome as other connectors do raise exception..
The limit 0 option is definitely better than parsing strings, so I'll use that.
Do you happen to know the cost of executing such query?
I'd like to prevent high costs for checking validity of an SQL statement..
from databricks-sql-python.
Guess I was used to other outcome as other connectors do raise exception
Which other connectors raise an exception in this case?
from databricks-sql-python.
For my project purposes I also use AWS athena, Vertica, postgresql & clickhouse
Using explain SELECT 1 AS FOO
& explain SELECT BAD_QUERY AS FOO
you can examine the different output in other DBs 😃:
from clickhouse_driver import Client
client = Client(host="play.clickhouse.com", user="explorer", secure=True)
good = client.query_dataframe("explain SELECT 1 AS FOO")
bad = client.query_dataframe("explain SELECT BAD_QUERY AS FOO")
from databricks-sql-python.
Sounds great, Thanks!
from databricks-sql-python.
Related Issues (20)
- [Document] Support databricks-cli authentication HOT 1
- Dash/Minus in column name causes UNBOUND_SQL_PARAMETER in bind values HOT 2
- Extremely slow import times on Python 3.12 HOT 9
- [sqlalchemy] execute("select 1") gives TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType' HOT 8
- `databricks.sql.connect` hangs in a long retrying loop when an invalid access token is used HOT 3
- Idea: arrow_record_batches cursor method
- SQLAlchemy engine from workspace level service principle? HOT 2
- Unable to write list/array type data HOT 2
- Issue with version 3.1.1
- Failure on cursor.fetchall() HOT 2
- Fixing a couple type problems. (adding py.typed, typing connect, returning Any from fetchall (which I failed to fix!)) HOT 2
- Connector reads 0 rows although Cluster returned results HOT 18
- support new Cursor attribute that provides information on completed commands HOT 1
- loosen, update, or widen pyarrow dependencies HOT 2
- ImportError: cannot import name 'sql' from partially initialized module 'databricks' HOT 2
- Unpin Thrift
- Original thrift file HOT 3
- Invalid SessionHandle Error
- PyCharm IDE + pandas exit code 139
- [Feature Request] Support async execution
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 databricks-sql-python.