-
Notifications
You must be signed in to change notification settings - Fork 6
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: add CustomSchemaNormalization
#194
Open
artem1205
wants to merge
9
commits into
main
Choose a base branch
from
artem1205/add-custom-type-transformer
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
9 commits
Select commit
Hold shift + click to select a range
3984559
CDK: add custom type transformer
artem1205 2433340
CDK: ref
artem1205 9bdfb73
CDK: fix
artem1205 c9202e5
CDK: fix typo
artem1205 26b99bf
CDK: fix schema
artem1205 8db550a
CDK: reorder definition declaration
artem1205 4f64a45
CDK: ref
artem1205 e7a6c0c
CDK: fix tests
artem1205 f787b6d
CDK: add AbstractTypeTransformer
artem1205 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 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
This file contains 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
This file contains 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
55 changes: 55 additions & 0 deletions
55
airbyte_cdk/sources/declarative/extractors/type_transformer.py
This file contains 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,55 @@ | ||
# | ||
# Copyright (c) 2025 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from abc import ABC, abstractmethod | ||
from dataclasses import dataclass | ||
from typing import Any, Dict, Mapping | ||
|
||
|
||
@dataclass | ||
class AbstractTypeTransformer(ABC): | ||
""" | ||
Abstract base class for implementing type transformation logic. | ||
|
||
This class provides a blueprint for defining custom transformations | ||
on data records based on a provided schema. Implementing classes | ||
must override the `transform` method to specify the transformation | ||
logic. | ||
|
||
Attributes: | ||
None explicitly defined, as this is a dataclass intended to be | ||
subclassed. | ||
|
||
Methods: | ||
transform(record: Dict[str, Any], schema: Mapping[str, Any]) -> None: | ||
Abstract method that must be implemented by subclasses. | ||
It performs a transformation on a given data record based | ||
on the provided schema. | ||
|
||
Usage: | ||
To use this class, create a subclass that implements the | ||
`transform` method with the desired transformation logic. | ||
""" | ||
|
||
@abstractmethod | ||
def transform( | ||
self, | ||
record: Dict[str, Any], | ||
schema: Mapping[str, Any], | ||
) -> None: | ||
""" | ||
Perform a transformation on a data record based on a given schema. | ||
|
||
Args: | ||
record (Dict[str, Any]): The data record to be transformed. | ||
schema (Mapping[str, Any]): The schema that dictates how | ||
the record should be transformed. | ||
|
||
Returns: | ||
None | ||
|
||
Raises: | ||
NotImplementedError: If the method is not implemented | ||
by a subclass. | ||
""" |
This file contains 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
This file contains 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
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.
Presumably this
CustomNormalization
component would need to already adhere or inherit from theTypeTransformer
interface/class?And that's why we don't need to invoke the
TypeTransformer
constructor?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.
yes, most of the time we use
customtypetransformer
by registration some custom function, but generally speaking we need onlytransform
interface, I can add abstract class for thisairbyte-python-cdk/airbyte_cdk/sources/declarative/extractors/record_selector.py
Lines 110 to 116 in 3984559
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.
Yeah I think we need to create an interface in the declarative package for this. I don't think we want users to be re-implementing
TypeTransformer
for a couple reasons:So we should just create a new TypeTransformer interface in low-code (i'll leave naming to you), and then I think
RecordSelector.schema_normalization
will need to be changed to a union of these two classes interfaces. Once we have these added will 👍 the PR. thanks for making the other adjustments!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.
added AbstractTypeTransformer