Skip to content

feat(low-code): added condition to TypesMap of DynamicSchemaLoader #224

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

Merged

Conversation

darynaishchenko
Copy link
Contributor

@darynaishchenko darynaishchenko commented Jan 16, 2025

What

Dynamic schema loader: there can be a case when type of the field doesn't depend on "type" field value only. Example: source airtable.
field_1

{
"type": "formula"
"result": {"type": "number"}
}

field_2

{
"type": "formula"
"result": {"type": "singleLineText"}
}

How

To properly identify field type in cases like above condition option was added to TypesMap object. Now providing TypesMap object condition we can create 2 separate cases for string values and number values.
See unit_tests/sources/declarative/schema/test_dynamic_schema_loader.py for more examples.

Summary by CodeRabbit

  • New Features

    • Introduced a condition property to support more flexible type mapping and record filtering in declarative components.
    • Enhanced schema loader to support conditional type validation and replacement.
  • Improvements

    • Expanded type mapping capabilities to allow string conditions.
    • Improved dynamic schema generation with context-aware type validation.
  • Tests

    • Added a new test case to validate the dynamic schema loader with type conditions.

@darynaishchenko darynaishchenko self-assigned this Jan 16, 2025
@github-actions github-actions bot added the enhancement New feature or request label Jan 16, 2025
@darynaishchenko
Copy link
Contributor Author

darynaishchenko commented Jan 16, 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 Jan 16, 2025

Warning

Rate limit exceeded

@darynaishchenko has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b189655 and b256ad8.

📒 Files selected for processing (4)
  • airbyte_cdk/sources/declarative/declarative_component_schema.yaml (1 hunks)
  • airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1 hunks)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (1 hunks)
  • airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (4 hunks)
📝 Walkthrough

Walkthrough

This pull request introduces a new condition property to the TypesMap definition across multiple files in the Airbyte CDK. The change allows for more flexible type mapping by enabling conditional logic through string values. The modification spans the schema definition, model classes, component factory, and dynamic schema loader, enhancing the ability to define context-sensitive type transformations.

Changes

File Change Summary
airbyte_cdk/sources/declarative/declarative_component_schema.yaml Added condition property to TypesMap as a string type with interpolation_context for raw_schema.
airbyte_cdk/sources/declarative/models/declarative_component_schema.py Added optional condition field to TypesMap and RecordFilter classes, both defined as Optional[str].
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py Updated create_types_map method to include condition parameter in the returned TypesMap object.
airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py Modified type replacement logic to evaluate condition using InterpolatedBoolean and updated method signatures accordingly.
unit_tests/sources/declarative/schema/test_dynamic_schema_loader.py Added new test function test_dynamic_schema_loader_with_type_conditions to validate the handling of type conditions.

Sequence Diagram

sequenceDiagram
    participant Factory as ModelToComponentFactory
    participant SchemaLoader as DynamicSchemaLoader
    participant TypesMap as TypesMap

    Factory->>TypesMap: Create with condition
    TypesMap-->>Factory: TypesMap instance
    SchemaLoader->>TypesMap: Evaluate condition
    TypesMap-->>SchemaLoader: Condition result
    SchemaLoader->>SchemaLoader: Replace type if condition is true
Loading

Possibly related PRs

Suggested reviewers

  • maxi297
  • aldogonzalez8

Hey there! Quick question - wdyt about how the new condition property adds some extra flexibility to type mapping? I'm curious to hear your thoughts on how this might be useful in different scenarios. 🤔


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.

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: 2

🔭 Outside diff range comments (1)
airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (1)

Line range hint 6-21: Would you mind sorting the imports to fix the linter error?

The linter reports an error (Ruff I001) indicating that the import block is un-sorted or un-formatted. Sorting the imports should resolve this issue. You can run the linter with the --fix option to automatically sort the imports. wdyt?

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

1766-1771: LGTM! The schema definition is well-structured.

The addition of the condition property to TypesMap is well-defined with:

  • Support for both string and boolean values through anyOf
  • Proper interpolation context for raw_schema

What do you think about adding some examples to help users understand how to use the condition property effectively? Something like:

examples:
  - "{{ raw_schema['type'] == 'string' }}"
  - true
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 40a9f1e and eef9b56.

📒 Files selected for processing (5)
  • airbyte_cdk/sources/declarative/declarative_component_schema.yaml (1 hunks)
  • airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1 hunks)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (1 hunks)
  • airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (4 hunks)
  • unit_tests/sources/declarative/schema/test_dynamic_schema_loader.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Linters
airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py

[error] 6-21: Import block is un-sorted or un-formatted (Ruff I001). This can be fixed automatically using the --fix option.

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-the-guardian-api' (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: Analyze (python)
🔇 Additional comments (2)
airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1)

702-702: Addition of condition attribute looks good.

The condition attribute in TypesMap enhances flexibility. Good addition!

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (1)

1689-1693: LGTM! The implementation looks clean and handles the default case well.

The changes to create_types_map method look good. I particularly like how you've handled the default case by setting condition=True when model.condition is None. This maintains backward compatibility while adding the new 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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eef9b56 and 595bcec.

📒 Files selected for processing (1)
  • airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (4 hunks)
🧰 Additional context used
🪛 GitHub Actions: Linters
airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py

[error] 208-208: Argument "condition" to "InterpolatedBoolean" has incompatible type "str | bool | None"; expected "str"

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-the-guardian-api' (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)
🔇 Additional comments (4)
airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (4)

13-13: LGTM! The new import and TypesMap condition field look good.

The addition of the optional condition field to TypesMap aligns well with the PR objective of supporting conditional type mapping.

Also applies to: 57-57


182-182: LGTM! Good addition of raw_schema parameter.

The change properly propagates the schema context needed for condition evaluation.


199-201: LGTM! Method signature update looks good.

The addition of raw_schema parameter with proper type annotation maintains type safety.


208-210: Should we pass the actual config and parameters instead of empty dicts?

Currently, config and parameters are set to empty dictionaries when evaluating the InterpolatedBoolean condition. Passing the actual config and parameters might be necessary for correct interpolation. wdyt?

🧰 Tools
🪛 GitHub Actions: Linters

[error] 208-208: Argument "condition" to "InterpolatedBoolean" has incompatible type "str | bool | None"; expected "str"

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)

1766-1769: LGTM! Consider adding documentation for the condition property.

The addition of the condition property to TypesMap looks good. Would you like to add a description field to document its purpose and usage? For example:

      condition:
        type: string
+       description: Optional condition to evaluate against the raw schema to determine if the type mapping should be applied.
        interpolation_context:
          - raw_schema
airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (1)

208-214: LGTM! Consider adding error handling for condition evaluation.

The condition evaluation logic looks good. Would you like to add error handling for potential evaluation failures? For example:

  condition = InterpolatedBoolean(
      condition=types_map.condition if types_map.condition is not None else "true",
      parameters={},
+ ).eval(config=self.config, raw_schema=raw_schema)
- ).eval(config=self.config, raw_schema=raw_schema)
+ except Exception as e:
+     logger.warning(f"Failed to evaluate condition: {e}. Defaulting to True.")
+     condition = True
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3293d03 and 3ac51d5.

📒 Files selected for processing (3)
  • airbyte_cdk/sources/declarative/declarative_component_schema.yaml (1 hunks)
  • airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1 hunks)
  • airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-the-guardian-api' (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)
🔇 Additional comments (3)
airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (2)

13-13: LGTM! Import added for new functionality.

The import of InterpolatedBoolean is required for the condition evaluation feature.


57-57: LGTM! Field matches schema definition.

The condition field is correctly defined as Optional[str], matching the schema definition.

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

702-702: LGTM! Field matches schema definition.

The condition field is correctly defined as Optional[str], maintaining consistency with the schema.

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

713-713: LGTM! Consider adding field documentation?

The addition of the optional condition field to TypesMap looks good and aligns with the PR objective of handling complex type determination scenarios. Would you like to add some documentation using Field(..., description="...") to clarify its purpose and provide usage examples? wdyt?

Here's a suggestion for the field definition:

-    condition: Optional[str]
+    condition: Optional[str] = Field(
+        None,
+        description="Optional condition to evaluate when determining if this type mapping should be applied. Useful when the type depends on additional fields beyond just the 'type' field.",
+        examples=['{{ raw_schema["type"] == "formula" and raw_schema["result_type"] == "number" }}'],
+        title="Type Mapping Condition"
+    )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ac51d5 and b189655.

📒 Files selected for processing (3)
  • airbyte_cdk/sources/declarative/declarative_component_schema.yaml (1 hunks)
  • airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1 hunks)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • airbyte_cdk/sources/declarative/declarative_component_schema.yaml
  • 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-the-guardian-api' (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: Pytest (Fast)
  • GitHub Check: Analyze (python)

Copy link
Contributor

@lazebnyi lazebnyi left a comment

Choose a reason for hiding this comment

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

lgtm

@darynaishchenko darynaishchenko merged commit c55fbbe into main Jan 16, 2025
19 checks passed
@darynaishchenko darynaishchenko deleted the daryna/low-code/add-conditions-to-schema-type-map branch January 16, 2025 17:34
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