Skip to content

Conversation

@Ash-ZAMAN
Copy link

Hi,

I noticed there was no airflow file sensor suitable for Azure Data Lake Storage. Hence, I created one. That could be realy useful for people who store data in Data Lake.

My sensor is adaptable with the prefix of the file's name and any directory path

hope this contribution will help someone.

Regards, Ashraf ZAMAN


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.

@boring-cyborg
Copy link

boring-cyborg bot commented Mar 16, 2022

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@potiuk
Copy link
Member

potiuk commented Mar 19, 2022

Can you please add unit tests for it ? (see other unit tests for azure as an example). Also an example dag and ideally howto guide would be great.

Copy link
Contributor

@josh-fell josh-fell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 For adding unit tests, example DAG, and how-to guide would be great. All don't necessarily need to be part of this PR.

The airflow.contrib path is deprecated so we shouldn't add new modules there. This module should be part of airflow.providers.microsoft.azure.sensors.

I would recommend running static code checks if you can as well. This will make the CI run smoother when approved and decrease any review back-and-forth, fixes, etc.

Comment on lines +1 to +3
from airflow.contrib.hooks.azure_data_lake_hook import AzureDataLakeHook
from airflow.sensors.base_sensor_operator import BaseSensorOperator
from airflow.utils.decorators import apply_defaults
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from airflow.contrib.hooks.azure_data_lake_hook import AzureDataLakeHook
from airflow.sensors.base_sensor_operator import BaseSensorOperator
from airflow.utils.decorators import apply_defaults
from airflow.providers.microsoft.azure.hooks.data_lake import AzureDataLakeHook
from airflow.sensors.base import BaseSensorOperator

The import paths for AzureDataLakeHook and BaseSensorOperator are deprecated. Also using apply_defaults is not necessary as of Airflow 2.


"""

@apply_defaults
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@apply_defaults

No longer needed as of Airflow 2.

@apply_defaults
def __init__(
self,
DataLake_path,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically use snake case for variables, args, etc.

DataLake_path,
prefix,
azure_data_lake_conn_id="azure_data_lake_default",
check_options=None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look used in the sensor. Should it be removed?

Comment on lines +19 to +21
DataLake_path : directory of the file

prefix : file name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the docstring for the parameters to match the Sphinx style used. The azure_data_lake_conn_id above is a good example or other examples in operators and sensors.

Comment on lines +11 to +15
Interacts with Azure Data Lake:

Client ID and client secret should be in user and password parameters.
Tenant and account name should be extra field as
{"tenant": "<TENANT>", "account_name": "ACCOUNT_NAME"}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description doesn't quite describe the purpose of the sensor. Would you mind updating and elaborating here?

Comment on lines +50 to +54
return len(hook.list(self.DataLake_path + "/" + self.prefix)) > 0


# return TRUE => 1 ou more file detected
# return FALSE => No file detected
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return len(hook.list(self.DataLake_path + "/" + self.prefix)) > 0
# return TRUE => 1 ou more file detected
# return FALSE => No file detected
num_files = len(hook.list(self.DataLake_path + "/" + self.prefix))
return num_files > 0

Small refactor for readability. The comments are better suited for the sensor's description in the docstring since this is the fundamental operation of the sensor.

@potiuk
Copy link
Member

potiuk commented Apr 25, 2022

I am going to release a new version of providers in ~ week so if you want to get it included @Ash-ZAMAN - good time to address the comments.

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Jun 10, 2022
@github-actions github-actions bot closed this Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PRs per the .github/workflows/stale.yml policy file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants