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

ENH: SQLAlchemy Default precision and scale to decimal types for PostgreSQL and MySQL #1969

Merged
merged 7 commits into from
Oct 12, 2019

Conversation

ian-r-rose
Copy link
Contributor

Possible fix for #1273

Adds default precision and scale to decimal types for PostgreSQL and MySQL. Numeric data types without defined precision and scale are allowed in these dialects (even if it is recommended that you specify them), and these tables exist in the wild.

I'm not sure if this is the best fix, but I was hoping to get a conversation started.

@xmnlab
Copy link
Contributor

xmnlab commented Sep 26, 2019

@ian-r-rose when you have a change, could you rebase your code on top of master?

@ian-r-rose
Copy link
Contributor Author

Rebased

@@ -100,6 +100,25 @@ def sa_boolean(_, satype, nullable=True):
return dt.Boolean(nullable=nullable)


@dt.dtype.register(MySQLDialect, sa.types.Numeric)
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems the tests have some conflict between float and decimal
maybe you can try sqlalchemy.types.DECIMAL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really, I'm not particularly interested in MySQL right now (just Postgres), but I'm having a tough time deciding how to handle when the generic SQLAlchemy backend should be used, and when a more specific backend should be used. In particular, I'm not really sure how the multiple dispatch handles this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

    -    float_col : float32
    +    float_col : decimal(1000, 0)

it seems the test for python 3.5 has this problem between float and decimal
maybe because the libraries in this environment is no updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for taking a look. I'm not sure what you mean here, what library is not updated?

@xmnlab
Copy link
Contributor

xmnlab commented Sep 30, 2019 via email

@ian-r-rose
Copy link
Contributor Author

Perhaps a better approach would be to allow None for precision and scale, since SQLAlchemy allows it?

@ian-r-rose
Copy link
Contributor Author

Okay, this is now passing CI.

xmnlab
xmnlab previously approved these changes Oct 3, 2019
Copy link
Contributor

@xmnlab xmnlab left a comment

Choose a reason for hiding this comment

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

Looks great @ian-r-rose, thanks for working on that.
let's give one more day to see if it receives more review.
and I can merge that tomorrow.

@xmnlab
Copy link
Contributor

xmnlab commented Oct 3, 2019

@ian-r-rose I was checking the tests and it seems there is no much tests for decimal.
would you mind to add some tests for decimal for the 3 backends related here? (mysql, postgresql and sqlite)

you can add the test to https://github.com/ibis-project/ibis/blob/master/ibis/tests/all/test_numeric.py

let me know if you want a hand with these tests.

@xmnlab xmnlab changed the title Default precision ENH: Default precision and scale to decimal types for PostgreSQL, MySQL and Sqlite Oct 3, 2019
@ian-r-rose
Copy link
Contributor Author

@xmnlab I can take a look, though I'm not really sure what these tests would look like. Do you have any examples to point me towards? I find the ibis test suite to be kind of confusing.

@xmnlab
Copy link
Contributor

xmnlab commented Oct 3, 2019

@ian-r-rose feel free to open an issue if you have any suggestion to improve the tests :) or to share your feelings about the current tests!

I think maybe just simple tests for the decimal operation with default and not default precision and scale should be enough.

there are some expression test here: https://github.com/ibis-project/ibis/blob/master/ibis/expr/tests/test_decimal.py

by expression test I mean it just test the expression it doesn't test it for the backend.

maybe you could get some tests from there and create the test for these 3 backends at /ibis/tests/all/test_numeric.py

@ian-r-rose
Copy link
Contributor Author

It's not really clear to me how to check for different behavior among the different backends in the expression tests. That is to say, I can instantiate datatypes or expressions as per the tests in test_decimal, but I don't know how to say "I expect the default precision and scale to be different for these backends".

@ian-r-rose
Copy link
Contributor Author

@xmnlab I've added some tests for this for PostgreSQL. I didn't see an obvious place for any mysql tests -- any suggestions? This PR doesn't touch sqlite, really.

@xmnlab xmnlab changed the title ENH: Default precision and scale to decimal types for PostgreSQL, MySQL and Sqlite ENH: Default precision and scale to decimal types for PostgreSQL and MySQL Oct 4, 2019
@toryhaavik
Copy link
Contributor

i think this looks good to me

@xmnlab
Copy link
Contributor

xmnlab commented Oct 4, 2019

Thanks @toryhaavik I am checking something. And if it is ok I will merge that.

@xmnlab
Copy link
Contributor

xmnlab commented Oct 4, 2019

hey @toryhaavik I need more time to review that.
I am playing with that (ian-r-rose#2) and it seems the sqlalchemy is not consistent to the default scale and precision .. and it needs to be forced as @ian-r-rose did it in the tests.

@xmnlab xmnlab self-requested a review October 4, 2019 22:46
@xmnlab xmnlab dismissed their stale review October 4, 2019 22:47

I need more time to review

@xmnlab xmnlab changed the title ENH: Default precision and scale to decimal types for PostgreSQL and MySQL ENH: SQLAlchemy Default precision and scale to decimal types for PostgreSQL and MySQL Oct 5, 2019
Add tests about decimal default precision and scale
@ian-r-rose
Copy link
Contributor Author

Now updated with some additional testing thanks to @xmnlab

Copy link
Contributor

@xmnlab xmnlab left a comment

Choose a reason for hiding this comment

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

Thanks @ian-r-rose! I will open an issue about the default precision and scale for ibis expressions

@xmnlab xmnlab merged commit b1c1b50 into ibis-project:master Oct 12, 2019
@ian-r-rose
Copy link
Contributor Author

Thanks for the review and help with the tests @xmnlab!

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.

3 participants