From 4a2a9bf0d7ee7f6bddcaa32520fb37a5dad78f9e Mon Sep 17 00:00:00 2001 From: Mjumbe Poe Date: Fri, 15 Jun 2018 17:58:57 -0400 Subject: [PATCH 1/3] Ensure that numeric precision is included only if not None --- dbt/schema.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dbt/schema.py b/dbt/schema.py index b66cf95a821..944ede0e0fc 100644 --- a/dbt/schema.py +++ b/dbt/schema.py @@ -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 "".format(self.name, self.data_type) From 8440a0775f4f8d17a6347f5a6706d7441eb495f2 Mon Sep 17 00:00:00 2001 From: Mjumbe Poe Date: Sat, 16 Jun 2018 16:47:34 -0400 Subject: [PATCH 2/3] Add unit test for data_type of field with empty numeric precision --- test/unit/test_schema.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/unit/test_schema.py diff --git a/test/unit/test_schema.py b/test/unit/test_schema.py new file mode 100644 index 00000000000..a7c3d94fff0 --- /dev/null +++ b/test/unit/test_schema.py @@ -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') From e49bfc4cdc71c24b5d24b47054be3dc65b0c09d2 Mon Sep 17 00:00:00 2001 From: Mjumbe Poe Date: Sat, 16 Jun 2018 17:07:24 -0400 Subject: [PATCH 3/3] Add numeric fields to the schema_tests integration tests --- test/integration/008_schema_tests_test/seed.sql | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/integration/008_schema_tests_test/seed.sql b/test/integration/008_schema_tests_test/seed.sql index 3de2d1a234b..8f1801504ca 100644 --- a/test/integration/008_schema_tests_test/seed.sql +++ b/test/integration/008_schema_tests_test/seed.sql @@ -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 );