Skip to content
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

Feat: Adds interop with Arrow library using new method Dataset.to_arrow() #281

Merged
merged 22 commits into from
Jul 9, 2024

Conversation

avirajsingh7
Copy link
Contributor

@avirajsingh7 avirajsingh7 commented Jun 27, 2024

Resolves #204

As discuss in issue added a supoort pyarrow dataset instead of pyarrow table to handle a large datasets.

Supporting docs:
pyarrow dataset
pyarrow.Table.from_pandas

Still need input on optimal chunksize...

Summary by CodeRabbit

  • New Features

    • Introduced Arrow dataset functionality for handling large tables by reading them in chunks.
    • Added to_arrow method for converting datasets to Arrow format with a specified chunk size.
  • Bug Fixes

    • Ensured proper handling of large datasets by implementing chunk reading.
  • Tests

    • Added new test case for verifying Arrow dataset functionality, including row and batch count checks.

Copy link

coderabbitai bot commented Jun 27, 2024

Walkthrough

Walkthrough

The updates introduce native Arrow support by adding to_arrow methods to dataset classes, enabling chunk-wise data processing and conversion to Arrow datasets. Key changes include new imports for pyarrow, the implementation of to_arrow methods in base and SQL datasets, a get_arrow_dataset method in caches, and a new default chunk size constant.

Changes

File Change Summary
airbyte/caches/base.py Introduced imports for pyarrow, added get_arrow_dataset method to handle large tables by reading them in chunks and converting to Arrow tables.
airbyte/caches/bigquery.py Added get_arrow_dataset method which raises NotImplementedError, BigQuery does not support Arrow.
airbyte/constants.py Added DEFAULT_ARROW_MAX_CHUNK_SIZE constant with a value of 100,000 to specify default chunk size.
airbyte/datasets/_base.py Added to_arrow method to base dataset class for Arrow dataset conversion with default max chunk size.
airbyte/datasets/_sql.py Implemented to_arrow method in SQLDataset for retrieval of data in Arrow format with specified chunk size.
tests/integration_tests/test_all_cache_types.py Added test case for reading data using Arrow dataset, checking row and batch counts.

Sequence Diagram(s)

%% No sequence diagrams generated due to straightforward nature of changes.

Assessment against linked issues

Objective Addressed Explanation
Feature Request: Add to_arrow() on Dataset class [#204]

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@avirajsingh7 avirajsingh7 changed the title Feature : Added to_arrow_dataset() on Dataset class Feat : Added to_arrow_dataset() on Dataset class Jun 27, 2024
@avirajsingh7 avirajsingh7 changed the title Feat : Added to_arrow_dataset() on Dataset class feat : Added to_arrow_dataset() on Dataset class Jun 27, 2024
@avirajsingh7 avirajsingh7 changed the title feat : Added to_arrow_dataset() on Dataset class Feat: Added to_arrow_dataset() on Dataset class Jun 27, 2024
Copy link
Contributor

@aaronsteers aaronsteers left a comment

Choose a reason for hiding this comment

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

A few changes requested inline.

Also, I would like request at least one or two tests added. Feel free to replicate another test that validates to_pandas() capabilities. At minimum, we just want to make sure that the code can execute. It is probably also worth adding a version of the test that forces a small chunk size, ensuring that the ">1 chunk" codepath is also working as expected.

Overall - this looks great. I think we will be ready to merge once this feedback is resolved.

airbyte/datasets/_base.py Outdated Show resolved Hide resolved
airbyte/datasets/_base.py Outdated Show resolved Hide resolved
airbyte/datasets/_sql.py Outdated Show resolved Hide resolved
@aaronsteers
Copy link
Contributor

@coderabbitai review

Copy link

coderabbitai bot commented Jun 29, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@aaronsteers
Copy link
Contributor

aaronsteers commented Jun 29, 2024

/fix-pr

PR auto-fix job started... Check job output.

✅ Changes applied successfully.

@aaronsteers
Copy link
Contributor

@avirajsingh7 - Auto-fix applied some lint fixing. And the other fixes you applied looked great. Lmk if this is ready for final review or if you are still applying additional changes.

@avirajsingh7
Copy link
Contributor Author

@aaronsteers it is ready for review

@aaronsteers

This comment was marked as outdated.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 37b50db and b99dcfd.

Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
Files selected for processing (5)
  • airbyte/caches/base.py (2 hunks)
  • airbyte/datasets/_base.py (2 hunks)
  • airbyte/datasets/_sql.py (4 hunks)
  • pyproject.toml (1 hunks)
  • tests/integration_tests/test_all_cache_types.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • pyproject.toml
Additional comments not posted (3)
airbyte/datasets/_sql.py (2)

108-109: Ensure chunk size is appropriate and method is tested.

The to_arrow method allows specifying a chunk size for processing the dataset. Ensure that the chunk size is appropriate and that the method is tested.


175-186: Ensure chunk size is appropriate and method is tested.

The to_arrow method allows specifying a chunk size for processing the dataset. Ensure that the chunk size is appropriate and that the method is tested.

Verification successful

Ensure chunk size is appropriate and method is tested.

The to_arrow method allows specifying a chunk size for processing the dataset. Based on the search results, the CachedDataset class is referenced in several integration tests, indicating that the method is likely tested indirectly through these tests.

  • tests/integration_tests/test_source_test_fixture.py
  • tests/integration_tests/cloud/test_cloud_sql_reads.py
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the to_arrow method in CachedDataset is tested.

# Test: Search for tests that call the to_arrow method in CachedDataset.
rg --type python $'CachedDataset.to_arrow'

Length of output: 72



Script:

#!/bin/bash
# Description: Verify that the to_arrow method in CachedDataset is tested.

# Test: Search for tests that call the to_arrow method in CachedDataset.
rg 'CachedDataset.to_arrow'

Length of output: 27



Script:

#!/bin/bash
# Description: Verify that the CachedDataset class and its methods are tested.

# Search for any references to the CachedDataset class in test files.
rg 'CachedDataset' --glob '*test*.py'

# Search for any test files that might be testing the functionality of CachedDataset.
fd test --type f --extension py

Length of output: 3235

tests/integration_tests/test_all_cache_types.py (1)

166-168: Verify the correctness of the conversion and assertions.

The conversion to Arrow dataset and the assertions for row count and batch iteration look correct. Ensure that the chunk size of 10 is optimal for the dataset size.

Verification successful

Verify the correctness of the conversion and assertions.

The conversion to an Arrow dataset and the assertions for row count and batch iteration look correct. Ensure that the chunk size of 10 is optimal for the dataset size.

  • The code snippet is located in tests/integration_tests/test_all_cache_types.py around lines 166-168.
  • The assertions check both the row count (FAKER_SCALE_A) and the number of batches (20).
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the conversion and assertions.

# Test: Run the test suite to ensure the new functionality is covered by tests.
pytest tests/integration_tests/test_all_cache_types.py

Length of output: 130



Script:

#!/bin/bash
# Search for the function containing the provided code snippet to inspect its correctness.
ast-grep --lang python --pattern $'def $_($$$):\n    $$$\n    arrow_dataset = result["users"].to_arrow(chunksize=10)\n    assert arrow_dataset.count_rows() == FAKER_SCALE_A\n    assert sum(1 for _ in arrow_dataset.to_batches()) == 20\n    $$$' 

Length of output: 239



Script:

#!/bin/bash
# Search for the provided code snippet in the specified file to locate its exact position and inspect its context.
rg 'arrow_dataset = result\["users"\].to_arrow\(chunksize=10\)' tests/integration_tests/test_all_cache_types.py -A 5 -B 5

Length of output: 644

airbyte/datasets/_base.py Outdated Show resolved Hide resolved
airbyte/caches/base.py Outdated Show resolved Hide resolved
Copy link
Contributor

@aaronsteers aaronsteers left a comment

Choose a reason for hiding this comment

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

The changes look great. Thanks for the added changes and for the contribution. 🚀

Will merge once all tests are passed.

tests/integration_tests/test_all_cache_types.py Outdated Show resolved Hide resolved
@aaronsteers
Copy link
Contributor

aaronsteers commented Jun 29, 2024

/poetry-lock

poetry lock job started... Check job output.

poetry lock applied successfully.

Resolving dependencies... changes
@aaronsteers

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as resolved.

@aaronsteers
Copy link
Contributor

aaronsteers commented Jul 8, 2024

/test-pr

PR test job started... Check job output.

❌ Tests failed.

@aaronsteers
Copy link
Contributor

aaronsteers commented Jul 8, 2024

@avirajsingh7 - On the tests side, I'm seeing this weird error. I'm not sure if it is new, since pulling in version updates from main, or if this was here before and we missed it.

UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.

https://github.com/airbytehq/PyAirbyte/actions/runs/9832269420

Update:

I think I have this resolved now. Will push an update shortly.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 936735a and fcbbb80.

Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
Files selected for processing (1)
  • pyproject.toml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pyproject.toml

@aaronsteers
Copy link
Contributor

aaronsteers commented Jul 8, 2024

/test-pr

PR test job started... Check job output.

❌ Tests failed.

@aaronsteers
Copy link
Contributor

aaronsteers commented Jul 8, 2024

BigQuery is failing at the pandas_chunks = pd.read_sql_table(.

To merge, we may want to declare BigQuery unsupported and simply raise NotImplementedError with a clear error message for BigQuery. @avirajsingh7 - Lmk if you are able to pick this up. We are very close!

FAILED tests/integration_tests/test_all_cache_types.py::test_faker_read[BigQuery] - sqlalchemy.exc.InvalidRequestError: Could not reflect: requested table(s) not available in Engine(bigquery://dataline-integration-testing?credentials_path=%2Ftmp%2Ftmpt3yt8wxn.txt) schema 'test_deleteme_fx14pe': (users)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
airbyte/caches/bigquery.py (1)

33-33: Remove whitespace from blank line.

The blank line contains unnecessary whitespace.

-    
+
Tools
Ruff

33-33: Blank line contains whitespace

Remove whitespace from blank line

(W293)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fcbbb80 and f9b7b6e.

Files selected for processing (2)
  • airbyte/caches/base.py (3 hunks)
  • airbyte/caches/bigquery.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • airbyte/caches/base.py
Additional context used
Ruff
airbyte/caches/bigquery.py

33-33: Blank line contains whitespace

Remove whitespace from blank line

(W293)

Additional comments not posted (2)
airbyte/caches/bigquery.py (2)

26-26: LGTM! Import statement is appropriate.

The import statement for DEFAULT_ARROW_MAX_CHUNK_SIZE is necessary for the new method.


34-45: LGTM! Method implementation is appropriate.

The method correctly raises a NotImplementedError with a clear and informative message.

@avirajsingh7
Copy link
Contributor Author

avirajsingh7 commented Jul 9, 2024

BigQuery is failing at the pandas_chunks = pd.read_sql_table(.

To merge, we may want to declare BigQuery unsupported and simply raise NotImplementedError with a clear error message for BigQuery. @avirajsingh7 - Lmk if you are able to pick this up. We are very close!

FAILED tests/integration_tests/test_all_cache_types.py::test_faker_read[BigQuery] - sqlalchemy.exc.InvalidRequestError: Could not reflect: requested table(s) not available in Engine(bigquery://dataline-integration-testing?credentials_path=%2Ftmp%2Ftmpt3yt8wxn.txt) schema 'test_deleteme_fx14pe': (users)

@aaronsteers I think this fix should work,
I have skipped tests for big_query, if there is specific method I can get cache type other than get_sql_alchemy_url LMK

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f9b7b6e and 4ebdc46.

Files selected for processing (1)
  • tests/integration_tests/test_all_cache_types.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/integration_tests/test_all_cache_types.py

@avirajsingh7
Copy link
Contributor Author

/fix-pr

@aaronsteers
Copy link
Contributor

@avirajsingh7 - Thanks for taking the revision for the BigQuery issue. I did some digging and found this issue from a while back, describing a similar problem for to_pandas() generally.

@aaronsteers
Copy link
Contributor

aaronsteers commented Jul 9, 2024

/fix-pr

Auto-Fix Job Info

This job attempts to auto-fix any linting or formating issues. If any fixes are made,
those changes will be automatically committed and pushed back to the PR.
(This job requires that the PR author has "Allow edits from maintainers" enabled.)

PR auto-fix job started... Check job output.

✅ Changes applied successfully.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4ebdc46 and 972f01d.

Files selected for processing (1)
  • airbyte/caches/bigquery.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • airbyte/caches/bigquery.py

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 972f01d and 08e11e1.

Files selected for processing (2)
  • airbyte/caches/bigquery.py (1 hunks)
  • tests/integration_tests/test_all_cache_types.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/integration_tests/test_all_cache_types.py
Additional context used
Ruff
airbyte/caches/bigquery.py

41-41: Blank line contains whitespace

Remove whitespace from blank line

(W293)

airbyte/caches/bigquery.py Outdated Show resolved Hide resolved
airbyte/caches/bigquery.py Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 08e11e1 and e47de78.

Files selected for processing (1)
  • airbyte/caches/bigquery.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • airbyte/caches/bigquery.py

@aaronsteers
Copy link
Contributor

aaronsteers commented Jul 9, 2024

/test-pr

PR test job started... Check job output.

❌ Tests failed.

(Actually successful. Failure is false-positive.)

@aaronsteers aaronsteers merged commit 2682ed2 into airbytehq:main Jul 9, 2024
9 checks passed
@aaronsteers
Copy link
Contributor

aaronsteers commented Jul 9, 2024

@avirajsingh7 - Thanks for all your hard work on this. Tests are passing. Merged!!

🚀 🙌

@avirajsingh7
Copy link
Contributor Author

Thanks @aaronsteers for all your efforts and help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

💡 Feature Request: Add to_arrow() on Dataset class
3 participants