|
1 | 1 | from contextlib import contextmanager
|
2 | 2 | from dataclasses import dataclass
|
| 3 | +import itertools |
3 | 4 | import re
|
4 | 5 | import time
|
5 |
| -from typing import Any, Callable, ClassVar, Dict, Iterator, List, Optional, Sequence, Tuple |
| 6 | +from typing import ( |
| 7 | + Any, |
| 8 | + Callable, |
| 9 | + ClassVar, |
| 10 | + Dict, |
| 11 | + Iterable, |
| 12 | + Iterator, |
| 13 | + List, |
| 14 | + Optional, |
| 15 | + Sequence, |
| 16 | + Tuple, |
| 17 | +) |
6 | 18 |
|
7 | 19 | from agate import Table
|
8 | 20 |
|
@@ -97,8 +109,30 @@ def type(self) -> str:
|
97 | 109 | def unique_field(self) -> str:
|
98 | 110 | return self.host
|
99 | 111 |
|
100 |
| - def _connection_keys(self) -> Tuple[str, ...]: |
101 |
| - connection_keys = ["host", "http_path", "database", "schema"] |
| 112 | + def connection_info(self, *, with_aliases: bool = False) -> Iterable[Tuple[str, Any]]: |
| 113 | + as_dict = self.to_dict(omit_none=False) |
| 114 | + connection_keys = set(self._connection_keys(with_aliases=with_aliases)) |
| 115 | + aliases: List[str] = [] |
| 116 | + if with_aliases: |
| 117 | + aliases = [k for k, v in self._ALIASES.items() if v in connection_keys] |
| 118 | + for key in itertools.chain(self._connection_keys(with_aliases=with_aliases), aliases): |
| 119 | + if key in as_dict: |
| 120 | + yield key, as_dict[key] |
| 121 | + |
| 122 | + def _connection_keys(self, *, with_aliases: bool = False) -> Tuple[str, ...]: |
| 123 | + # Assuming `DatabricksCredentials.connection_info(self, *, with_aliases: bool = False)` |
| 124 | + # is called from only: |
| 125 | + # |
| 126 | + # - `Profile` with `with_aliases=True` |
| 127 | + # - `DebugTask` without `with_aliases` (`False` by default) |
| 128 | + # |
| 129 | + # Thus, if `with_aliases` is `True`, `DatabricksCredentials._connection_keys` should return |
| 130 | + # the internal key names; otherwise it can use aliases to show in `dbt debug`. |
| 131 | + connection_keys = ["host", "http_path", "schema"] |
| 132 | + if with_aliases: |
| 133 | + connection_keys.insert(2, "database") |
| 134 | + elif self.database: |
| 135 | + connection_keys.insert(2, "catalog") |
102 | 136 | if self.session_properties:
|
103 | 137 | connection_keys.append("session_properties")
|
104 | 138 | return tuple(connection_keys)
|
|
0 commit comments