|
1 | 1 | import datetime |
2 | 2 | import urllib.parse |
3 | | -from typing import Callable, Dict, Generic, Optional, Type, TypeVar |
4 | | - |
| 3 | +from typing import Callable, Dict, Generic, List, Optional, Type, TypeVar, Any |
| 4 | +from databricks.sdk import common |
5 | 5 |
|
6 | 6 | def _from_dict(d: Dict[str, any], field: str, cls: Type) -> any: |
7 | 7 | if field not in d or d[field] is None: |
@@ -41,6 +41,35 @@ def _repeated_enum(d: Dict[str, any], field: str, cls: Type) -> any: |
41 | 41 | res.append(val) |
42 | 42 | return res |
43 | 43 |
|
| 44 | +def _get_duration(d: Dict[str, Any], field: str) -> Optional[common.Duration]: |
| 45 | + if field not in d or d[field] is None: |
| 46 | + return None |
| 47 | + return common.Duration.parse(d[field]) |
| 48 | + |
| 49 | +def _repeated_duration(d: Dict[str, Any], field: str) -> Optional[List[common.Duration]]: |
| 50 | + if field not in d or not d[field]: |
| 51 | + return None |
| 52 | + return [common.Duration.parse(v) for v in d[field]] |
| 53 | + |
| 54 | +def _get_timestamp(d: Dict[str, Any], field: str) -> Optional[common.Timestamp]: |
| 55 | + if field not in d or d[field] is None: |
| 56 | + return None |
| 57 | + return common.Timestamp.parse(d[field]) |
| 58 | + |
| 59 | +def _repeated_timestamp(d: Dict[str, Any], field: str) -> Optional[List[common.Timestamp]]: |
| 60 | + if field not in d or not d[field]: |
| 61 | + return None |
| 62 | + return [common.Timestamp.parse(v) for v in d[field]] |
| 63 | + |
| 64 | +def _get_value(d: Dict[str, Any], field: str) -> Optional[Any]: |
| 65 | + if field not in d or d[field] is None: |
| 66 | + return None |
| 67 | + return d[field] |
| 68 | + |
| 69 | +def _repeated_value(d: Dict[str, Any], field: str) -> Optional[List[Any]]: |
| 70 | + if field not in d or not d[field]: |
| 71 | + return None |
| 72 | + return d[field] |
44 | 73 |
|
45 | 74 | def _escape_multi_segment_path_parameter(param: str) -> str: |
46 | 75 | return urllib.parse.quote(param) |
|
0 commit comments