Skip to content

Add avro parser to s3 source - #12602

Merged
George Claireaux (Phlair) merged 12 commits into
airbytehq:masterfrom
mohrman:add-avro-parser-to-s3-source
May 11, 2022
Merged

Add avro parser to s3 source#12602
George Claireaux (Phlair) merged 12 commits into
airbytehq:masterfrom
mohrman:add-avro-parser-to-s3-source

Conversation

@mohrman

@mohrman Melker Öhrman (mohrman) commented May 5, 2022

Copy link
Copy Markdown
Contributor

What

This PR aims to add support for avro files for the S3 source. There is currently a limitation to only support avro files with records and not records nested in records

How

The fastavro package is used to read the avro files with the included schema. The data types in the schema are converted to comply with json standard data types.

I use a generator to yield over the records in the file to save memory.

Both schema and rows use the abstract methods from the super class (get_inferred_schema & stream_records)

Recommended reading order

  1. avro_parser.py
  2. avro_spec.py
  3. test_avro_parser.py
  4. spec.py
  5. stream.py
  6. acceptance-test-config.yml
  7. spec.json
  8. setup.py

🚨 User Impact 🚨

No breaking changes

Pre-merge Checklist

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • docs/SUMMARY.md
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the connector is published, connector added to connector index as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here
Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub and connector version bumped by running the /publish command described here
Connector Generator
  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed

Tests

Unit

Put your unit tests output here.

Integration

Put your integration tests output here.

Acceptance

Put your acceptance tests output here.

@CLAassistant

CLAassistant commented May 5, 2022

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Phlair George Claireaux (Phlair) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is excellent, thank you so much for contributing! 🚀

Most of my comments are minor code optimisations, the main change blocking approval is on supporting nested data types (see my review comment for more details).

Comment thread airbyte-integrations/connectors/source-s3/setup.py Outdated
Comment thread airbyte-integrations/connectors/source-s3/setup.py Outdated
Comment thread airbyte-integrations/connectors/source-s3/unit_tests/test_avro_parser.py Outdated
@mohrman
Melker Öhrman (mohrman) marked this pull request as ready for review May 9, 2022 14:07
@github-actions github-actions Bot added the area/documentation Improvements or additions to documentation label May 11, 2022

@Phlair George Claireaux (Phlair) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking excellent, thanks for making the changes!

I've pushed some small additions to enable acceptance tests and update docs.

@Phlair

George Claireaux (Phlair) commented May 11, 2022

Copy link
Copy Markdown
Contributor

/test connector=connectors/source-s3

🕑 connectors/source-s3 https://github.com/airbytehq/airbyte/actions/runs/2307357819
✅ connectors/source-s3 https://github.com/airbytehq/airbyte/actions/runs/2307357819
Python tests coverage:

Name                                                 Stmts   Miss  Cover
------------------------------------------------------------------------
source_acceptance_test/utils/__init__.py                 6      0   100%
source_acceptance_test/tests/__init__.py                 4      0   100%
source_acceptance_test/__init__.py                       2      0   100%
source_acceptance_test/tests/test_full_refresh.py       52      2    96%
source_acceptance_test/utils/asserts.py                 37      2    95%
source_acceptance_test/config.py                        74      6    92%
source_acceptance_test/utils/json_schema_helper.py     105     13    88%
source_acceptance_test/utils/common.py                  80     17    79%
source_acceptance_test/utils/compare.py                 62     23    63%
source_acceptance_test/tests/test_core.py              285    106    63%
source_acceptance_test/base.py                          10      4    60%
source_acceptance_test/utils/connector_runner.py       110     48    56%
source_acceptance_test/tests/test_incremental.py        69     38    45%
------------------------------------------------------------------------
TOTAL                                                  896    259    71%
Name                                                              Stmts   Miss  Cover
-------------------------------------------------------------------------------------
source_s3/source_files_abstract/formats/parquet_spec.py               9      0   100%
source_s3/source_files_abstract/formats/csv_spec.py                  16      0   100%
source_s3/source_files_abstract/formats/avro_spec.py                  5      0   100%
source_s3/s3_utils.py                                                19      0   100%
source_s3/__init__.py                                                 2      0   100%
source_s3/source.py                                                  29      1    97%
source_s3/source_files_abstract/storagefile.py                       23      1    96%
source_s3/s3file.py                                                  37      2    95%
source_s3/source_files_abstract/formats/abstract_file_parser.py      35      2    94%
source_s3/source_files_abstract/stream.py                           185     11    94%
source_s3/stream.py                                                  43      3    93%
source_s3/source_files_abstract/formats/csv_parser.py                74     18    76%
source_s3/source_files_abstract/file_info.py                         26      8    69%
source_s3/utils.py                                                   29     10    66%
source_s3/source_files_abstract/source.py                            37     14    62%
source_s3/source_files_abstract/spec.py                              43     22    49%
source_s3/source_files_abstract/formats/avro_parser.py               38     25    34%
source_s3/source_files_abstract/formats/parquet_parser.py            61     44    28%
-------------------------------------------------------------------------------------
TOTAL                                                               711    161    77%
Name                                                              Stmts   Miss  Cover
-------------------------------------------------------------------------------------
source_s3/source_files_abstract/formats/parquet_spec.py               9      0   100%
source_s3/source_files_abstract/formats/csv_spec.py                  16      0   100%
source_s3/source_files_abstract/formats/avro_spec.py                  5      0   100%
source_s3/source_files_abstract/formats/abstract_file_parser.py      35      0   100%
source_s3/source.py                                                  29      0   100%
source_s3/__init__.py                                                 2      0   100%
source_s3/source_files_abstract/formats/parquet_parser.py            61      3    95%
source_s3/source_files_abstract/formats/avro_parser.py               38      3    92%
source_s3/source_files_abstract/storagefile.py                       23      5    78%
source_s3/source_files_abstract/formats/csv_parser.py                74     18    76%
source_s3/utils.py                                                   29      8    72%
source_s3/source_files_abstract/file_info.py                         26     10    62%
source_s3/source_files_abstract/source.py                            37     15    59%
source_s3/s3file.py                                                  37     18    51%
source_s3/source_files_abstract/stream.py                           185     91    51%
source_s3/source_files_abstract/spec.py                              43     22    49%
source_s3/s3_utils.py                                                19     13    32%
source_s3/stream.py                                                  43     30    30%
-------------------------------------------------------------------------------------
TOTAL                                                               711    236    67%

@Phlair

George Claireaux (Phlair) commented May 11, 2022

Copy link
Copy Markdown
Contributor

/publish connector=connectors/source-s3

🕑 connectors/source-s3 https://github.com/airbytehq/airbyte/actions/runs/2307776881
❌ Failed to publish connectors/source-s3
❌ Couldn't auto-bump version for connectors/source-s3

@Phlair

Copy link
Copy Markdown
Contributor

^ weird, the tests passed in /test but then the parquet parser (not changed in this PR) failed tests in the /publish command causing that to fail. There's no reason unit tests should have a transient failure like that but going to run again anyway just in case...

@Phlair

George Claireaux (Phlair) commented May 11, 2022

Copy link
Copy Markdown
Contributor

/publish connector=connectors/source-s3

🕑 connectors/source-s3 https://github.com/airbytehq/airbyte/actions/runs/2308075491
🚀 Successfully published connectors/source-s3
🚀 Auto-bumped version for connectors/source-s3
✅ connectors/source-s3 https://github.com/airbytehq/airbyte/actions/runs/2308075491

@Phlair
George Claireaux (Phlair) merged commit f918859 into airbytehq:master May 11, 2022
Yevhen Sukhomud (suhomud) pushed a commit that referenced this pull request May 23, 2022
* added MVP avro parser running fine locally

* added unit tests for avro

* added wip state of avro integration test setup

* deleted unused files

* added avro specific config path

* fixed comments. Added nested record support, simplify code and minor fixes

* bumped version + docs update

* Added working acceptance tests + format

* auto-bump connector version

Co-authored-by: George Claireaux <george@claireaux.co.uk>
Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/connectors Connector related issues area/documentation Improvements or additions to documentation community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants