You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "selimchergui (via GitHub)" <gi...@apache.org> on 2024/01/28 11:17:07 UTC

[PR] SqlToS3Operator: feat/ add max_rows_per_file parameter [airflow]

selimchergui opened a new pull request, #37055:
URL: https://github.com/apache/airflow/pull/37055

   **Description**
   `SqlToS3Operator` create an S3 object from the output of sql qurey. Unless you specify a groupby_kwargs parameter, the entire data will be written in one object. This could results on data pipeline issues specially if output files are consumed by limited resources workers (like pods).
   So I suggest adding a new paramter, max_rows_per_file, to limit the size of destination files and dispatch output data into multiple files.
   
   **Use case/motivation**
   I faced a lot of out-of-memory issues when trying to process SqlToS3Operator destination object. With such a feature, output will be standardized and new compute worker can have more suited size.
   
   Related issues
   No response
   
   **Are you willing to submit a PR?**
    Yes I am willing to submit a PR!
   
   **Code of Conduct**
    I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md) 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SqlToS3Operator: feat/ add max_rows_per_file parameter [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #37055:
URL: https://github.com/apache/airflow/pull/37055#discussion_r1469545063


##########
airflow/providers/amazon/aws/transfers/sql_to_s3.py:
##########
@@ -81,6 +81,9 @@ class SqlToS3Operator(BaseOperator):
                 You can specify this argument if you want to use a different
                 CA cert bundle than the one used by botocore.
     :param file_format: the destination file format, only string 'csv', 'json' or 'parquet' is accepted.
+    :param max_rows_per_file: (optional) argument to set destination file number of rows limit, if source data
+        is larger than that, it will be dispatched into multiple files.
+        Will be ignored if groupby_kwargs argument is specified.

Review Comment:
   ```suggestion
           Will be ignored if ``groupby_kwargs`` argument is specified.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SqlToS3Operator: feat/ add max_rows_per_file parameter [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #37055:
URL: https://github.com/apache/airflow/pull/37055#issuecomment-1913559242

   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 Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (ruff, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-pre-commit-hooks) 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](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) 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](https://www.apache.org/foundation/policies/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]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
   - Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
   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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SqlToS3Operator: feat/ add max_rows_per_file parameter [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #37055:
URL: https://github.com/apache/airflow/pull/37055#issuecomment-1914630398

   I reverse-quoted a grouby_keywords as spellchecking did not like it, hopefully it will get green and I will be able to merge it


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SqlToS3Operator: feat/ add max_rows_per_file parameter [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #37055:
URL: https://github.com/apache/airflow/pull/37055


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SqlToS3Operator: feat/ add max_rows_per_file parameter [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #37055:
URL: https://github.com/apache/airflow/pull/37055#issuecomment-1915824330

   Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional contributions.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SqlToS3Operator: feat/ add max_rows_per_file parameter [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #37055:
URL: https://github.com/apache/airflow/pull/37055#issuecomment-1914610384

   LGTM


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SqlToS3Operator: feat/ add max_rows_per_file parameter [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #37055:
URL: https://github.com/apache/airflow/pull/37055#issuecomment-1915824822

   > Now that you explicitly fail if both parameters are specified, you could potentially simplify this statement: `if self.max_rows_per_file and not self.groupby_kwargs:` But I'll leave that up to you :)
   
   Yeah. Thought about that too, but now it is very explicit as well.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SqlToS3Operator: feat/ add max_rows_per_file parameter [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #37055:
URL: https://github.com/apache/airflow/pull/37055#discussion_r1468901595


##########
airflow/providers/amazon/aws/transfers/sql_to_s3.py:
##########
@@ -194,13 +197,32 @@ def execute(self, context: Context) -> None:
 
     def _partition_dataframe(self, df: pd.DataFrame) -> Iterable[tuple[str, pd.DataFrame]]:
         """Partition dataframe using pandas groupby() method."""
+        try:
+            import secrets
+            import string
+
+            import numpy as np
+        except ImportError:
+            pass
+        # if max_rows_per_file argument is specified, a temporary column with a random unusual name will be
+        # added to the dataframe. This column is used to dispatch the dataframe into smaller ones using groupby()
+        random_column_name = ""
+        if self.max_rows_per_file and not self.groupby_kwargs:

Review Comment:
   Could you please rather fail in case both parameters are specified? I think it's better to fail explicitly rather than silently swallow `max_ros_per_file`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SqlToS3Operator: feat/ add max_rows_per_file parameter [airflow]

Posted by "selimchergui (via GitHub)" <gi...@apache.org>.
selimchergui commented on code in PR #37055:
URL: https://github.com/apache/airflow/pull/37055#discussion_r1469234261


##########
airflow/providers/amazon/aws/transfers/sql_to_s3.py:
##########
@@ -194,13 +197,32 @@ def execute(self, context: Context) -> None:
 
     def _partition_dataframe(self, df: pd.DataFrame) -> Iterable[tuple[str, pd.DataFrame]]:
         """Partition dataframe using pandas groupby() method."""
+        try:
+            import secrets
+            import string
+
+            import numpy as np
+        except ImportError:
+            pass
+        # if max_rows_per_file argument is specified, a temporary column with a random unusual name will be
+        # added to the dataframe. This column is used to dispatch the dataframe into smaller ones using groupby()
+        random_column_name = ""
+        if self.max_rows_per_file and not self.groupby_kwargs:

Review Comment:
   Sure!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org