Skip to content

Commit 483a732

Browse files
copy from universe
1 parent cb773f1 commit 483a732

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

databricks/sdk/__init__.py

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

databricks/sdk/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pathlib
77
import sys
88
import urllib.parse
9-
from typing import Dict, Iterable, List, Optional
9+
from typing import Dict, Iterable, Optional, List
1010

1111
import requests
1212

@@ -110,7 +110,7 @@ class Config:
110110

111111
disable_async_token_refresh: bool = ConfigAttribute(env="DATABRICKS_DISABLE_ASYNC_TOKEN_REFRESH")
112112

113-
enable_experimental_files_api_client: bool = ConfigAttribute(env="DATABRICKS_ENABLE_EXPERIMENTAL_FILES_API_CLIENT")
113+
disable_experimental_files_api_client: bool = ConfigAttribute(env="DATABRICKS_DISABLE_EXPERIMENTAL_FILES_API_CLIENT")
114114

115115
files_ext_client_download_streaming_chunk_size: int = 2 * 1024 * 1024 # 2 MiB
116116

databricks/sdk/mixins/files.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,9 @@ def download(
796796
797797
:returns: :class:`DownloadResponse`
798798
"""
799+
if self._config.disable_experimental_files_api_client:
800+
_LOG.info("Disable experimental files API client, will use the original download method.")
801+
return super().download(file_path)
799802

800803
initial_response: DownloadResponse = self._open_download_stream(
801804
file_path=file_path, start_byte_offset=0, if_unmodified_since_timestamp=None
@@ -829,6 +832,11 @@ def download_to(
829832
830833
:returns: :class:`DownloadFileResult`
831834
"""
835+
if self._config.disable_experimental_files_api_client:
836+
raise NotImplementedError(
837+
"Experimental files API features are disabled, download_to is not supported. Please use download instead."
838+
)
839+
832840
# The existence of the target file is checked before starting the download. This is a best-effort check
833841
# to avoid overwriting an existing file. However, there is nothing preventing a file from being created
834842
# at the destination path after this check and before the file is written, and no way to prevent other
@@ -1086,6 +1094,11 @@ def upload(
10861094
:returns: :class:`UploadStreamResult`
10871095
"""
10881096

1097+
if self._config.disable_experimental_files_api_client:
1098+
_LOG.info("Disable experimental files API client, will use the original upload method.")
1099+
super().upload(file_path=file_path, contents=content, overwrite=overwrite)
1100+
return UploadStreamResult()
1101+
10891102
_LOG.debug(f"Uploading file from BinaryIO stream")
10901103
if parallelism is not None and not use_parallel:
10911104
raise ValueError("parallelism can only be set if use_parallel is True")
@@ -1163,6 +1176,10 @@ def upload_from(
11631176
11641177
:returns: :class:`UploadFileResult`
11651178
"""
1179+
if self._config.disable_experimental_files_api_client:
1180+
raise NotImplementedError(
1181+
"Experimental files API features are disabled, upload_from is not supported. Please use upload instead."
1182+
)
11661183

11671184
_LOG.debug(f"Uploading file from local path: {source_path}")
11681185

tests/test_files.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from enum import Enum
1414
from tempfile import NamedTemporaryFile
1515
from threading import Lock
16-
from typing import Any, Callable, Dict, List, Optional, Type, Union
16+
from typing import Any, Callable, List, Optional, Type, Union, Dict
1717
from urllib.parse import parse_qs, urlparse
1818

1919
import pytest
@@ -203,7 +203,7 @@ def run(self, config: Config, monkeypatch) -> None:
203203
if self.use_parallel and platform.system() == "Windows":
204204
pytest.skip("Skipping parallel download tests on Windows")
205205
config = config.copy()
206-
config.enable_experimental_files_api_client = self.enable_new_client
206+
config.disable_experimental_files_api_client = not self.enable_new_client
207207
config.files_ext_client_download_max_total_recovers = self.max_recovers_total
208208
config.files_ext_client_download_max_total_recovers_without_progressing = self.max_recovers_without_progressing
209209
config.enable_presigned_download_api = False
@@ -950,7 +950,6 @@ def run_one_case(self, config: Config, monkeypatch, download_mode: DownloadMode,
950950
logger.debug("Parallel download is not supported on Windows. Falling back to sequential download.")
951951
return
952952
config = config.copy()
953-
config.enable_experimental_files_api_client = True
954953
config.enable_presigned_download_api = True
955954
config._clock = FakeClock()
956955
if self.parallel_download_min_file_size is not None:
@@ -1323,7 +1322,6 @@ def run_one_case(self, config: Config, use_parallel: bool, source_type: "UploadS
13231322
logger.debug(f"Running test case: {self.name}, source_type={source_type}, use_parallel={use_parallel}")
13241323
config = config.copy()
13251324
config._clock = FakeClock()
1326-
config.enable_experimental_files_api_client = True
13271325

13281326
if self.cloud:
13291327
config.databricks_environment = DatabricksEnvironment(self.cloud, "")

tests/test_files_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
from abc import ABC, abstractmethod
44
from io import BytesIO, RawIOBase, UnsupportedOperation
5-
from typing import BinaryIO, Callable, List, Optional, Tuple
5+
from typing import BinaryIO, Callable, Optional, Tuple, List
66

77
import pytest
88

0 commit comments

Comments
 (0)