Skip to content

Commit

Permalink
Ensure that numeric precision is included only if not None (#796)
Browse files Browse the repository at this point in the history
* Ensure that numeric precision is included only if not None

* Add unit test for data_type of field with empty numeric precision

* Add numeric fields to the schema_tests integration tests
  • Loading branch information
mjumbewu authored and drewbanin committed Jun 16, 2018
1 parent fa43d9d commit 13691ad
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dbt/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def string_type(cls, size):
def numeric_type(cls, dtype, size):
# This could be decimal(...), numeric(...), number(...)
# Just use whatever was fed in here -- don't try to get too clever
return "{}({})".format(dtype, size)
if size is None:
return dtype
else:
return "{}({})".format(dtype, size)

def __repr__(self):
return "<Column {} ({})>".format(self.name, self.data_type)
Expand Down
4 changes: 4 additions & 0 deletions test/integration/008_schema_tests_test/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ create table {schema}.seed (
id INTEGER,
first_name VARCHAR(11),
email VARCHAR(31),

net_worth NUMERIC(12, 2) DEFAULT '100.00',
fav_number NUMERIC DEFAULT '3.14159265',

ip_address VARCHAR(15),
updated_at TIMESTAMP WITHOUT TIME ZONE
);
Expand Down
23 changes: 23 additions & 0 deletions test/unit/test_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import unittest

import dbt.schema


class TestNumericType(unittest.TestCase):

def test__numeric_type(self):
col = dbt.schema.Column(
'fieldname',
'numeric',
numeric_size='12,2')

self.assertEqual(col.data_type, 'numeric(12,2)')

def test__numeric_type_with_no_precision(self):
# PostgreSQL, at least, will allow empty numeric precision
col = dbt.schema.Column(
'fieldname',
'numeric',
numeric_size=None)

self.assertEqual(col.data_type, 'numeric')

0 comments on commit 13691ad

Please sign in to comment.