|
1 | 1 | import datetime |
2 | 2 | import urllib.parse |
3 | | -from typing import Callable, Dict, Generic, List, Optional, Type, TypeVar, Any |
| 3 | +from typing import Any, Callable, Dict, Generic, List, Optional, Type, TypeVar |
| 4 | + |
4 | 5 | from databricks.sdk import common |
5 | 6 |
|
| 7 | + |
6 | 8 | def _from_dict(d: Dict[str, any], field: str, cls: Type) -> any: |
7 | 9 | if field not in d or d[field] is None: |
8 | 10 | return None |
@@ -41,36 +43,55 @@ def _repeated_enum(d: Dict[str, any], field: str, cls: Type) -> any: |
41 | 43 | res.append(val) |
42 | 44 | return res |
43 | 45 |
|
| 46 | + |
44 | 47 | def _get_duration(d: Dict[str, Any], field: str) -> Optional[common.Duration]: |
45 | 48 | if field not in d or d[field] is None: |
46 | 49 | return None |
47 | 50 | return common.Duration.parse(d[field]) |
48 | 51 |
|
| 52 | + |
49 | 53 | def _repeated_duration(d: Dict[str, Any], field: str) -> Optional[List[common.Duration]]: |
50 | 54 | if field not in d or not d[field]: |
51 | 55 | return None |
52 | 56 | return [common.Duration.parse(v) for v in d[field]] |
53 | 57 |
|
| 58 | + |
54 | 59 | def _get_timestamp(d: Dict[str, Any], field: str) -> Optional[common.Timestamp]: |
55 | 60 | if field not in d or d[field] is None: |
56 | 61 | return None |
57 | 62 | return common.Timestamp.parse(d[field]) |
58 | 63 |
|
| 64 | + |
59 | 65 | def _repeated_timestamp(d: Dict[str, Any], field: str) -> Optional[List[common.Timestamp]]: |
60 | 66 | if field not in d or not d[field]: |
61 | 67 | return None |
62 | 68 | return [common.Timestamp.parse(v) for v in d[field]] |
63 | 69 |
|
| 70 | + |
64 | 71 | def _get_value(d: Dict[str, Any], field: str) -> Optional[Any]: |
65 | 72 | if field not in d or d[field] is None: |
66 | 73 | return None |
67 | 74 | return d[field] |
68 | 75 |
|
| 76 | + |
69 | 77 | def _repeated_value(d: Dict[str, Any], field: str) -> Optional[List[Any]]: |
70 | 78 | if field not in d or not d[field]: |
71 | 79 | return None |
72 | 80 | return d[field] |
73 | 81 |
|
| 82 | + |
| 83 | +def _get_field_mask(d: Dict[str, Any], field: str) -> Optional[List[str]]: |
| 84 | + if field not in d or d[field] is None: |
| 85 | + return None |
| 86 | + return d[field].split(",") |
| 87 | + |
| 88 | + |
| 89 | +def _repeated_field_mask(d: Dict[str, Any], field: str) -> Optional[List[str]]: |
| 90 | + if field not in d or not d[field]: |
| 91 | + return None |
| 92 | + return [v.split(",") for v in d[field]] |
| 93 | + |
| 94 | + |
74 | 95 | def _escape_multi_segment_path_parameter(param: str) -> str: |
75 | 96 | return urllib.parse.quote(param) |
76 | 97 |
|
|
0 commit comments