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(low-code cdk): add condition to add fields #409

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

lazebnyi
Copy link
Contributor

@lazebnyi lazebnyi commented Mar 12, 2025

Fixed : https://github.com/airbytehq/airbyte-internal-issues/issues/11938

Summary by CodeRabbit

  • New Features
    • Introduced a new conditional logic option for adding fields, allowing record transformations to include extra fields only when defined expressions evaluate to true. This enhancement provides users with greater flexibility in tailoring how and when fields are applied based on dynamic conditions.

@Copilot Copilot bot review requested due to automatic review settings March 12, 2025 10:42
@github-actions github-actions bot added the enhancement New feature or request label Mar 12, 2025
@lazebnyi
Copy link
Contributor Author

lazebnyi commented Mar 12, 2025

/autofix

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.

Note: This job can only be run by maintainers. On PRs from forks, this command requires
that the PR author has enabled the Allow edits from maintainers option.

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

✅ Changes applied successfully.

Copy link
Contributor

coderabbitai bot commented Mar 12, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a new condition property into the AddFields definition across the declarative component schema. The addition is implemented in the YAML schema file, Python model, transformation logic, and associated tests. Changes include updates to the create_add_fields parser and modifications to the transformation flow to conditionally add fields based on the evaluation of the condition expression.

Changes

Files Summary of Changes
airbyte_cdk/.../declarative_component_schema.yaml Added new condition property to the AddFields definition with description, default value, interpolation context (config, property, parameters), and usage examples.
airbyte_cdk/.../declarative_component_schema.py Introduced new field condition: Optional[str] in AddFields.
airbyte_cdk/.../model_to_component_factory.py Updated the create_add_fields method to pass the condition parameter when constructing an AddFields object.
airbyte_cdk/.../add_fields.py Added a condition attribute to the AddFields class and modified the transform method to add fields based on a conditional evaluation using an interpolated boolean.
unit_tests/.../test_add_fields.py Modified test cases to include the new condition parameter in the parametrization, adding scenarios where fields are conditionally added or omitted.

Suggested reviewers

  • darynaishchenko
  • maxi297
  • aldogonzalez8

Would you like to add these reviewers, 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 0098859 and 3b01f3f.

📒 Files selected for processing (1)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (1 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 (Fast)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: SDM Docker Image Build

🪧 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.
  • @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: 1

🧹 Nitpick comments (2)
airbyte_cdk/sources/declarative/transformations/add_fields.py (1)

141-143: Conditional field addition logic is well implemented.

The transform method now checks if the condition is empty or evaluates to true before adding fields. This maintains backward compatibility (empty condition works like before) while adding new functionality.

One thought - should we consider adding debug logging when fields are skipped due to conditions not being met? This might help users troubleshoot their configurations, wdyt?

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

1471-1480: Review on the new condition field in AddFields:
You've added a new optional condition field to control whether fields should be added, which aligns with similar patterns elsewhere in the schema (e.g., in RecordFilter and RemoveFields). A couple of quick questions:

  • Are you comfortable with using an empty string ("") as the default instead of perhaps using None? (I see consistency with other parts of the code, so this might be fine.)
  • The description string ends with an extra comma. Would you consider cleaning it up for clarity?

Here's a small diff suggestion to polish up the formatting:

-    condition: Optional[str] = Field(
-        "",
-        description="Fields will be added if expression is evaluated to True.,",
-        examples=[
-            "{{ property|string == '' }}",
-            "{{ property is integer }}",
-            "{{ property|length > 5 }}",
-            "{{ property == 'some_string_to_match' }}",
-        ],
-    )
+    condition: Optional[str] = Field(
+        "",
+        description="Fields will be added if the expression evaluates to True.",
+        examples=[
+            "{{ property|string == '' }}",
+            "{{ property is integer }}",
+            "{{ property|length > 5 }}",
+            "{{ property == 'some_string_to_match' }}",
+        ],
+    )

wdyt?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5d82e14 and a3e2907.

📒 Files selected for processing (5)
  • airbyte_cdk/sources/declarative/declarative_component_schema.yaml (1 hunks)
  • airbyte_cdk/sources/declarative/models/declarative_component_schema.py (10 hunks)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (1 hunks)
  • airbyte_cdk/sources/declarative/transformations/add_fields.py (3 hunks)
  • unit_tests/sources/declarative/transformations/test_add_fields.py (16 hunks)
🧰 Additional context used
🪛 GitHub Actions: Linters
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

[error] 709-709: Argument "condition" to "AddFields" has incompatible type "str | None"; expected "str"

⏰ Context from checks skipped due to timeout of 90000ms (9)
  • 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: SDM Docker Image Build
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Analyze (python)
🔇 Additional comments (7)
airbyte_cdk/sources/declarative/transformations/add_fields.py (3)

10-10: New import InterpolatedBoolean looks good!

Nice addition of the InterpolatedBoolean import to support conditional field addition, aligning with the new feature.


90-90: Condition attribute is well-defined.

The new condition attribute with default empty string provides good backward compatibility. This allows for optional conditional field addition without breaking existing implementations, wdyt?


96-98: Initializing filter interpolator looks good.

Clean implementation of the condition evaluation using the InterpolatedBoolean class in the __post_init__ method.

airbyte_cdk/sources/declarative/declarative_component_schema.yaml (1)

113-125: Well-defined condition property with helpful examples.

The schema definition for the new condition property is clear and thorough:

  • Description clearly explains the purpose
  • Default empty string maintains backward compatibility
  • Interpolation context includes the necessary variables
  • Examples cover common use cases for filtering

The examples are particularly useful, showing different ways to use the condition:

  • Checking for empty strings
  • Type validation
  • Length-based conditions
  • Exact matching

This will be valuable for users implementing conditional field addition. Nice work!

unit_tests/sources/declarative/transformations/test_add_fields.py (3)

161-178: LGTM! Good test cases for the new condition parameter

The new test cases effectively validate the conditional behavior - verifying that fields are only added when the condition evaluates to True and skipped when False. This is a solid addition to ensure the new feature works as expected.


185-186: LGTM! Function signature updated correctly

The function signature has been properly updated to include the new condition parameter.


193-193: LGTM! Correctly passing the condition parameter

The AddFields constructor now properly receives the condition parameter, ensuring the tests validate the new conditional functionality.

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/models/declarative_component_schema.py (1)

1463-1472: The addition of the condition field looks good!

This new feature adds flexibility to the AddFields transformation by allowing it to conditionally add fields based on evaluated expressions. The examples provided are comprehensive and illustrate various use cases.

Just noticed a tiny typo in line 1465 - there's an extra comma after "True" in the phrase "True.,". Nothing major, but might be worth removing for clarity, wdyt?

-        description="Fields will be added if expression is evaluated to True.,",
+        description="Fields will be added if expression is evaluated to True.",
unit_tests/sources/declarative/transformations/test_add_fields.py (1)

161-178: Good test cases for the new condition functionality!

These test cases clearly demonstrate the behavior when the condition is explicitly set to False (no fields added) or True (fields added).

Would it also be valuable to test some of the more complex condition examples from your Field description, like string comparison or length checks? Something like "{{ property|length > 5 }}" or "{{ property is integer }}", wdyt?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a3e2907 and 0098859.

📒 Files selected for processing (3)
  • 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/transformations/test_add_fields.py (16 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 (9)
  • 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: SDM Docker Image Build
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Analyze (python)
🔇 Additional comments (4)
unit_tests/sources/declarative/transformations/test_add_fields.py (4)

14-16: LGTM! Good update to the parametrize decorator.

The test parameter list has been correctly updated to include the new condition parameter.


21-22: Solid backward compatibility approach.

Adding an empty string condition to existing test cases ensures backward compatibility while testing the new functionality. The empty string is correctly treated as a default "true" condition where fields are added.

Also applies to: 30-31, 39-40, 48-49, 57-58, 66-67, 75-76, 84-85, 93-94, 102-103, 111-112, 120-121, 129-130, 138-139, 147-148, 156-157


185-186: LGTM! Function signature updated correctly.

The test function signature has been properly updated to include the new condition parameter.


193-195: Constructor updated appropriately.

The AddFields constructor call now includes the condition parameter, ensuring it's properly passed to the transformation. The line formatting maintains good readability despite the added parameter.

@lazebnyi
Copy link
Contributor Author

lazebnyi commented Mar 12, 2025

/autofix

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.

Note: This job can only be run by maintainers. On PRs from forks, this command requires
that the PR author has enabled the Allow edits from maintainers option.

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

✅ Changes applied successfully.

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.

1 participant