-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix boolean literals #357
Fix boolean literals #357
Conversation
Signed-off-by: Alex Holyoke <alexander.holyoke@growthloop.com>
@susodapop Can you take a look at this when you get a chance? |
@andrefurlan-db @benc-db @jackyhu-db can you take a look? And run the integration tests of our own before approving merge? |
Hey @aholyoke thanks for the ping. I'm not working on this repository anymore so what I can do is limited but you are welcome to ping me with questions about the sqlalchemy dialect any time. What version of SQLAlchemy are you running? Here's what I can tell you and the Databricks team: First, consider the tests that are failing. Notice that The change proposed by @aholyoke in this PR is a good one as it simply instructs SQLAlchemy to render the string literals
You understand If I had reviewing privileges on this PR I would approve this, but request one change: Add a unit test for this compilation that mirrors your exact reproduction steps. Here's a patch that does this (if you add me as an editor on your branch I can also just push this to it so it's bundled into your PR):
|
Also @aholyoke are you able to share the exact error message you see when def test_render_literal_bool(self, literal_round_trip):
literal_round_trip(Boolean(), [True, False], [True, False])
The In other words: this test should pass before your change. Thus my question at the top of this comment. I don't have a databricks environment I can run tests against anymore so I'm pawing around in the dark. |
Unit tests pass, trying integration now. |
Reproducing the issue:
Go to Query History in the workspace. See that it executes:
SELECT 1 AS anon_1, 0 AS anon_2
This becomes a problem when trying to compare to a boolean column:
In Databricks this produces the error:
[DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES] Cannot resolve "(value = 1)" due to data type mismatch: the left and right operands of the binary operator have incompatible types ("BOOLEAN" and "INT").; line 3 pos 6
SQLAlchemy has a flag called supports_native_boolean that controls this behaviour and is set to false by default. Setting this flag to true starts rendering booleans correctly:
At growthloop.com we've been using this fix in production for about a month and haven't had any issues.
I'm confused as to why some of the tests are failing on main when the description of _regression.py in README.tests.md implies tests in this file should be passing, maybe I'm running them incorrectly? Nevertheless, this change seems to be fixing a couple of the reusable dialect tests.
Before:
After: