From a8abc496323f741d3218d298d5d2bb118fa01017 Mon Sep 17 00:00:00 2001 From: Neelesh Salian Date: Fri, 27 Jan 2023 17:00:39 -0800 Subject: [PATCH] [CT-1940] Stand-alone Python module for PostgresColumn (#6773) --- .changes/unreleased/Features-20230127-162812.yaml | 6 ++++++ plugins/postgres/dbt/adapters/postgres/__init__.py | 2 +- plugins/postgres/dbt/adapters/postgres/column.py | 12 ++++++++++++ plugins/postgres/dbt/adapters/postgres/impl.py | 2 +- plugins/postgres/dbt/adapters/postgres/relation.py | 12 ------------ 5 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 .changes/unreleased/Features-20230127-162812.yaml create mode 100644 plugins/postgres/dbt/adapters/postgres/column.py diff --git a/.changes/unreleased/Features-20230127-162812.yaml b/.changes/unreleased/Features-20230127-162812.yaml new file mode 100644 index 00000000000..8076cf3b18d --- /dev/null +++ b/.changes/unreleased/Features-20230127-162812.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Stand-alone Python module for PostgresColumn +time: 2023-01-27T16:28:12.212427-08:00 +custom: + Author: nssalian + Issue: "6772" diff --git a/plugins/postgres/dbt/adapters/postgres/__init__.py b/plugins/postgres/dbt/adapters/postgres/__init__.py index b5b3b7b7a09..38dce8bdb22 100644 --- a/plugins/postgres/dbt/adapters/postgres/__init__.py +++ b/plugins/postgres/dbt/adapters/postgres/__init__.py @@ -1,7 +1,7 @@ # these are mostly just exports, #noqa them so flake8 will be happy from dbt.adapters.postgres.connections import PostgresConnectionManager # noqa from dbt.adapters.postgres.connections import PostgresCredentials -from dbt.adapters.postgres.relation import PostgresColumn # noqa +from dbt.adapters.postgres.column import PostgresColumn # noqa from dbt.adapters.postgres.relation import PostgresRelation # noqa: F401 from dbt.adapters.postgres.impl import PostgresAdapter diff --git a/plugins/postgres/dbt/adapters/postgres/column.py b/plugins/postgres/dbt/adapters/postgres/column.py new file mode 100644 index 00000000000..686ec0cb8a4 --- /dev/null +++ b/plugins/postgres/dbt/adapters/postgres/column.py @@ -0,0 +1,12 @@ +from dbt.adapters.base import Column + + +class PostgresColumn(Column): + @property + def data_type(self): + # on postgres, do not convert 'text' or 'varchar' to 'varchar()' + if self.dtype.lower() == "text" or ( + self.dtype.lower() == "character varying" and self.char_size is None + ): + return self.dtype + return super().data_type diff --git a/plugins/postgres/dbt/adapters/postgres/impl.py b/plugins/postgres/dbt/adapters/postgres/impl.py index 9a5d5d3f8f6..9d729b5148e 100644 --- a/plugins/postgres/dbt/adapters/postgres/impl.py +++ b/plugins/postgres/dbt/adapters/postgres/impl.py @@ -5,7 +5,7 @@ from dbt.adapters.base.impl import AdapterConfig from dbt.adapters.sql import SQLAdapter from dbt.adapters.postgres import PostgresConnectionManager -from dbt.adapters.postgres import PostgresColumn +from dbt.adapters.postgres.column import PostgresColumn from dbt.adapters.postgres import PostgresRelation from dbt.dataclass_schema import dbtClassMixin, ValidationError from dbt.exceptions import ( diff --git a/plugins/postgres/dbt/adapters/postgres/relation.py b/plugins/postgres/dbt/adapters/postgres/relation.py index 43c8c724a74..820a69b0c64 100644 --- a/plugins/postgres/dbt/adapters/postgres/relation.py +++ b/plugins/postgres/dbt/adapters/postgres/relation.py @@ -1,4 +1,3 @@ -from dbt.adapters.base import Column from dataclasses import dataclass from dbt.adapters.base.relation import BaseRelation from dbt.exceptions import DbtRuntimeError @@ -21,14 +20,3 @@ def __post_init__(self): def relation_max_name_length(self): return 63 - - -class PostgresColumn(Column): - @property - def data_type(self): - # on postgres, do not convert 'text' or 'varchar' to 'varchar()' - if self.dtype.lower() == "text" or ( - self.dtype.lower() == "character varying" and self.char_size is None - ): - return self.dtype - return super().data_type