-
Notifications
You must be signed in to change notification settings - Fork 8
python(feat): add data import api to sift_client #515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
11838ae
python(feat): add data import api
wei-qlu 7224b79
add detect config data types
wei-qlu d27b070
added relative time validation, refactored the import process
wei-qlu 77dbf86
added progress spinner for polling
wei-qlu bd5e9f8
missing run defaults to filename
wei-qlu 41f9c08
added relative time format validation in the model
wei-qlu e76d2d2
updated post request to include file name for downstream file attachment
wei-qlu 4cb5ebd
added parquet data type, refactor to use util
wei-qlu 01f5831
remove upload_from_url
wei-qlu 269a8b5
converted imports to using jobs
wei-qlu 54014ea
fix sync/async behavior when polling directly
wei-qlu fe50604
add parquet import support
wei-qlu f0c186b
unfrozen config model refactor
wei-qlu 593f3dc
mypy fix
wei-qlu 8725f59
small refactor moving configs to sift_types
wei-qlu fd925eb
add a helper function to get a specific data_column
wei-qlu 85e87be
add unit tests
wei-qlu d669cf2
added client side validation for detect_config
wei-qlu bac1b52
add validation tests
wei-qlu 09f48e9
update asset_name handlign
wei-qlu 3b1e28f
update sync stubs
wei-qlu 1ae1e95
add ch10, hdf5, and tdms configs
wei-qlu 3ee74a4
mypy fix
wei-qlu ffdb06f
additional file format tests
wei-qlu b0559b0
added documentation for csv json metadata
wei-qlu d66d8e0
updated docs and split import and polling
wei-qlu e4ae07d
add upload_file polling and refactor global show_progress to a util
wei-qlu 107eaa2
error handling from missing job_id from upload
wei-qlu 9fe594c
refactor to use run/asset objects
wei-qlu d3377d1
refactor file format configs into private helpers, updated error message
wei-qlu 07007f9
refactored to apply inheritance on time and config classes
wei-qlu fca8331
updated documentation around detect_config
wei-qlu deb3590
updated unit tests
wei-qlu 7aa2da4
updated documentation regarding json metadata
wei-qlu f59336d
updated get_column to getitem
wei-qlu 0328d27
updated detect_config error messages
wei-qlu 930c556
move data column validation from detect_config to _to_proto
wei-qlu c610c88
updated error types to be more accurate
wei-qlu 66d567f
add import_data method to Run for importing files into existing runs
wei-qlu 462a36d
add get_run to data import API and get_import_run to Job for resolvin…
wei-qlu f049daa
add model validation for parquet single/multi channel
wei-qlu 8ff5fde
refactor parquet timecolumn detection
wei-qlu 6771278
mypy fix
wei-qlu 261e091
simplify _resolve_data_type_key logic
wei-qlu 59af2a8
autofill the run's asset during import
wei-qlu f999e97
updated docstrings and fixed run import to infer asset object
wei-qlu e074a4c
refactor show_progress helper to the base class
wei-qlu 78703e5
add client binding test for data imports
wei-qlu d736d1e
add a base class for data columns shared by csv, parquet, and hdf5
wei-qlu 3cc3607
update the upload_file progress bar to be more detailed
wei-qlu 8b65390
removed ch10 references, no more support
wei-qlu 542b5fa
sync stubs update
wei-qlu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
python/lib/sift_client/_internal/low_level_wrappers/data_imports.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING, cast | ||
|
|
||
| from sift.data_imports.v2.data_imports_pb2 import ( | ||
| CreateDataImportFromUploadRequest, | ||
| CreateDataImportFromUploadResponse, | ||
| DetectConfigRequest, | ||
| DetectConfigResponse, | ||
| GetDataImportRequest, | ||
| GetDataImportResponse, | ||
| ) | ||
| from sift.data_imports.v2.data_imports_pb2_grpc import DataImportServiceStub | ||
|
|
||
| from sift_client._internal.low_level_wrappers.base import LowLevelClientBase | ||
| from sift_client.sift_types.data_import import ( | ||
| CsvImportConfig, | ||
| Hdf5ImportConfig, | ||
| ImportConfig, | ||
| ParquetFlatDatasetImportConfig, | ||
| ParquetSingleChannelPerRowImportConfig, | ||
| TdmsImportConfig, | ||
| ) | ||
| from sift_client.transport import WithGrpcClient | ||
|
|
||
| if TYPE_CHECKING: | ||
| from sift.data_imports.v2.data_imports_pb2 import DataTypeKey | ||
|
|
||
| from sift_client.transport.grpc_transport import GrpcClient | ||
|
|
||
|
|
||
| def _set_config_on_request( | ||
| request: CreateDataImportFromUploadRequest, | ||
| config: ImportConfig, | ||
| ) -> None: | ||
| """Set the appropriate config field on a proto request based on the config type.""" | ||
| if isinstance(config, CsvImportConfig): | ||
| request.csv_config.CopyFrom(config._to_proto()) | ||
| elif isinstance( | ||
| config, (ParquetFlatDatasetImportConfig, ParquetSingleChannelPerRowImportConfig) | ||
| ): | ||
| request.parquet_config.CopyFrom(config._to_proto()) | ||
| elif isinstance(config, TdmsImportConfig): | ||
| request.tdms_config.CopyFrom(config._to_proto()) | ||
| elif isinstance(config, Hdf5ImportConfig): | ||
| request.hdf5_config.CopyFrom(config._to_proto()) | ||
| else: | ||
| raise TypeError(f"Unsupported import config type: {type(config).__name__}") | ||
|
|
||
|
|
||
| class DataImportsLowLevelClient(LowLevelClientBase, WithGrpcClient): | ||
| """Low-level client for the DataImportService. | ||
|
|
||
| This class provides a thin wrapper around the autogenerated bindings for the DataImportsAPI. | ||
| """ | ||
|
|
||
| def __init__(self, grpc_client: GrpcClient): | ||
| WithGrpcClient.__init__(self, grpc_client=grpc_client) | ||
|
|
||
| async def create_from_upload(self, config: ImportConfig) -> tuple[str, str]: | ||
| """Create a data import and get back a presigned upload URL. | ||
|
|
||
| Args: | ||
| config: The import configuration. | ||
|
|
||
| Returns: | ||
| A tuple of (data_import_id, upload_url). | ||
| """ | ||
| request = CreateDataImportFromUploadRequest() | ||
| _set_config_on_request(request, config) | ||
| response = await self._grpc_client.get_stub( | ||
| DataImportServiceStub | ||
| ).CreateDataImportFromUpload(request) | ||
| response = cast("CreateDataImportFromUploadResponse", response) | ||
| return response.data_import_id, response.upload_url | ||
|
|
||
| async def get(self, data_import_id: str) -> GetDataImportResponse: | ||
| """Get a data import by ID. | ||
|
|
||
| Args: | ||
| data_import_id: The ID of the data import. | ||
|
|
||
| Returns: | ||
| The GetDataImportResponse proto. | ||
| """ | ||
| request = GetDataImportRequest(data_import_id=data_import_id) | ||
| response = await self._grpc_client.get_stub(DataImportServiceStub).GetDataImport(request) | ||
| return cast("GetDataImportResponse", response) | ||
|
|
||
| async def detect_config( | ||
| self, data: bytes, data_type_key: DataTypeKey.ValueType | ||
| ) -> DetectConfigResponse: | ||
| """Call the DetectConfig RPC to auto-detect import configuration. | ||
|
|
||
| Args: | ||
| data: A sample of the file content (e.g. the first 64 KiB). | ||
| data_type_key: The file type hint. | ||
|
|
||
| Returns: | ||
| The raw DetectConfigResponse proto. | ||
| """ | ||
| request = DetectConfigRequest(data=data, type=data_type_key) | ||
| response = await self._grpc_client.get_stub(DataImportServiceStub).DetectConfig(request) | ||
| return cast("DetectConfigResponse", response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.