Skip to content

Commit c94211b

Browse files
[Datalake] Removed list_paths manual paging and deserialization (#16309)
* Removed path listing manual deserialization * removed imports * removed imports * linter * lint * fixing flaky large file upload test
1 parent fa745eb commit c94211b

File tree

7 files changed

+19
-162
lines changed

7 files changed

+19
-162
lines changed

sdk/storage/azure-storage-blob/tests/test_largest_block_blob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def test_create_largest_blob_from_stream_single_upload_without_network(self, res
259259
payload_dropping_policy = PayloadDroppingPolicy()
260260
credential_policy = _format_shared_key_credential(storage_account.name, storage_account_key)
261261
self._setup(storage_account, storage_account_key, [payload_dropping_policy, credential_policy],
262-
max_single_put_size=LARGEST_SINGLE_UPLOAD_SIZE)
262+
max_single_put_size=LARGEST_SINGLE_UPLOAD_SIZE+1)
263263
blob_name = self._get_blob_reference()
264264
blob = self.bsc.get_blob_client(self.container_name, blob_name)
265265

sdk/storage/azure-storage-blob/tests/test_largest_block_blob_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ async def test_create_largest_blob_from_stream_single_upload_without_network(sel
291291
payload_dropping_policy = PayloadDroppingPolicy()
292292
credential_policy = _format_shared_key_credential(storage_account.name, storage_account_key)
293293
await self._setup(storage_account, storage_account_key, [payload_dropping_policy, credential_policy],
294-
max_single_put_size=LARGEST_SINGLE_UPLOAD_SIZE)
294+
max_single_put_size=LARGEST_SINGLE_UPLOAD_SIZE+1)
295295
blob_name = self._get_blob_reference()
296296
blob = self.bsc.get_blob_client(self.container_name, blob_name)
297297

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_deserialize.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from azure.core.pipeline.policies import ContentDecodePolicy
1313
from azure.core.exceptions import HttpResponseError, DecodeError, ResourceModifiedError, ClientAuthenticationError, \
1414
ResourceNotFoundError, ResourceExistsError
15-
from ._models import FileProperties, DirectoryProperties, LeaseProperties
15+
from ._models import FileProperties, DirectoryProperties, LeaseProperties, PathProperties
1616
from ._shared.models import StorageErrorCode
1717

1818
if TYPE_CHECKING:
@@ -44,6 +44,10 @@ def deserialize_file_properties(response, obj, headers):
4444
return file_properties
4545

4646

47+
def deserialize_path_properties(path_list):
48+
return [PathProperties._from_generated(path) for path in path_list] # pylint: disable=protected-access
49+
50+
4751
def from_blob_properties(blob_properties):
4852
file_props = FileProperties()
4953
file_props.name = blob_properties.name

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
import functools
6+
from typing import Optional
77

88
try:
99
from urllib.parse import urlparse, quote
@@ -18,11 +18,11 @@
1818
from ._shared.base_client import TransportWrapper, StorageAccountHostsMixin, parse_query, parse_connection_str
1919
from ._serialize import convert_dfs_url_to_blob_url
2020
from ._models import LocationMode, FileSystemProperties, PublicAccess
21-
from ._list_paths_helper import PathPropertiesPaged
2221
from ._data_lake_file_client import DataLakeFileClient
2322
from ._data_lake_directory_client import DataLakeDirectoryClient
2423
from ._data_lake_lease import DataLakeLeaseClient
2524
from ._generated import AzureDataLakeStorageRESTAPI
25+
from ._deserialize import deserialize_path_properties
2626

2727

2828
class FileSystemClient(StorageAccountHostsMixin):
@@ -463,14 +463,13 @@ def get_paths(self, path=None, # type: Optional[str]
463463
:caption: List the paths in the file system.
464464
"""
465465
timeout = kwargs.pop('timeout', None)
466-
command = functools.partial(
467-
self._client.file_system.list_paths,
466+
return self._client.file_system.list_paths(
467+
recursive=recursive,
468+
max_results=max_results,
468469
path=path,
469470
timeout=timeout,
471+
cls=deserialize_path_properties,
470472
**kwargs)
471-
return ItemPaged(
472-
command, recursive, path=path, max_results=max_results,
473-
page_iterator_class=PathPropertiesPaged, **kwargs)
474473

475474
def create_directory(self, directory, # type: Union[DirectoryProperties, str]
476475
metadata=None, # type: Optional[Dict[str, str]]

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_list_paths_helper.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# --------------------------------------------------------------------------
77
# pylint: disable=invalid-overridden-method
88

9-
import functools
109
from typing import ( # pylint: disable=unused-import
1110
Union, Optional, Any, Dict, TYPE_CHECKING
1211
)
@@ -21,8 +20,8 @@
2120

2221
from ._data_lake_file_client_async import DataLakeFileClient
2322
from ._data_lake_directory_client_async import DataLakeDirectoryClient
24-
from ._models import PathPropertiesPaged
2523
from ._data_lake_lease_async import DataLakeLeaseClient
24+
from .._deserialize import deserialize_path_properties
2625
from .._file_system_client import FileSystemClient as FileSystemClientBase
2726
from .._generated.aio import AzureDataLakeStorageRESTAPI
2827
from .._shared.base_client_async import AsyncTransportWrapper, AsyncStorageAccountHostsMixin
@@ -385,7 +384,7 @@ def get_paths(self, path=None, # type: Optional[str]
385384
recursive=True, # type: Optional[bool]
386385
max_results=None, # type: Optional[int]
387386
**kwargs):
388-
# type: (...) -> ItemPaged[PathProperties]
387+
# type: (...) -> AsyncItemPaged[PathProperties]
389388
"""Returns a generator to list the paths(could be files or directories) under the specified file system.
390389
The generator will lazily follow the continuation tokens returned by
391390
the service.
@@ -421,14 +420,13 @@ def get_paths(self, path=None, # type: Optional[str]
421420
:caption: List the blobs in the file system.
422421
"""
423422
timeout = kwargs.pop('timeout', None)
424-
command = functools.partial(
425-
self._client.file_system.list_paths,
423+
return self._client.file_system.list_paths(
424+
recursive=recursive,
425+
max_results=max_results,
426426
path=path,
427427
timeout=timeout,
428+
cls=deserialize_path_properties,
428429
**kwargs)
429-
return AsyncItemPaged(
430-
command, recursive, path=path, max_results=max_results,
431-
page_iterator_class=PathPropertiesPaged, **kwargs)
432430

433431
@distributed_trace_async
434432
async def create_directory(self, directory, # type: Union[DirectoryProperties, str]

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_models.py

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@
55
# --------------------------------------------------------------------------
66
# pylint: disable=too-few-public-methods, too-many-instance-attributes
77
# pylint: disable=super-init-not-called, too-many-lines
8-
from azure.core.async_paging import AsyncPageIterator
9-
from azure.core.exceptions import HttpResponseError
108
from azure.storage.blob.aio._models import ContainerPropertiesPaged
11-
12-
from .._deserialize import process_storage_error
13-
from .._generated.models import Path
14-
from .._models import PathProperties
15-
169
from .._models import FileSystemProperties
1710

1811

@@ -46,68 +39,3 @@ def __init__(self, *args, **kwargs):
4639
@staticmethod
4740
def _build_item(item):
4841
return FileSystemProperties._from_generated(item) # pylint: disable=protected-access
49-
50-
51-
class PathPropertiesPaged(AsyncPageIterator):
52-
"""An Iterable of Path properties.
53-
54-
:ivar str path: Filters the results to return only paths under the specified path.
55-
:ivar int results_per_page: The maximum number of results retrieved per API call.
56-
:ivar str continuation_token: The continuation token to retrieve the next page of results.
57-
:ivar list(~azure.storage.filedatalake.PathProperties) current_page: The current page of listed results.
58-
59-
:param callable command: Function to retrieve the next page of items.
60-
:param str path: Filters the results to return only paths under the specified path.
61-
:param int max_results: The maximum number of psths to retrieve per
62-
call.
63-
:param str continuation_token: An opaque continuation token.
64-
"""
65-
66-
def __init__(
67-
self, command,
68-
recursive,
69-
path=None,
70-
max_results=None,
71-
continuation_token=None,
72-
upn=None):
73-
super(PathPropertiesPaged, self).__init__(
74-
get_next=self._get_next_cb,
75-
extract_data=self._extract_data_cb,
76-
continuation_token=continuation_token or ""
77-
)
78-
self._command = command
79-
self.recursive = recursive
80-
self.results_per_page = max_results
81-
self.path = path
82-
self.upn = upn
83-
self.current_page = None
84-
self.path_list = None
85-
86-
async def _get_next_cb(self, continuation_token):
87-
try:
88-
return self._command(
89-
self.recursive,
90-
continuation=continuation_token or None,
91-
path=self.path,
92-
max_results=self.results_per_page,
93-
upn=self.upn)
94-
except HttpResponseError as error:
95-
process_storage_error(error)
96-
97-
async def _extract_data_cb(self, get_next_return):
98-
path_list = []
99-
async for path in get_next_return:
100-
path_list.append(path)
101-
self.path_list = path_list
102-
self.current_page = [self._build_item(item) for item in self.path_list]
103-
104-
return None, self.current_page
105-
106-
@staticmethod
107-
def _build_item(item):
108-
if isinstance(item, PathProperties):
109-
return item
110-
if isinstance(item, Path):
111-
path = PathProperties._from_generated(item) # pylint: disable=protected-access
112-
return path
113-
return item

0 commit comments

Comments
 (0)