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

fix: update csv parser for builder compatibility #364

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

ChristoGrab
Copy link
Collaborator

@ChristoGrab ChristoGrab commented Feb 21, 2025

What

Addresses a couple issues related to enabling the CsvParser in the Builder UI.

Closed File Error

When trying to parse a CSV file using the declarative CsvParser, the following error gets thrown:

ValueError: I/O operation on closed file.

This seems to be because when we yield from reader, the file handle is somehow closed before the data has been read. Iterating and yielding each row seems to resolve the issue.

No Records in Builder Read

Specifically when running a test read in the builder, even when getting a successful response with the CSV data included, 0 records are being read:

Screenshot 2025-02-20 at 3 33 38 PM

The issue appears to be because the contents of the record generator are consumed when the records are emitted during read. So no data is subsequently passed to the Builder to be displayed in the testing panel. By flagging the component to specifically not emit messages when in the Builder environment, we can get accurate test results again.

Summary by CodeRabbit

  • Refactor
    • Updated the CSV processing logic to use explicit iteration, enhancing clarity while maintaining the same end results.
    • Modified the component creation process to support dynamic behavior based on instance state.

@github-actions github-actions bot added bug Something isn't working security labels Feb 21, 2025
@ChristoGrab ChristoGrab self-assigned this Feb 21, 2025
@ChristoGrab ChristoGrab marked this pull request as ready for review February 21, 2025 18:33
@ChristoGrab ChristoGrab requested a review from bazarnov February 21, 2025 18:34
Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

📝 Walkthrough

Walkthrough

This pull request implements two main changes. In the CsvParser class (located in composite_raw_decoder.py), the parse method is modified to replace the yield from statement with an explicit loop that yields each row individually. In the ModelToComponentFactory class (found in model_to_component_factory.py), the create_csv_decoder and create_gzip_decoder methods are changed from static methods to instance methods, allowing them to access instance variables and conditionally set the stream_response parameter based on the internal state.

Changes

File(s) Change Summary
airbyte_cdk/.../composite_raw_decoder.py Updated CsvParser.parse: replaced yield from reader with an explicit for loop iterating over csv.DictReader, yielding one row at a time.
airbyte_cdk/.../model_to_component_factory.py Modified create_csv_decoder and create_gzip_decoder: removed the @staticmethod decorator to make them instance methods and updated logic to set stream_response based on the instance variable _emit_connector_builder_messages.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant Parser as CsvParser.parse()
    participant Reader as csv.DictReader
    Caller->>Parser: parse(data)
    Parser->>Reader: Initialize csv.DictReader
    loop Iterating each row
        Reader-->>Parser: row
        Parser-->>Caller: row
    end
Loading
sequenceDiagram
    participant Client as Caller
    participant Factory as ModelToComponentFactory.create_csv_decoder()
    participant Decoder as CompositeRawDecoder
    Client->>Factory: create_csv_decoder(model, config)
    alt _emit_connector_builder_messages is True
        note right of Factory: set stream_response = False
    else
        note right of Factory: stream_response remains True
    end
    Factory->>Decoder: Instantiate with stream_response value
    Decoder-->>Factory: csv decoder instance
    Factory-->>Client: csv decoder
Loading

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • natikgadzhi — do you think this reviewer’s expertise aligns with the changes?
  • artem1205 — would like your thoughts on this update, wdyt?
  • aaronsteers — does your experience with similar changes make you a good fit for this review, wdyt?

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b435a7d and fa13d8f.

📒 Files selected for processing (1)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Analyze (python)
  • GitHub Check: Pytest (Fast)

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

@ChristoGrab ChristoGrab requested a review from bazarnov February 21, 2025 18:45
@ChristoGrab ChristoGrab enabled auto-merge (squash) February 21, 2025 18:58
@ChristoGrab ChristoGrab merged commit c3efa4c into main Feb 21, 2025
23 of 24 checks passed
@ChristoGrab ChristoGrab deleted the christo/csv-builder-fixes branch February 21, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants