Skip to content

Commit d2d91b4

Browse files
committed
Add helpers
1 parent 5d4c93f commit d2d91b4

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

databricks/sdk/service/_internal.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22
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
55

66
def _from_dict(d: Dict[str, any], field: str, cls: Type) -> any:
77
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:
4141
res.append(val)
4242
return res
4343

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]
4473

4574
def _escape_multi_segment_path_parameter(param: str) -> str:
4675
return urllib.parse.quote(param)

0 commit comments

Comments
 (0)