Skip to content

Commit

Permalink
CT-2103: Implement data_type_code_to_name for redshift (dbt-labs#346)
Browse files Browse the repository at this point in the history
* CT-2103: Implement data_type_code_to_name for redshift

* CT-2103: Hardcode dbt version for testing.

* CT-2103: Update dev-requirements to use branch name

Co-authored-by: Jeremy Cohen <[email protected]>

* CT-2103: Fix mypy complaint

* CT-2103: Provide a Redshift specific override of test cases for new tests

* CT-2103: Remove now-unneeded fixture overrides

* CT-2103: Remove temporary branch hacks in dev-requirements.txt

* CT-2103: Revert temporary branch changes to setup.py

---------

Co-authored-by: Jeremy Cohen <[email protected]>
Co-authored-by: colin-rogers-dbt <[email protected]>
Co-authored-by: Mike Alfare <[email protected]>
  • Loading branch information
4 people authored Mar 3, 2023
1 parent 24ad0f0 commit 648a00c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230301-113553.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Implemented data_type_code_to_name for redshift
time: 2023-03-01T11:35:53.98885-05:00
custom:
Author: peterallenwebb
Issue: "319"
7 changes: 6 additions & 1 deletion dbt/adapters/redshift/connections.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from multiprocessing import Lock
from contextlib import contextmanager
from typing import NewType, Tuple
from typing import NewType, Tuple, Union

import agate
import sqlparse
Expand All @@ -18,6 +18,7 @@

from dbt.helper_types import Port
from redshift_connector import OperationalError, DatabaseError, DataError
from redshift_connector.utils.oids import get_datatype_name

logger = AdapterLogger("Redshift")

Expand Down Expand Up @@ -278,3 +279,7 @@ def add_query(self, sql, auto_begin=True, bindings=None, abridge_sql_log=False):
@classmethod
def get_credentials(cls, credentials):
return credentials

@classmethod
def data_type_code_to_name(cls, type_code: Union[int, str]) -> str:
return get_datatype_name(type_code)
17 changes: 16 additions & 1 deletion tests/functional/adapter/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,23 @@
;
"""


class TestRedshiftConstraintsColumnsEqual(BaseConstraintsColumnsEqual):
pass
@pytest.fixture
def data_types(self, schema_int_type, int_type, string_type):
# NOTE: Unlike some other adapters, we don't test array or JSON types here, because
# Redshift does not support them as materialized table column types.

# sql_column_value, schema_data_type, error_data_type
return [
["1", schema_int_type, int_type],
["'1'", string_type, string_type],
["cast('2019-01-01' as date)", "date", "DATE"],
["true", "bool", "BOOL"],
["'2013-11-03 00:00:00-07'::timestamptz", "timestamptz", "TIMESTAMPTZ"],
["'2013-11-03 00:00:00-07'::timestamp", "timestamp", "TIMESTAMP"],
["'1'::numeric", "numeric", "NUMERIC"]
]


class TestRedshiftConstraintsRuntimeEnforcement(BaseConstraintsRuntimeEnforcement):
Expand Down

0 comments on commit 648a00c

Please sign in to comment.