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

fix csv precision #684

Merged
merged 4 commits into from
Mar 8, 2018
Merged

fix csv precision #684

merged 4 commits into from
Mar 8, 2018

Conversation

cmcarthur
Copy link
Member

dbt 0.9.2 RC had a bug where we miscalculate the precision required for decimal values like 0.001. we were attempting to create a numeric(1,3) which doesn't make sense -- according to the Postgres docs:

NUMERIC(precision, scale)
The scale of a numeric is the count of decimal digits in the fractional part, to the right of the decimal point. The precision of a numeric is the total count of significant digits in the whole number, that is, the number of digits to both sides of the decimal point. So the number 23.5141 has a precision of 6 and a scale of 4. Integers can be considered to have a scale of zero.

So the precision should be 4, not 1. This branch fixes that.

@cmcarthur
Copy link
Member Author

Used the file in #683 to test, also wrote unit tests for that max_digits fn

@drewbanin
Copy link
Contributor

@cmcarthur lgtm! Nice job on that test

@@ -1,5 +1,7 @@
import unittest

from decimal import Decimal
Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed?

@joevandyk
Copy link
Contributor

not a fan of that code climate "duplicate code" check that's currently failing btw. duplicate code is not always bad, trying to solve it often makes for more complicated code.

@drewbanin
Copy link
Contributor

right there with you @joevandyk -- sometimes no abstraction is better than a bad abstraction

@joevandyk
Copy link
Contributor

joevandyk commented Mar 7, 2018

I confirmed this fixed my issue with loading the csv file. I think getting rid of the datatype limits is a good idea, as it allows for the truncate/insert strategy with different lengths of data.

Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

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

lgtm!

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