Skip to content
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

fixing problems with comments that have % and fixing incompatibility with MySQL #362

Merged
merged 14 commits into from
Apr 5, 2023

Conversation

edublancas
Copy link

@edublancas edublancas commented Apr 5, 2023

Describe your changes

This PR fixes several problems:

  1. All internal queries now switch between " and backticks depending on the dialect
  2. passing text objects to the execute method to prevent SQLAlchemy from interpreting stuff like %name as query parameter

Issue number

Closes #X

Checklist before requesting a review


📚 Documentation preview 📚: https://jupysql--362.org.readthedocs.build/en/362/

@edublancas edublancas marked this pull request as ready for review April 5, 2023 14:10
@edublancas edublancas changed the title fixes fixing problems with comments that have % and fixing incompatibility with MySQL Apr 5, 2023
Copy link

@yafimvo yafimvo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

Tested locally these code cells and it works:

%%sql --save many_passengers --no-execute
SELECT *
FROM taxi
WHERE passenger_count > 3
-- remove top 1% outliers for better visualization
AND trip_distance < 18.93

Returns a table

%sql --with many_passengers select * from many_passengers limit 2

Returns a plot

%sqlplot histogram --table many_passengers --column trip_distance --with many_passengers

)

if use_backticks:
template_ = template_.replace('"', "`")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the future we can make it dynamic because there might be exceptional DBs, and we don't want to have to pass use_backticks and check it every time we run a query.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm passing it depending on the dialect type, but yes, we need to come up with a more reliable way

Copy link

@idomic idomic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lg, added small comment

@@ -482,9 +486,13 @@ def _histogram(table, column, bins, with_=None, conn=None, facet=None):
"""Compute bins and heights"""
if not conn:
conn = sql.connection.Connection.current.session
use_backticks = sql.connection.Connection.is_use_backtick_template()
else:
# TODO: fix
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to open an issue on this.

@tonykploomber
Copy link

I think I have a lot similar fix in https://github.com/ploomber/jupysql/pull/339/files

But LGTM

@edublancas edublancas merged commit 5b60464 into master Apr 5, 2023
@edublancas edublancas deleted the plot-backticks branch April 5, 2023 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants