Create the namespace. BigLake doesn't auto-create on first commit. With ``exist_ok`` (the default), a 409 from a namespace that already exists is treated as success, so this is safe to call repeatedly against a fixed long-lived namespace.
(
token: str, project: str, prefix: str, namespace: str, *, exist_ok: bool = True
)
| 167 | |
| 168 | |
| 169 | def create_namespace( |
| 170 | token: str, project: str, prefix: str, namespace: str, *, exist_ok: bool = True |
| 171 | ) -> None: |
| 172 | """Create the namespace. BigLake doesn't auto-create on first commit. |
| 173 | |
| 174 | With ``exist_ok`` (the default), a 409 from a namespace that already exists |
| 175 | is treated as success, so this is safe to call repeatedly against a fixed |
| 176 | long-lived namespace. |
| 177 | """ |
| 178 | req = biglake_request("POST", catalog_url(prefix, "namespaces"), token, project) |
| 179 | req.add_header("Content-Type", "application/json") |
| 180 | req.data = json.dumps({"namespace": [namespace]}).encode() |
| 181 | try: |
| 182 | urllib.request.urlopen(req) |
| 183 | except urllib.error.HTTPError as e: |
| 184 | if exist_ok and e.code == 409: |
| 185 | return |
| 186 | raise |
| 187 | |
| 188 | |
| 189 | def bootstrap_namespace(service_account: dict, bucket: str, namespace: str) -> str: |
no test coverage detected