Skip to content

feat(csv-parser): update option to provide an array of values that should be set to None in the csv file#581

Merged
Aldo Gonzalez (aldogonzalez8) merged 1 commit intomainfrom
ac8/make-array-for-none-types-parsing
Jun 5, 2025
Merged

feat(csv-parser): update option to provide an array of values that should be set to None in the csv file#581
Aldo Gonzalez (aldogonzalez8) merged 1 commit intomainfrom
ac8/make-array-for-none-types-parsing

Conversation

@aldogonzalez8
Copy link
Contributor

@aldogonzalez8 Aldo Gonzalez (aldogonzalez8) commented Jun 4, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced CSV parsing configuration to allow specifying a list of string values that should be interpreted as None, offering more flexibility beyond just empty cells.
  • Tests

    • Updated tests to cover the new CSV parsing behavior for various specified string values.

@github-actions github-actions bot added the enhancement New feature or request label Jun 4, 2025
@aldogonzalez8 Aldo Gonzalez (aldogonzalez8) changed the title feat(cdv-parser): provide option to provide an array of values that should be set to None in the csv file feat(csv-parser): provide option to provide an array of values that should be set to None in the csv file Jun 4, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 4, 2025

📝 Walkthrough

Walkthrough

The changes replace the boolean set_empty_cell_to_none option for CSV decoding with a new set_values_to_none array of strings. This update generalizes the configuration, allowing multiple specified string values in CSV cells to be interpreted as None instead of only empty strings. Corresponding schema, model, parser, factory, and test logic were updated.

Changes

File(s) Change Summary
airbyte_cdk/sources/declarative/declarative_component_schema.yaml Replaced set_empty_cell_to_none (bool) with set_values_to_none (array of strings) in schema.
airbyte_cdk/sources/declarative/models/declarative_component_schema.py Updated CsvDecoder model: removed boolean, added optional list of strings for set_values_to_none.
airbyte_cdk/sources/declarative/decoders/composite_raw_decoder.py Updated CsvParser: replaced boolean attribute with optional list of strings; parsing logic updated.
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py Changed factory to pass set_values_to_none instead of set_empty_cell_to_none to parser.
unit_tests/sources/declarative/decoders/test_composite_decoder.py Refactored tests to use set_values_to_none (list of strings) and updated CSV generation logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CsvDecoder
    participant CsvParser

    User->>CsvDecoder: Configure with set_values_to_none = ["", "--"]
    CsvDecoder->>CsvParser: Instantiate with set_values_to_none
    CsvParser->>CsvParser: Parse CSV rows
    CsvParser->>CsvParser: For each cell, if value in set_values_to_none, set to None
    CsvParser-->>User: Return parsed data with specified values as None
Loading

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • brianjlai
  • darynaishchenko

Would you like to add a migration note or documentation update for users upgrading from the boolean to the new list-based configuration, wdyt?

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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.

Copy link
Contributor

@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

🧹 Nitpick comments (2)
airbyte_cdk/sources/declarative/declarative_component_schema.yaml (1)

3633-3636: Add description and default for the new set_values_to_none property
The new set_values_to_none entry currently only defines its type. Could we include a description (e.g. “List of string values that should be treated as null when parsing CSV cells”) and a sensible default (like default: []) to guide users? wdyt?

airbyte_cdk/sources/declarative/decoders/composite_raw_decoder.py (1)

125-126: Logic looks correct, but consider a performance optimization?

The implementation correctly converts any cell value found in set_values_to_none to None. For better performance with larger lists, wdyt about converting the list to a set for O(1) lookups?

    def parse(self, data: BufferedIOBase) -> PARSER_OUTPUT_TYPE:
        """
        Parse CSV data from decompressed bytes.
        """
        text_data = TextIOWrapper(data, encoding=self.encoding)  # type: ignore
        reader = csv.DictReader(text_data, delimiter=self._get_delimiter() or ",")
+       values_to_none_set = set(self.set_values_to_none) if self.set_values_to_none else None
        for row in reader:
-           if self.set_values_to_none:
-               row = {k: (None if v in self.set_values_to_none else v) for k, v in row.items()}
+           if values_to_none_set:
+               row = {k: (None if v in values_to_none_set else v) for k, v in row.items()}
            yield row
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f03dc9f and 7351a39.

📒 Files selected for processing (5)
  • airbyte_cdk/sources/declarative/declarative_component_schema.yaml (1 hunks)
  • airbyte_cdk/sources/declarative/decoders/composite_raw_decoder.py (3 hunks)
  • airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1 hunks)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (1 hunks)
  • unit_tests/sources/declarative/decoders/test_composite_decoder.py (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
unit_tests/sources/declarative/decoders/test_composite_decoder.py (1)
airbyte_cdk/sources/declarative/decoders/composite_raw_decoder.py (1)
  • CsvParser (102-127)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: SDM Docker Image Build
  • GitHub Check: Analyze (python)
🔇 Additional comments (11)
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (1)

2651-2656: Align parser instantiation with updated model field
The CsvParser call now uses set_values_to_none as expected to reflect the updated CSV decoder configuration. wdyt?

airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1)

1382-1387: LGTM! Nice generalization from boolean to list of values.

The addition of set_values_to_none as an Optional[List[str]] is a solid improvement that provides much more flexibility than the previous boolean flag. The type annotation and default value are spot-on.

Just curious - might it be worth adding a docstring or field description to help users understand what string values they can specify here? Something like examples of common null representations ("", "NULL", "N/A", etc.)? wdyt?

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 1382-1382: Too few public methods (0/2)

(R0903)

airbyte_cdk/sources/declarative/decoders/composite_raw_decoder.py (2)

12-12: LGTM!

The import addition supports the new Optional[List[str]] type annotation.


106-106: Nice enhancement from boolean to list of strings!

This change aligns perfectly with the PR objective to allow multiple values to be converted to None, not just empty strings. The type annotation is correct and the default value is appropriate.

unit_tests/sources/declarative/decoders/test_composite_decoder.py (7)

11-11: LGTM!

The import addition supports the new type annotations in the test.


47-48: Great refactor of the helper function!

Replacing the boolean add_empty_strings with add_extra_column and extra_column_value makes the function much more flexible and better aligned with the new functionality.


56-58: Logic update looks correct!

The implementation properly uses the new parameters to add the specified value to the extra column.


270-273: Excellent test coverage for the new feature!

The parametrization covers the key scenarios: None (no conversion), empty string, and a custom value. The type annotation is also correct.


277-281: Smart test data generation!

Using set_values_to_none[0] when available and falling back to "random_value" ensures the test data matches the expected conversion behavior.


285-285: Correct parser instantiation!

The update to use set_values_to_none properly tests the new parameter.


294-294: Test expectation logic is spot on!

The conditional logic correctly sets the expected gender value to None when set_values_to_none is provided, matching the parser's behavior.

@aldogonzalez8 Aldo Gonzalez (aldogonzalez8) changed the title feat(csv-parser): provide option to provide an array of values that should be set to None in the csv file feat(csv-parser): update option to provide an array of values that should be set to None in the csv file Jun 5, 2025
Copy link
Collaborator

@ChristoGrab Christo Grabowski (ChristoGrab) left a comment

Choose a reason for hiding this comment

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

Tested on Bing Ads migration :shipit:

@aldogonzalez8 Aldo Gonzalez (aldogonzalez8) merged commit 2a5924f into main Jun 5, 2025
34 checks passed
@aldogonzalez8 Aldo Gonzalez (aldogonzalez8) deleted the ac8/make-array-for-none-types-parsing branch June 5, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants