Skip to content

Commit

Permalink
feat(client): desigin the move and copy operation of data and segment
Browse files Browse the repository at this point in the history
PR Closed: #748
  • Loading branch information
linjiX committed Jun 23, 2021
1 parent 6c7fd33 commit 88a42cf
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 0 deletions.
106 changes: 106 additions & 0 deletions tensorbay/client/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,59 @@ def create_segment(self, name: str = "default") -> SegmentClient:
raise NameConflictError(resource="segment", identification=name)
return SegmentClient(name, self)

def copy_segment(
self,
source_name: str,
target_name: Optional[str] = None,
*,
source_client: Optional["DatasetClient"] = None,
strategy: str = "abort",
) -> SegmentClient:
"""Copy segment to this dataset.
Arguments:
source_name: The source name of the copied segment.
target_name: The target name of the copied segment.
This argument is used to specify a new name of the copied segment.
If None, the name of the copied segment will not be changed after copy.
source_client: The source dataset client of the copied segment.
This argument is used to specify where the copied segment comes from when the
copied segment is from another commit, draft or even another dataset.
If None, the copied segment comes from this dataset.
strategy: The strategy of handling the name conflict. There are three options:
1. "abort": stop copying and raise exception;
2. "override": the source segment will override the origin segment;
3. "skip": keep the origin segment.
Returns: #noqa: DAR202
The client of the copied target segment.
"""

def move_segment(
self,
source_name: str,
target_name: str,
*,
strategy: str = "abort",
) -> SegmentClient:
"""Move/Rename segment in this dataset.
Arguments:
source_name: The source name of the moved segment.
target_name: The target name of the moved segment.
strategy: The strategy of handling the name conflict. There are three options:
1. "abort": stop moving and raise exception;
2. "override": the source segment will override the origin segment;
3. "skip": keep the origin segment.
Returns: #noqa: DAR202
The client of the moved target segment.
"""

def get_segment(self, name: str = "default") -> SegmentClient:
"""Get a segment in a certain commit according to given name.
Expand Down Expand Up @@ -483,6 +536,59 @@ def create_segment(self, name: str = "default") -> FusionSegmentClient:
raise NameConflictError(resource="segment", identification=name)
return FusionSegmentClient(name, self)

def copy_segment(
self,
source_name: str,
target_name: Optional[str] = None,
*,
source_client: Optional["FusionDatasetClient"] = None,
strategy: str = "abort",
) -> FusionSegmentClient:
"""Copy segment to this dataset.
Arguments:
source_name: The source name of the copied segment.
target_name: The target name of the copied segment.
This argument is used to specify a new name of the copied segment.
If None, the name of the copied segment will not be changed after copy.
source_client: The source dataset client of the copied segment.
This argument is used to specify where the copied segment comes from when the
copied segment is from another commit, draft or even another dataset.
If None, the copied segment comes from this dataset.
strategy: The strategy of handling the name conflict. There are three options:
1. "abort": stop copying and raise exception;
2. "override": the source segment will override the origin segment;
3. "skip": keep the origin segment.
Returns: #noqa: DAR202
The client of the copied target segment.
"""

def move_segment(
self,
source_name: str,
target_name: str,
*,
strategy: str = "abort",
) -> FusionSegmentClient:
"""Move/Rename segment in this dataset.
Arguments:
source_name: The source name of the moved segment.
target_name: The target name of the moved segment.
strategy: The strategy of handling the name conflict. There are three options:
1. "abort": stop moving and raise exception;
2. "override": the source segment will override the origin segment;
3. "skip": keep the origin segment.
Returns: #noqa: DAR202
The client of the moved target segment.
"""

def get_segment(self, name: str = "default") -> FusionSegmentClient:
"""Get a fusion segment in a certain commit according to given name.
Expand Down
54 changes: 54 additions & 0 deletions tensorbay/client/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,60 @@ def upload_data(self, data: Data) -> None:
self.upload_file(data.path, data.target_remote_path)
self._upload_label(data)

def copy_data(
self,
source_remote_paths: Union[str, Iterable[str]],
target_remote_paths: Union[None, str, Iterable[str]] = None,
*,
source_client: Optional["SegmentClient"] = None,
strategy: str = "abort",
) -> None:
"""Copy data to this segment.
Arguments:
source_remote_paths: The source remote paths of the copied data.
target_remote_paths: The target remote paths of the copied data.
This argument is used to specify new remote paths of the copied data.
If None, the remote path of the copied data will not be changed after copy.
source_client: The source segment client of the copied data.
This argument is used to specifies where the copied data comes from when the copied
data is from another commit, draft, segment or even another dataset.
If None, the copied data comes from this segment.
strategy: The strategy of handling the name conflict. There are three options:
1. "abort": stop copying and raise exception;
2. "override": the source data will override the origin data;
3. "skip": keep the origin data.
"""

def move_data(
self,
source_remote_paths: Union[str, Iterable[str]],
target_remote_paths: Union[None, str, Iterable[str]] = None,
*,
source_client: Optional["SegmentClient"] = None,
strategy: str = "abort",
) -> None:
"""Move data to this segment, also used to rename data.
Arguments:
source_remote_paths: The source remote paths of the moved data.
target_remote_paths: The target remote paths of the moved data.
This argument is used to specify new remote paths of the moved data.
If None, the remote path of the moved data will not be changed after copy.
source_client: The source segment client of the moved data.
This argument is used to specifies where the moved data comes from when the moved
data is from another segment.
If None, the moved data comes from this segment.
strategy: The strategy of handling the name conflict. There are three options:
1. "abort": stop moving and raise exception;
2. "override": the source data will override the origin data;
3. "skip": keep the origin data.
"""

def list_data_paths(self) -> PagingList[str]:
"""List required data path in a segment in a certain commit.
Expand Down

0 comments on commit 88a42cf

Please sign in to comment.