Skip to content

feat(cdk): add schema filter to DynamicSchemaLoader #550

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

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

Conversation

lazebnyi
Copy link
Contributor

@lazebnyi lazebnyi commented May 17, 2025

What

Resolved: https://github.com/airbytehq/airbyte-internal-issues/issues/13045

In some cases, when using the dynamic schema loader endpoint, the provider may return all possible fields that could be present. To keep the schema up to date and ensure that the properties section only includes the fields that were actually requested, we need to filter the returned values accordingly.

How

Added filtering behavior to the schema loader using the schema_filter.

⚠️ UNIT TESTS TO BE ADDED LATER

Summary by CodeRabbit

  • New Features

    • Added the ability to filter fields included in dynamically loaded schemas using a new schema filter option. This allows for more precise control over which fields are present in generated schemas.
  • Documentation

    • Improved descriptions for schema loader configuration to clarify merging behavior when multiple schema loaders are used.

@github-actions github-actions bot added the enhancement New feature or request label May 17, 2025
@lazebnyi
Copy link
Contributor Author

lazebnyi commented May 17, 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 May 17, 2025

Warning

Rate limit exceeded

@lazebnyi has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 29 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 3961f6c and 86f7176.

📒 Files selected for processing (3)
  • airbyte_cdk/sources/declarative/models/declarative_component_schema.py (2 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

The changes introduce a new optional schema_filter property to the DynamicSchemaLoader component, allowing selective filtering of schema fields. Corresponding updates were made to the schema definitions, models, component factory, and the loader's logic. Additionally, a create_or_update flag was added to component mapping dataclasses.

Changes

File(s) Change Summary
airbyte_cdk/sources/declarative/declarative_component_schema.yaml Added optional schema_filter property to DynamicSchemaLoader definition, accepting RecordFilter or CustomRecordFilter.
airbyte_cdk/sources/declarative/models/declarative_component_schema.py Updated schema_loader field description in DeclarativeStream; added optional schema_filter field to DynamicSchemaLoader.
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py Modified create_dynamic_schema_loader to construct and pass schema_filter to DynamicSchemaLoader if present in the model.
airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py Added optional schema_filter attribute and _filter method to DynamicSchemaLoader; updated get_json_schema to filter properties before transformation.
airbyte_cdk/sources/declarative/resolvers/components_resolver.py Added optional boolean field create_or_update (default False) to ComponentMappingDefinition and ResolvedComponentMappingDefinition dataclasses.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DeclarativeStream
    participant DynamicSchemaLoader
    participant RecordFilter

    User->>DeclarativeStream: Request schema
    DeclarativeStream->>DynamicSchemaLoader: get_json_schema()
    DynamicSchemaLoader->>DynamicSchemaLoader: Extract schema properties
    alt schema_filter is set
        DynamicSchemaLoader->>RecordFilter: filter_records(properties)
        RecordFilter-->>DynamicSchemaLoader: Filtered properties
    else schema_filter not set
        DynamicSchemaLoader->>DynamicSchemaLoader: Use all properties
    end
    DynamicSchemaLoader->>DynamicSchemaLoader: Apply schema transformations
    DynamicSchemaLoader-->>DeclarativeStream: Return filtered/transformed schema
Loading

Would you like to see a diagram comparing the old and new flows for clarity, or is this high-level overview sufficient for your needs? 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: 2

🧹 Nitpick comments (2)
airbyte_cdk/sources/declarative/resolvers/components_resolver.py (1)

25-25: Introduce create_or_update flag in ComponentMappingDefinition
Great to see a control flag added for mapping behavior! Should we simplify the annotation to create_or_update: bool = False instead of Optional[bool], since the default is always False? wdyt?

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

2417-2419: The schema_filter description needs improvement, wdyt?

The description is currently just a placeholder ("placeholder"). Consider providing a more informative description that explains the purpose of this field, similar to how other filter fields are documented in this file.

-    schema_filter: Optional[Union[RecordFilter, CustomRecordFilter]] = Field(
-        None, description="placeholder", title="Schema Filter"
-    )
+    schema_filter: Optional[Union[RecordFilter, CustomRecordFilter]] = Field(
+        None, 
+        description="Filter applied to schema properties during schema generation. Properties will be included only if they satisfy the filter condition.",
+        title="Schema Filter"
+    )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between fa8d54d and 3961f6c.

📒 Files selected for processing (5)
  • airbyte_cdk/sources/declarative/declarative_component_schema.yaml (1 hunks)
  • airbyte_cdk/sources/declarative/models/declarative_component_schema.py (2 hunks)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (1 hunks)
  • airbyte_cdk/sources/declarative/resolvers/components_resolver.py (2 hunks)
  • airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1)
airbyte_cdk/sources/declarative/extractors/record_filter.py (1)
  • RecordFilter (17-49)
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (2)
airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (1)
  • DynamicSchemaLoader (120-300)
airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1)
  • DynamicSchemaLoader (2410-2439)
🪛 GitHub Actions: Linters
airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py

[error] 183-183: mypy error: Need type annotation for "filtered_properties" (hint: "filtered_properties: dict[, ] = ...") [var-annotated]

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

[error] 2436-2436: mypy error: Argument 1 to "_create_component_from_model" of "ModelToComponentFactory" has incompatible type "RecordFilter | CustomRecordFilter | None"; expected "BaseModel" [arg-type]

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
🔇 Additional comments (7)
airbyte_cdk/sources/declarative/resolvers/components_resolver.py (1)

38-38: Mirror create_or_update in ResolvedComponentMappingDefinition
Nice consistency between the definition and its resolved counterpart. Could you verify that downstream logic (e.g., in the component factory or resolver implementations) properly consumes this new flag? wdyt?

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

2321-2326: Add optional schema_filter to DynamicSchemaLoader schema
This looks like a solid enhancement for selective field inclusion. Can you confirm that omitting schema_filter still results in the expected “no filter” behavior and that it’s correctly wired in the loader implementation? wdyt?

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

2167-2168: Good improvement to the schema loader description

The updated description now clearly explains what happens when multiple schema loaders are used in a declarative stream, particularly that properties will be merged with precedence given to loaders defined earlier in the list.

airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py (4)

13-13: Appropriate import addition

The import for RecordFilter is correctly added and needed for the new schema filtering functionality.


130-130: Good addition of the schema_filter parameter

The optional schema_filter parameter is correctly added to the DynamicSchemaLoader class.


156-156: Correct application of filtering before transformation

The get_json_schema method now correctly applies filtering before transformation, which is the appropriate order.


183-189: Consider empty stream state for filter_records, wdyt?

The filter_records method is called with an empty dictionary as the stream_state. Is this intentional? If a more appropriate state should be used, consider passing it.

Given that this is a schema filtering context rather than a normal data stream context, is passing an empty dictionary for stream_state appropriate for your use case? This might be fine if schema filtering doesn't need stream state information, but it's worth confirming.

🧰 Tools
🪛 GitHub Actions: Linters

[error] 183-183: mypy error: Need type annotation for "filtered_properties" (hint: "filtered_properties: dict[, ] = ...") [var-annotated]

@lazebnyi
Copy link
Contributor Author

lazebnyi commented May 17, 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.

@lazebnyi lazebnyi requested review from bnchrch and brianjlai May 17, 2025 02:50
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