Skip to content

feat(low-code): add default type to dynamic schema loader#335

Closed
Daryna Ishchenko (darynaishchenko) wants to merge 3 commits intomainfrom
daryna/add-default-type-to-DynamicSchemaLoader
Closed

feat(low-code): add default type to dynamic schema loader#335
Daryna Ishchenko (darynaishchenko) wants to merge 3 commits intomainfrom
daryna/add-default-type-to-DynamicSchemaLoader

Conversation

@darynaishchenko
Copy link
Contributor

@darynaishchenko Daryna Ishchenko (darynaishchenko) commented Feb 13, 2025

What

For source airtable we already have types mapping, but airtable also have types that "unknown" and python airtable version handled it as strings. but Dynamic Schema loader fails with value error if type of field not in airbyte types map or in schema identifier types map.

How

Added default_type to schema_type_identifier, When provided default type will be used if field not it airbyte types map or in schema identifier types map.

Summary by CodeRabbit

  • New Features

    • Enhanced schema definitions with a fallback default type. Fields without a matching type now use a predefined default, improving data consistency and accuracy.
  • Tests

    • Added new tests to validate that the fallback mechanism correctly applies the default type during schema processing.

@darynaishchenko
Copy link
Contributor Author

Daryna Ishchenko (darynaishchenko) commented Feb 13, 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.

@github-actions github-actions bot added the enhancement New feature or request label Feb 13, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

📝 Walkthrough

Walkthrough

The pull request introduces a new optional default_type property to the SchemaTypeIdentifier definition across several components. This addition provides a fallback mechanism when a field type is not found in the types mapping. Changes were made to the YAML schema file, the related Python model class, the component factory method, and the dynamic schema loader’s type replacement logic. A new unit test has also been added to verify the behavior of this default type handling. wdyt?

Changes

File(s) Change Summary
airbyte_cdk/sources/declarative/.../declarative_component_schema.yaml
airbyte_cdk/sources/declarative/.../declarative_component_schema.py
Added a new default_type property/field in the SchemaTypeIdentifier definition with an associated title and description.
airbyte_cdk/sources/declarative/.../parsers/model_to_component_factory.py Updated the create_schema_type_identifier method to handle the default_type parameter from the model.
airbyte_cdk/sources/declarative/.../dynamic_schema_loader.py Introduced an optional default_type attribute in SchemaTypeIdentifier and modified _replace_type_if_not_valid to return the default_type if the field type is not in AIRBYTE_DATA_TYPES.
unit_tests/sources/declarative/.../test_dynamic_schema_loader.py Added a new test function (test_dynamic_schema_loader_with_default_type) to validate that the dynamic schema loader uses the default_type appropriately.

Sequence Diagram(s)

sequenceDiagram
    participant MCF as ModelToComponentFactory
    participant STI as SchemaTypeIdentifier
    participant DSL as DynamicSchemaLoader

    MCF->>STI: Create identifier (with default_type if provided)
    STI-->>MCF: Return identifier object
    MCF->>DSL: Pass identifier for schema resolution
    DSL->>DSL: Check if field type is in AIRBYTE_DATA_TYPES
    alt Field type is invalid
        DSL->>STI: Return default_type (if defined)
    else Field type is valid
        DSL->>STI: Return original field type
    end
Loading

Does this diagram capture the updated control flow clearly, wdyt?

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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

🧹 Nitpick comments (3)
airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (1)

256-258: Consider optimizing the default type check.

The current implementation checks if the field_type is not in AIRBYTE_DATA_TYPES after the types_mapping check. What do you think about combining these checks to avoid multiple lookups? wdyt?

-        if self.schema_type_identifier.default_type and field_type not in AIRBYTE_DATA_TYPES:
+        if field_type not in AIRBYTE_DATA_TYPES and self.schema_type_identifier.default_type:
             return self.schema_type_identifier.default_type
         return field_type
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (1)

2048-2055: LGTM! The default_type parameter is correctly added.

The implementation looks good and aligns with the PR objectives. The default_type is properly passed to the SchemaTypeIdentifier constructor with a fallback to None if not provided.

One small suggestion: Would you consider adding a docstring to explain the purpose of the default_type parameter and when it should be used? This would help future developers understand its role in schema type identification, wdyt?

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

2050-2053: LGTM! The new default_type property is well-defined.

The addition of the default_type property with clear title and description aligns well with the PR objectives to handle unknown types from Airtable. The property is appropriately defined as an optional string field.

Just a thought - would it make sense to add some examples of common default types (like "string") in the schema definition to help guide users? wdyt?

       default_type:
         title: Default Type
         description: Default to be set if field type wasn't found in the types_mapping.
         type: string
+        examples:
+          - "string"
+          - "integer"
+          - "boolean"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 522caab and a1a3cab.

📒 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 (2 hunks)
  • unit_tests/sources/declarative/schema/test_dynamic_schema_loader.py (1 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 (All, Python 3.10, Ubuntu)
  • GitHub Check: Pytest (Fast)
🔇 Additional comments (3)
airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (1)

90-90: LGTM! Nice addition of the default_type field.

The optional default_type field provides a good fallback mechanism for handling unknown field types.

unit_tests/sources/declarative/schema/test_dynamic_schema_loader.py (1)

408-475: Great test coverage!

The test thoroughly validates the default_type behavior across different scenarios:

  1. Unknown type defaulting to string
  2. Type in types map but condition is False
  3. Airbyte type handling
  4. Multiple records with different types
airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1)

815-819: LGTM! Well-documented model field.

The default_type field is properly added to the model with clear description and title.

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