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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions dbt/adapters/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dbt.adapters.default
import dbt.compat
import dbt.exceptions
from dbt.utils import max_digits
import agate

from dbt.logger import GLOBAL_LOGGER as logger
Expand Down Expand Up @@ -174,14 +173,8 @@ def convert_text_type(cls, agate_table, col_idx):

@classmethod
def convert_number_type(cls, agate_table, col_idx):
column = agate_table.columns[col_idx]
precision = max_digits(column.values_without_nulls())
# agate uses the term Precision but in this context, it is really the
# scale - ie. the number of decimal places
scale = agate_table.aggregate(agate.MaxPrecision(col_idx))
if not scale:
return "integer"
return "numeric({}, {})".format(precision, scale)
decimals = agate_table.aggregate(agate.MaxPrecision(col_idx))
return "numeric" if decimals else "integer"

@classmethod
def convert_boolean_type(cls, agate_table, col_idx):
Expand Down
13 changes: 0 additions & 13 deletions dbt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,19 +400,6 @@ def __get__(self, obj, objtype):
return functools.partial(self.__call__, obj)


def max_digits(values):
"""Given a series of decimal.Decimal values, find the maximum
number of digits (on both sides of the decimal point) used by the
values."""
max_ = 0
for value in values:
if value is None:
continue
sign, digits, exponent = value.normalize().as_tuple()
max_ = max(len(digits), max_)
return max_


def invalid_ref_fail_unless_test(node, target_model_name,
target_model_package):
if node.get('resource_type') == NodeType.Test:
Expand Down