dbt-adapters 0.1.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dbt-adapters might be problematic. Click here for more details.

Files changed (147) hide show
  1. dbt/__init__.py +0 -0
  2. dbt/adapters/__about__.py +1 -0
  3. dbt/adapters/__init__.py +7 -0
  4. dbt/adapters/base/README.md +13 -0
  5. dbt/adapters/base/__init__.py +15 -0
  6. dbt/adapters/base/column.py +166 -0
  7. dbt/adapters/base/connections.py +426 -0
  8. dbt/adapters/base/impl.py +1654 -0
  9. dbt/adapters/base/meta.py +131 -0
  10. dbt/adapters/base/plugin.py +32 -0
  11. dbt/adapters/base/query_headers.py +101 -0
  12. dbt/adapters/base/relation.py +471 -0
  13. dbt/adapters/cache.py +521 -0
  14. dbt/adapters/capability.py +52 -0
  15. dbt/adapters/clients/__init__.py +0 -0
  16. dbt/adapters/clients/jinja.py +24 -0
  17. dbt/adapters/contracts/__init__.py +0 -0
  18. dbt/adapters/contracts/connection.py +228 -0
  19. dbt/adapters/contracts/macros.py +11 -0
  20. dbt/adapters/contracts/relation.py +125 -0
  21. dbt/adapters/events/README.md +57 -0
  22. dbt/adapters/events/__init__.py +0 -0
  23. dbt/adapters/events/adapter_types.proto +517 -0
  24. dbt/adapters/events/adapter_types_pb2.py +208 -0
  25. dbt/adapters/events/base_types.py +40 -0
  26. dbt/adapters/events/logging.py +83 -0
  27. dbt/adapters/events/types.py +423 -0
  28. dbt/adapters/exceptions/__init__.py +40 -0
  29. dbt/adapters/exceptions/alias.py +24 -0
  30. dbt/adapters/exceptions/cache.py +68 -0
  31. dbt/adapters/exceptions/compilation.py +255 -0
  32. dbt/adapters/exceptions/connection.py +16 -0
  33. dbt/adapters/exceptions/database.py +51 -0
  34. dbt/adapters/factory.py +246 -0
  35. dbt/adapters/protocol.py +173 -0
  36. dbt/adapters/reference_keys.py +39 -0
  37. dbt/adapters/relation_configs/README.md +25 -0
  38. dbt/adapters/relation_configs/__init__.py +12 -0
  39. dbt/adapters/relation_configs/config_base.py +44 -0
  40. dbt/adapters/relation_configs/config_change.py +24 -0
  41. dbt/adapters/relation_configs/config_validation.py +57 -0
  42. dbt/adapters/sql/__init__.py +2 -0
  43. dbt/adapters/sql/connections.py +195 -0
  44. dbt/adapters/sql/impl.py +273 -0
  45. dbt/adapters/utils.py +69 -0
  46. dbt/include/global_project/__init__.py +4 -0
  47. dbt/include/global_project/dbt_project.yml +7 -0
  48. dbt/include/global_project/docs/overview.md +43 -0
  49. dbt/include/global_project/macros/adapters/apply_grants.sql +167 -0
  50. dbt/include/global_project/macros/adapters/columns.sql +137 -0
  51. dbt/include/global_project/macros/adapters/freshness.sql +16 -0
  52. dbt/include/global_project/macros/adapters/indexes.sql +41 -0
  53. dbt/include/global_project/macros/adapters/metadata.sql +96 -0
  54. dbt/include/global_project/macros/adapters/persist_docs.sql +33 -0
  55. dbt/include/global_project/macros/adapters/relation.sql +79 -0
  56. dbt/include/global_project/macros/adapters/schema.sql +20 -0
  57. dbt/include/global_project/macros/adapters/show.sql +22 -0
  58. dbt/include/global_project/macros/adapters/timestamps.sql +44 -0
  59. dbt/include/global_project/macros/adapters/validate_sql.sql +10 -0
  60. dbt/include/global_project/macros/etc/datetime.sql +62 -0
  61. dbt/include/global_project/macros/etc/statement.sql +52 -0
  62. dbt/include/global_project/macros/generic_test_sql/accepted_values.sql +27 -0
  63. dbt/include/global_project/macros/generic_test_sql/not_null.sql +9 -0
  64. dbt/include/global_project/macros/generic_test_sql/relationships.sql +23 -0
  65. dbt/include/global_project/macros/generic_test_sql/unique.sql +12 -0
  66. dbt/include/global_project/macros/get_custom_name/get_custom_alias.sql +36 -0
  67. dbt/include/global_project/macros/get_custom_name/get_custom_database.sql +32 -0
  68. dbt/include/global_project/macros/get_custom_name/get_custom_schema.sql +60 -0
  69. dbt/include/global_project/macros/materializations/configs.sql +21 -0
  70. dbt/include/global_project/macros/materializations/hooks.sql +35 -0
  71. dbt/include/global_project/macros/materializations/models/clone/can_clone_table.sql +7 -0
  72. dbt/include/global_project/macros/materializations/models/clone/clone.sql +67 -0
  73. dbt/include/global_project/macros/materializations/models/clone/create_or_replace_clone.sql +7 -0
  74. dbt/include/global_project/macros/materializations/models/incremental/column_helpers.sql +80 -0
  75. dbt/include/global_project/macros/materializations/models/incremental/incremental.sql +92 -0
  76. dbt/include/global_project/macros/materializations/models/incremental/is_incremental.sql +13 -0
  77. dbt/include/global_project/macros/materializations/models/incremental/merge.sql +131 -0
  78. dbt/include/global_project/macros/materializations/models/incremental/on_schema_change.sql +144 -0
  79. dbt/include/global_project/macros/materializations/models/incremental/strategies.sql +79 -0
  80. dbt/include/global_project/macros/materializations/models/materialized_view.sql +121 -0
  81. dbt/include/global_project/macros/materializations/models/table.sql +64 -0
  82. dbt/include/global_project/macros/materializations/models/view.sql +72 -0
  83. dbt/include/global_project/macros/materializations/seeds/helpers.sql +128 -0
  84. dbt/include/global_project/macros/materializations/seeds/seed.sql +60 -0
  85. dbt/include/global_project/macros/materializations/snapshots/helpers.sql +181 -0
  86. dbt/include/global_project/macros/materializations/snapshots/snapshot.sql +99 -0
  87. dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql +25 -0
  88. dbt/include/global_project/macros/materializations/snapshots/strategies.sql +174 -0
  89. dbt/include/global_project/macros/materializations/tests/helpers.sql +14 -0
  90. dbt/include/global_project/macros/materializations/tests/test.sql +60 -0
  91. dbt/include/global_project/macros/materializations/tests/where_subquery.sql +15 -0
  92. dbt/include/global_project/macros/python_model/python.sql +103 -0
  93. dbt/include/global_project/macros/relations/column/columns_spec_ddl.sql +89 -0
  94. dbt/include/global_project/macros/relations/create.sql +23 -0
  95. dbt/include/global_project/macros/relations/create_backup.sql +17 -0
  96. dbt/include/global_project/macros/relations/create_intermediate.sql +17 -0
  97. dbt/include/global_project/macros/relations/drop.sql +41 -0
  98. dbt/include/global_project/macros/relations/drop_backup.sql +14 -0
  99. dbt/include/global_project/macros/relations/materialized_view/alter.sql +55 -0
  100. dbt/include/global_project/macros/relations/materialized_view/create.sql +10 -0
  101. dbt/include/global_project/macros/relations/materialized_view/drop.sql +14 -0
  102. dbt/include/global_project/macros/relations/materialized_view/refresh.sql +9 -0
  103. dbt/include/global_project/macros/relations/materialized_view/rename.sql +10 -0
  104. dbt/include/global_project/macros/relations/materialized_view/replace.sql +10 -0
  105. dbt/include/global_project/macros/relations/rename.sql +35 -0
  106. dbt/include/global_project/macros/relations/rename_intermediate.sql +14 -0
  107. dbt/include/global_project/macros/relations/replace.sql +50 -0
  108. dbt/include/global_project/macros/relations/schema.sql +8 -0
  109. dbt/include/global_project/macros/relations/table/create.sql +60 -0
  110. dbt/include/global_project/macros/relations/table/drop.sql +14 -0
  111. dbt/include/global_project/macros/relations/table/rename.sql +10 -0
  112. dbt/include/global_project/macros/relations/table/replace.sql +10 -0
  113. dbt/include/global_project/macros/relations/view/create.sql +27 -0
  114. dbt/include/global_project/macros/relations/view/drop.sql +14 -0
  115. dbt/include/global_project/macros/relations/view/rename.sql +10 -0
  116. dbt/include/global_project/macros/relations/view/replace.sql +66 -0
  117. dbt/include/global_project/macros/utils/any_value.sql +9 -0
  118. dbt/include/global_project/macros/utils/array_append.sql +8 -0
  119. dbt/include/global_project/macros/utils/array_concat.sql +7 -0
  120. dbt/include/global_project/macros/utils/array_construct.sql +12 -0
  121. dbt/include/global_project/macros/utils/bool_or.sql +9 -0
  122. dbt/include/global_project/macros/utils/cast_bool_to_text.sql +7 -0
  123. dbt/include/global_project/macros/utils/concat.sql +7 -0
  124. dbt/include/global_project/macros/utils/data_types.sql +129 -0
  125. dbt/include/global_project/macros/utils/date_spine.sql +75 -0
  126. dbt/include/global_project/macros/utils/date_trunc.sql +7 -0
  127. dbt/include/global_project/macros/utils/dateadd.sql +14 -0
  128. dbt/include/global_project/macros/utils/datediff.sql +14 -0
  129. dbt/include/global_project/macros/utils/escape_single_quotes.sql +8 -0
  130. dbt/include/global_project/macros/utils/except.sql +9 -0
  131. dbt/include/global_project/macros/utils/generate_series.sql +53 -0
  132. dbt/include/global_project/macros/utils/hash.sql +7 -0
  133. dbt/include/global_project/macros/utils/intersect.sql +9 -0
  134. dbt/include/global_project/macros/utils/last_day.sql +15 -0
  135. dbt/include/global_project/macros/utils/length.sql +11 -0
  136. dbt/include/global_project/macros/utils/listagg.sql +30 -0
  137. dbt/include/global_project/macros/utils/literal.sql +7 -0
  138. dbt/include/global_project/macros/utils/position.sql +11 -0
  139. dbt/include/global_project/macros/utils/replace.sql +14 -0
  140. dbt/include/global_project/macros/utils/right.sql +12 -0
  141. dbt/include/global_project/macros/utils/safe_cast.sql +9 -0
  142. dbt/include/global_project/macros/utils/split_part.sql +26 -0
  143. dbt/include/global_project/tests/generic/builtin.sql +30 -0
  144. dbt_adapters-0.1.0a1.dist-info/METADATA +81 -0
  145. dbt_adapters-0.1.0a1.dist-info/RECORD +147 -0
  146. dbt_adapters-0.1.0a1.dist-info/WHEEL +4 -0
  147. dbt_adapters-0.1.0a1.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,131 @@
1
+ import abc
2
+ from functools import wraps
3
+ from typing import Any, Callable, Dict, FrozenSet, Optional, Set
4
+
5
+ from dbt_common.events.functions import warn_or_error
6
+
7
+ from dbt.adapters.events.types import AdapterDeprecationWarning
8
+
9
+
10
+ Decorator = Callable[[Any], Callable]
11
+
12
+
13
+ class _Available:
14
+ def __call__(self, func: Callable) -> Callable:
15
+ func._is_available_ = True # type: ignore
16
+ return func
17
+
18
+ def parse(self, parse_replacement: Callable) -> Decorator:
19
+ """A decorator factory to indicate that a method on the adapter will be
20
+ exposed to the database wrapper, and will be stubbed out at parse time
21
+ with the given function.
22
+
23
+ @available.parse()
24
+ def my_method(self, a, b):
25
+ if something:
26
+ return None
27
+ return big_expensive_db_query()
28
+
29
+ @available.parse(lambda *args, **args: {})
30
+ def my_other_method(self, a, b):
31
+ x = {}
32
+ x.update(big_expensive_db_query())
33
+ return x
34
+ """
35
+
36
+ def inner(func):
37
+ func._parse_replacement_ = parse_replacement
38
+ return self(func)
39
+
40
+ return inner
41
+
42
+ def deprecated(
43
+ self, supported_name: str, parse_replacement: Optional[Callable] = None
44
+ ) -> Decorator:
45
+ """A decorator that marks a function as available, but also prints a
46
+ deprecation warning. Use like
47
+
48
+ @available.deprecated('my_new_method')
49
+ def my_old_method(self, arg):
50
+ args = compatability_shim(arg)
51
+ return self.my_new_method(*args)
52
+
53
+ @available.deprecated('my_new_slow_method', lambda *a, **k: (0, ''))
54
+ def my_old_slow_method(self, arg):
55
+ args = compatibility_shim(arg)
56
+ return self.my_new_slow_method(*args)
57
+
58
+ To make `adapter.my_old_method` available but also print out a warning
59
+ on use directing users to `my_new_method`.
60
+
61
+ The optional parse_replacement, if provided, will provide a parse-time
62
+ replacement for the actual method (see `available.parse`).
63
+ """
64
+
65
+ def wrapper(func):
66
+ func_name = func.__name__
67
+
68
+ @wraps(func)
69
+ def inner(*args, **kwargs):
70
+ warn_or_error(
71
+ AdapterDeprecationWarning(old_name=func_name, new_name=supported_name)
72
+ )
73
+ return func(*args, **kwargs)
74
+
75
+ if parse_replacement:
76
+ available_function = self.parse(parse_replacement)
77
+ else:
78
+ available_function = self
79
+ return available_function(inner)
80
+
81
+ return wrapper
82
+
83
+ def parse_none(self, func: Callable) -> Callable:
84
+ wrapper = self.parse(lambda *a, **k: None)
85
+ return wrapper(func)
86
+
87
+ def parse_list(self, func: Callable) -> Callable:
88
+ wrapper = self.parse(lambda *a, **k: [])
89
+ return wrapper(func)
90
+
91
+
92
+ available = _Available()
93
+
94
+
95
+ class AdapterMeta(abc.ABCMeta):
96
+ _available_: FrozenSet[str]
97
+ _parse_replacements_: Dict[str, Callable]
98
+
99
+ def __new__(mcls, name, bases, namespace, **kwargs) -> "AdapterMeta":
100
+ # mypy does not like the `**kwargs`. But `ABCMeta` itself takes
101
+ # `**kwargs` in its argspec here (and passes them to `type.__new__`.
102
+ # I'm not sure there is any benefit to it after poking around a bit,
103
+ # but having it doesn't hurt on the python side (and omitting it could
104
+ # hurt for obscure metaclass reasons, for all I know)
105
+ cls = abc.ABCMeta.__new__(mcls, name, bases, namespace, **kwargs) # type: ignore
106
+
107
+ # this is very much inspired by ABCMeta's own implementation
108
+
109
+ # dict mapping the method name to whether the model name should be
110
+ # injected into the arguments. All methods in here are exposed to the
111
+ # context.
112
+ available: Set[str] = set()
113
+ replacements: Dict[str, Any] = {}
114
+
115
+ # collect base class data first
116
+ for base in bases:
117
+ available.update(getattr(base, "_available_", set()))
118
+ replacements.update(getattr(base, "_parse_replacements_", set()))
119
+
120
+ # override with local data if it exists
121
+ for name, value in namespace.items():
122
+ if getattr(value, "_is_available_", False):
123
+ available.add(name)
124
+ parse_replacement = getattr(value, "_parse_replacement_", None)
125
+ if parse_replacement is not None:
126
+ replacements[name] = parse_replacement
127
+
128
+ cls._available_ = frozenset(available)
129
+ # should this be a namedtuple so it will be immutable like _available_?
130
+ cls._parse_replacements_ = replacements
131
+ return cls
@@ -0,0 +1,32 @@
1
+ from pathlib import Path
2
+ from typing import List, Optional, Type
3
+
4
+ from dbt.adapters.contracts.connection import Credentials
5
+ from dbt.adapters.protocol import AdapterProtocol
6
+
7
+
8
+ class AdapterPlugin:
9
+ """Defines the basic requirements for a dbt adapter plugin.
10
+
11
+ :param include_path: The path to this adapter plugin's root
12
+ :param dependencies: A list of adapter names that this adapter depends
13
+ upon.
14
+ """
15
+
16
+ def __init__(
17
+ self,
18
+ adapter: Type[AdapterProtocol],
19
+ credentials: Type[Credentials],
20
+ include_path: str,
21
+ dependencies: Optional[List[str]] = None,
22
+ project_name: Optional[str] = None,
23
+ ) -> None:
24
+ self.adapter: Type[AdapterProtocol] = adapter
25
+ self.credentials: Type[Credentials] = credentials
26
+ self.include_path: str = include_path
27
+ self.project_name: str = project_name or f"dbt_{Path(include_path).name}"
28
+ self.dependencies: List[str]
29
+ if dependencies is None:
30
+ self.dependencies = []
31
+ else:
32
+ self.dependencies = dependencies
@@ -0,0 +1,101 @@
1
+ from threading import local
2
+ from typing import Any, Callable, Dict, Optional
3
+
4
+ from dbt_common.exceptions import DbtRuntimeError
5
+
6
+ from dbt.adapters.clients.jinja import QueryStringGenerator
7
+ from dbt.adapters.contracts.connection import AdapterRequiredConfig, QueryComment
8
+
9
+
10
+ class QueryHeaderContextWrapper:
11
+ def __init__(self, context) -> None:
12
+ self._inner_context = context
13
+
14
+ def __getattr__(self, name):
15
+ return getattr(self._inner_context, name, "")
16
+
17
+
18
+ class _QueryComment(local):
19
+ """A thread-local class storing thread-specific state information for
20
+ connection management, namely:
21
+ - the current thread's query comment.
22
+ - a source_name indicating what set the current thread's query comment
23
+ """
24
+
25
+ def __init__(self, initial) -> None:
26
+ self.query_comment: Optional[str] = initial
27
+ self.append: bool = False
28
+
29
+ def add(self, sql: str) -> str:
30
+ if not self.query_comment:
31
+ return sql
32
+
33
+ if self.append:
34
+ # replace last ';' with '<comment>;'
35
+ sql = sql.rstrip()
36
+ if sql[-1] == ";":
37
+ sql = sql[:-1]
38
+ return "{}\n/* {} */;".format(sql, self.query_comment.strip())
39
+
40
+ return "{}\n/* {} */".format(sql, self.query_comment.strip())
41
+
42
+ return "/* {} */\n{}".format(self.query_comment.strip(), sql)
43
+
44
+ def set(self, comment: Optional[str], append: bool):
45
+ if isinstance(comment, str) and "*/" in comment:
46
+ # tell the user "no" so they don't hurt themselves by writing
47
+ # garbage
48
+ raise DbtRuntimeError(f'query comment contains illegal value "*/": {comment}')
49
+ self.query_comment = comment
50
+ self.append = append
51
+
52
+
53
+ QueryStringFunc = Callable[[str, Optional[QueryHeaderContextWrapper]], str]
54
+
55
+
56
+ class MacroQueryStringSetter:
57
+ def __init__(
58
+ self, config: AdapterRequiredConfig, query_header_context: Dict[str, Any]
59
+ ) -> None:
60
+ self.config = config
61
+ self._query_header_context = query_header_context
62
+
63
+ comment_macro = self._get_comment_macro()
64
+ self.generator: QueryStringFunc = lambda name, model: ""
65
+ # if the comment value was None or the empty string, just skip it
66
+ if comment_macro:
67
+ assert isinstance(comment_macro, str)
68
+ macro = "\n".join(
69
+ (
70
+ "{%- macro query_comment_macro(connection_name, node) -%}",
71
+ comment_macro,
72
+ "{% endmacro %}",
73
+ )
74
+ )
75
+ ctx = self._get_context()
76
+ self.generator = QueryStringGenerator(macro, ctx)
77
+ self.comment = _QueryComment(None)
78
+ self.reset()
79
+
80
+ def _get_comment_macro(self) -> Optional[str]:
81
+ return self.config.query_comment.comment
82
+
83
+ def _get_context(self) -> Dict[str, Any]:
84
+ return self._query_header_context
85
+
86
+ def add(self, sql: str) -> str:
87
+ return self.comment.add(sql)
88
+
89
+ def reset(self):
90
+ self.set("master", None)
91
+
92
+ def set(self, name: str, query_header_context: Any):
93
+ wrapped: Optional[QueryHeaderContextWrapper] = None
94
+ if query_header_context is not None:
95
+ wrapped = QueryHeaderContextWrapper(query_header_context)
96
+ comment_str = self.generator(name, wrapped)
97
+
98
+ append = False
99
+ if isinstance(self.config.query_comment, QueryComment):
100
+ append = self.config.query_comment.append
101
+ self.comment.set(comment_str, append)