-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Add ADLSCreateObjectOperator
#37821
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
Add ADLSCreateObjectOperator
#37821
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
c89fbfb
feat: Pass proxies config when using ClientSecretCredential in AzureD…
754a5f1
refactor: Try fixing typing issues
davidblain-infrabel 0469dd9
docs: Updated provider docs
davidblain-infrabel 78e7fa2
refactor: Reformatted files
davidblain-infrabel e6f142c
refactor: Make sure upload_data method is verified and asserted
davidblain-infrabel f50dfd1
refactor: Reformatted some files
davidblain-infrabel 62753a4
refactor: Try fixing mypy issues
davidblain-infrabel 55f3ba3
refactor: Fixed additional static checks
davidblain-infrabel 9127631
refactor: Fixed length parameter type definition in operator
davidblain-infrabel 7374c47
refactor: Removed unused import
davidblain-infrabel 51b319d
docs: Updated docstring for DataToADLSOperator
davidblain-infrabel e8c0638
Merge branch 'main' into fix/azure-data-lake-proxies
dabla 8124a9d
Merge branch 'main' into fix/azure-data-lake-proxies
dabla be95816
Merge branch 'main' into feature/data-to-adls-operator
dabla 5f520ab
Merge branch 'main' into feature/data-to-adls-operator
dabla 7517de9
refactor: Renamed DataToADLSOperator to ADLSCreateObjectOperator and …
davidblain-infrabel 90d5dd7
fix: Re-added wrongly removed unit test
davidblain-infrabel 490ef76
refactor: Re-ordered typing imports in adls module
davidblain-infrabel affca82
Merge branch 'main' into feature/data-to-adls-operator
dabla 6dca248
docs: Replaced tiles with dashes
davidblain-infrabel c983f8a
docs: Fixed class reference to ADLSDeleteOperator
davidblain-infrabel 7a0003e
docs: Updated comment near class reference for ADLSCreateObjectOperator
davidblain-infrabel 3eaeb6e
docs: Added example of ADLSListOperator
davidblain-infrabel 67149ad
Merge branch 'main' into feature/data-to-adls-operator
dabla 4be01cf
Merge branch 'main' into feature/data-to-adls-operator
dabla ec4c84e
Merge branch 'main' into feature/data-to-adls-operator
dabla 65b2f74
fix: Reverted wrong rename of replace to overwrite due to refactoring…
31c494b
refactor: Reformatted import of LocalFilesystemToADLSOperator as in m…
davidblain-infrabel ccd1f20
Merge branch 'main' into feature/data-to-adls-operator
dabla de9d654
fix: Fixed patch of AzureDataLakeStorageV2Hook in TestADLSUploadOperator
davidblain-infrabel edf14c0
Merge branch 'main' into feature/data-to-adls-operator
dabla 309eadc
Merge branch 'main' into feature/data-to-adls-operator
dabla 1c45e9c
Update tests/system/providers/microsoft/azure/example_adls_list.py
dabla 36108b5
Merge branch 'main' into feature/data-to-adls-operator
dabla d3e5729
Merge branch 'main' into feature/data-to-adls-operator
dabla 8e8858f
Merge branch 'main' into feature/data-to-adls-operator
dabla 8f08da0
Merge branch 'main' into feature/data-to-adls-operator
dabla a3753e9
docs: Temporary removed docs for ADLSListOperator
davidblain-infrabel a4fda00
Merge branch 'main' into feature/data-to-adls-operator
dabla a3de8fb
Revert "docs: Temporary removed docs for ADLSListOperator"
davidblain-infrabel 77f6cae
fix: Fixed unit tests for TestADLSUploadOperator
davidblain-infrabel 7bcb075
Merge branch 'main' into feature/data-to-adls-operator
dabla 346112c
Merge branch 'main' into feature/data-to-adls-operator
dabla 66f1ed5
Merge branch 'main' into feature/data-to-adls-operator
dabla ec32733
Merge branch 'main' into feature/data-to-adls-operator
dabla 49b50cf
Merge branch 'main' into feature/data-to-adls-operator
dabla 1545c84
Merge branch 'main' into feature/data-to-adls-operator
dabla 8051b3d
Merge branch 'main' into feature/data-to-adls-operator
dabla 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
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
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
47 changes: 47 additions & 0 deletions
47
tests/providers/microsoft/azure/operators/test_adls_create.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,47 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from unittest import mock | ||
|
|
||
| from airflow.providers.microsoft.azure.operators.adls import ADLSCreateObjectOperator | ||
|
|
||
| TASK_ID = "test-adls-upload-operator" | ||
| FILE_SYSTEM_NAME = "Fabric" | ||
| REMOTE_PATH = "TEST-DIR" | ||
| DATA = json.dumps({"name": "David", "surname": "Blain", "gender": "M"}).encode("utf-8") | ||
|
|
||
|
|
||
| class TestADLSUploadOperator: | ||
| @mock.patch("airflow.providers.microsoft.azure.operators.adls.AzureDataLakeStorageV2Hook") | ||
| def test_execute_success_when_local_data(self, mock_hook): | ||
| operator = ADLSCreateObjectOperator( | ||
| task_id=TASK_ID, | ||
| file_system_name=FILE_SYSTEM_NAME, | ||
| file_name=REMOTE_PATH, | ||
| data=DATA, | ||
| replace=True, | ||
| ) | ||
| operator.execute(None) | ||
| data_lake_file_client_mock = mock_hook.return_value.create_file | ||
| data_lake_file_client_mock.assert_called_once_with( | ||
| file_system_name=FILE_SYSTEM_NAME, file_name=REMOTE_PATH | ||
| ) | ||
| upload_data_mock = data_lake_file_client_mock.return_value.upload_data | ||
| upload_data_mock.assert_called_once_with(data=DATA, length=None, overwrite=True) |
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
58 changes: 58 additions & 0 deletions
58
tests/system/providers/microsoft/azure/example_adls_create.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,58 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from datetime import datetime | ||
|
|
||
| from airflow import models | ||
| from airflow.providers.microsoft.azure.operators.adls import ADLSCreateObjectOperator, ADLSDeleteOperator | ||
|
|
||
| REMOTE_FILE_PATH = os.environ.get("REMOTE_LOCAL_PATH", "remote.txt") | ||
| DAG_ID = "example_adls_create" | ||
|
|
||
| with models.DAG( | ||
| DAG_ID, | ||
| start_date=datetime(2021, 1, 1), | ||
| catchup=False, | ||
| schedule=None, | ||
| tags=["example"], | ||
| ) as dag: | ||
| # [START howto_operator_adls_create] | ||
| upload_data = ADLSCreateObjectOperator( | ||
| task_id="upload_data", | ||
| file_system_name="Fabric", | ||
| file_name=REMOTE_FILE_PATH, | ||
| data="Hello world", | ||
| replace=True, | ||
| ) | ||
| # [END howto_operator_adls_create] | ||
|
|
||
| delete_file = ADLSDeleteOperator(task_id="remove_task", path=REMOTE_FILE_PATH, recursive=True) | ||
|
|
||
| upload_data >> delete_file | ||
|
|
||
| from tests.system.utils.watcher import watcher | ||
|
|
||
| # This test needs watcher in order to properly mark success/failure | ||
| # when "tearDown" task with trigger rule is part of the DAG | ||
| list(dag.tasks) >> watcher() | ||
|
|
||
| from tests.system.utils import get_test_run # noqa: E402 | ||
|
|
||
| # Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest) | ||
| test_run = get_test_run(dag) |
54 changes: 54 additions & 0 deletions
54
tests/system/providers/microsoft/azure/example_adls_list.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,54 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from datetime import datetime | ||
|
|
||
| from airflow import models | ||
| from airflow.providers.microsoft.azure.operators.adls import ADLSListOperator | ||
|
|
||
| LOCAL_FILE_PATH = os.environ.get("LOCAL_FILE_PATH", "localfile.txt") | ||
| REMOTE_FILE_PATH = os.environ.get("REMOTE_LOCAL_PATH", "remote.txt") | ||
|
|
||
| ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID") | ||
| DAG_ID = "example_adls_list" | ||
|
|
||
| with models.DAG( | ||
| DAG_ID, | ||
| start_date=datetime(2021, 1, 1), | ||
| schedule=None, | ||
| tags=["example"], | ||
| ) as dag: | ||
| # [START howto_operator_adls_list] | ||
| adls_files = ADLSListOperator( | ||
| task_id="adls_files", | ||
| path="folder/output/*.parquet", | ||
| azure_data_lake_conn_id="azure_data_lake_default", | ||
| ) | ||
| # [END howto_operator_adls_list] | ||
|
|
||
| from tests.system.utils.watcher import watcher | ||
|
|
||
| # This test needs watcher in order to properly mark success/failure | ||
| # when "tearDown" task with trigger rule is part of the DAG | ||
| list(dag.tasks) >> watcher() | ||
|
|
||
| from tests.system.utils import get_test_run # noqa: E402 | ||
|
|
||
| # Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest) | ||
| test_run = get_test_run(dag) |
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.