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

Remove APIObject (#1762) #1780

Merged
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
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## dbt 0.15.0 (TBD)

### Breaking changes
- The 'table_name' parameter to relations has been removed
- Cache management changes:
- Materialization macros should now return a dictionary {"relations": [...]}, with the list containing all relations that have been added, in order to add them to the cache. The default behavior is to still add the materialization's model to the cache.
- Materializations that perform drops via direct "drop" statements must call `adapter.cache_dropped`
Expand All @@ -18,8 +19,6 @@ This is a bugfix release.
### Under the hood:
- Provide a programmatic method for validating profile targets ([#1754](https://github.com/fishtown-analytics/dbt/issues/1754), [#1775](https://github.com/fishtown-analytics/dbt/pull/1775))

>>>>>>> dev/0.14.3
## dbt 0.14.2 (September 13, 2019)

### Overview
Expand Down
8 changes: 5 additions & 3 deletions core/dbt/adapters/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# these are all just exports, #noqa them so flake8 will be happy

# TODO: Should we still include this in the `adapters` namespace?
from dbt.contracts.connection import Credentials # noqa
from dbt.adapters.base.meta import available # noqa
from dbt.adapters.base.relation import BaseRelation # noqa
from dbt.adapters.base.relation import Column # noqa
from dbt.adapters.base.connections import BaseConnectionManager # noqa
from dbt.adapters.base.connections import Credentials # noqa
from dbt.adapters.base.relation import BaseRelation, RelationType # noqa
from dbt.adapters.base.column import Column # noqa
from dbt.adapters.base.impl import BaseAdapter # noqa
from dbt.adapters.base.plugin import AdapterPlugin # noqa
93 changes: 93 additions & 0 deletions core/dbt/adapters/base/column.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from dataclasses import dataclass

from hologram import JsonSchemaMixin

from typing import TypeVar, Dict, ClassVar, Any, Optional, Type

Self = TypeVar('Self', bound='Column')


@dataclass
class Column(JsonSchemaMixin):
TYPE_LABELS: ClassVar[Dict[str, str]] = {
'STRING': 'TEXT',
'TIMESTAMP': 'TIMESTAMP',
'FLOAT': 'FLOAT',
'INTEGER': 'INT'
}
column: str
dtype: str
char_size: Optional[int] = None
numeric_precision: Optional[Any] = None
numeric_scale: Optional[Any] = None

@classmethod
def translate_type(cls, dtype: str) -> str:
return cls.TYPE_LABELS.get(dtype.upper(), dtype)

@classmethod
def create(cls: Type[Self], name, label_or_dtype: str) -> Self:
column_type = cls.translate_type(label_or_dtype)
return cls(name, column_type)

@property
def name(self) -> str:
return self.column

@property
def quoted(self) -> str:
return '"{}"'.format(self.column)

@property
def data_type(self) -> str:
if self.is_string():
return Column.string_type(self.string_size())
elif self.is_numeric():
return Column.numeric_type(self.dtype, self.numeric_precision,
self.numeric_scale)
else:
return self.dtype

def is_string(self) -> bool:
return self.dtype.lower() in ['text', 'character varying', 'character',
'varchar']

def is_numeric(self) -> bool:
return self.dtype.lower() in ['numeric', 'number']

def string_size(self) -> int:
if not self.is_string():
raise RuntimeError("Called string_size() on non-string field!")

if self.dtype == 'text' or self.char_size is None:
# char_size should never be None. Handle it reasonably just in case
return 256
else:
return int(self.char_size)

def can_expand_to(self: Self, other_column: Self) -> bool:
"""returns True if this column can be expanded to the size of the
other column"""
if not self.is_string() or not other_column.is_string():
return False

return other_column.string_size() > self.string_size()

def literal(self, value: Any) -> str:
return "{}::{}".format(value, self.data_type)

@classmethod
def string_type(cls, size: int) -> str:
return "character varying({})".format(size)

@classmethod
def numeric_type(cls, dtype: str, precision: Any, scale: Any) -> str:
# This could be decimal(...), numeric(...), number(...)
# Just use whatever was fed in here -- don't try to get too clever
if precision is None or scale is None:
return dtype
else:
return "{}({},{})".format(dtype, precision, scale)

def __repr__(self) -> str:
return "<Column {} ({})>".format(self.name, self.data_type)
Loading