-
Notifications
You must be signed in to change notification settings - Fork 30
chore(low code): refactor model to component factory #673
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
darynaishchenko
wants to merge
24
commits into
main
Choose a base branch
from
daryna/low-code/refactor-model-to-component-factory
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b878987
added ComponentConstructor class
darynaishchenko 0c27b96
updated model_to_component.py, set up RecordFilter with resolve_depen…
darynaishchenko 2d8129b
Auto-fix lint and format issues
e1a4e7e
fix mypy
darynaishchenko 2b569f5
added check for function
darynaishchenko bd551fc
fix typo in error message
darynaishchenko 01d2f87
added AdditionalFlags to ComponentConstructor
darynaishchenko fafab4d
added ComponentConstructor to QueryProperties
darynaishchenko 57706a7
updated RecordFilter
darynaishchenko bc4a36f
updated ModelToComponent
darynaishchenko ba33479
updated SimpleRetriever with ComponentConstructor
darynaishchenko 3cdd426
Auto-fix lint and format issues
06e05b9
updated check for name
darynaishchenko 7d06719
fix unit tests
darynaishchenko 218dabb
Auto-fix lint and format issues
b212ed9
fix mypy
darynaishchenko 2d4fdae
Merge branch 'main' into daryna/low-code/refactor-model-to-component-…
darynaishchenko b9e26bd
updated simple retriever
darynaishchenko 1b02cdc
Auto-fix lint and format issues
3d48eb0
Merge branch 'main' into daryna/low-code/refactor-model-to-component-…
darynaishchenko 5e71790
deleted _json_schema_type_name_to_type from ComponentConstructor class
darynaishchenko cb93847
Merge branch 'main' into daryna/low-code/refactor-model-to-component-…
darynaishchenko 906d587
format fix
darynaishchenko 2fca25a
fix imports
darynaishchenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
airbyte_cdk/sources/declarative/parsers/component_constructor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# | ||
# Copyright (c) 2025 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from dataclasses import dataclass | ||
from typing import Any, Callable, Generic, Mapping, Optional, Type, TypeVar | ||
|
||
from pydantic.v1 import BaseModel | ||
|
||
from airbyte_cdk.sources.connector_state_manager import ConnectorStateManager | ||
from airbyte_cdk.sources.declarative.models.declarative_component_schema import ValueType | ||
from airbyte_cdk.sources.message import MessageRepository | ||
from airbyte_cdk.sources.types import Config | ||
|
||
M = TypeVar("M", bound=BaseModel) | ||
|
||
|
||
@dataclass | ||
class AdditionalFlags: | ||
def __init__( | ||
self, | ||
emit_connector_builder_messages: bool, | ||
disable_retries: bool, | ||
message_repository: MessageRepository, | ||
connector_state_manager: ConnectorStateManager, | ||
limit_pages_fetched_per_slice: Optional[int], | ||
limit_slices_fetched: Optional[int], | ||
): | ||
self.emit_connector_builder_messages = emit_connector_builder_messages | ||
self.disable_retries = disable_retries | ||
self.message_repository = message_repository | ||
self.connector_state_manager = connector_state_manager | ||
self.limit_pages_fetched_per_slice = limit_pages_fetched_per_slice | ||
self.limit_slices_fetched = limit_slices_fetched | ||
|
||
@property | ||
def should_limit_slices_fetched(self) -> bool: | ||
""" | ||
Returns True if the number of slices fetched should be limited, False otherwise. | ||
This is used to limit the number of slices fetched during tests. | ||
""" | ||
return bool(self.limit_slices_fetched or self.emit_connector_builder_messages) | ||
|
||
|
||
@dataclass | ||
class ComponentConstructor(Generic[M]): | ||
@classmethod | ||
def resolve_dependencies( | ||
cls, | ||
model: M, | ||
config: Config, | ||
dependency_constructor: Callable[..., Any], | ||
additional_flags: AdditionalFlags, | ||
**kwargs: Any, | ||
) -> Mapping[str, Any]: | ||
""" | ||
Resolves the component's dependencies, this method should be created in the component, | ||
if there are any dependencies on other components, or we need to adopt / change / adjust / fine-tune | ||
specific component's behavior. | ||
""" | ||
return {} | ||
|
||
@classmethod | ||
def build( | ||
cls, | ||
model: M, | ||
config: Config, | ||
dependency_constructor: Callable[..., Any], | ||
additional_flags: AdditionalFlags, | ||
**kwargs: Any, | ||
) -> "ComponentConstructor[M]": | ||
""" | ||
Builds up the Component and it's component-specific dependencies. | ||
Order of operations: | ||
- build the dependencies first | ||
- build the component with the resolved dependencies | ||
""" | ||
|
||
# resolve the component dependencies first | ||
resolved_dependencies: Mapping[str, Any] = cls.resolve_dependencies( | ||
model=model, | ||
config=config, | ||
dependency_constructor=dependency_constructor, | ||
additional_flags=additional_flags, | ||
**kwargs, | ||
) | ||
|
||
# returns the instance of the component class, | ||
# with resolved dependencies and model-specific arguments. | ||
return cls(**resolved_dependencies) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to better understand the pattern: In an ideal world where this isn't a dataclass that exposes everything as public, would the logic of having the condition as
InterpolatedBoolean
be done inresolve_dependencies
or would we still have this in the init?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for now we will still have this in
__init__
just to have less thing to refactor and avoid missing something. But it's a good idea and I think we consider changing the place of interpolation here or in__init__