-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Airbyte CDK: add filter to RemoveFields #35326
Changes from all commits
50ab7db
9928b9d
c4627f5
ce1c48b
4d54221
efc0795
3fea6de
f6858cb
6b203af
d39119b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -579,6 +579,16 @@ class SchemaNormalization(Enum): | |
|
||
class RemoveFields(BaseModel): | ||
type: Literal['RemoveFields'] | ||
condition: Optional[str] = Field( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was this file modified manually? we should run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL, btw. |
||
'', | ||
description="The predicate to filter a property by a property value. Property will be removed if it is empty OR expression is evaluated to True.", | ||
examples=[ | ||
"{{ property|string == '' }}", | ||
'{{ property is integer }}', | ||
'{{ property|length > 5 }}', | ||
"{{ property == 'some_string_to_match' }}", | ||
], | ||
) | ||
field_pointers: List[List[str]] = Field( | ||
..., | ||
description='Array of paths defining the field to remove. Each item is an array whose field describe the path of a field to remove.', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -909,7 +909,7 @@ def create_record_selector( | |
|
||
@staticmethod | ||
def create_remove_fields(model: RemoveFieldsModel, config: Config, **kwargs: Any) -> RemoveFields: | ||
return RemoveFields(field_pointers=model.field_pointers, parameters={}) | ||
return RemoveFields(field_pointers=model.field_pointers, condition=model.condition or "", parameters={}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a unit test where condition is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
|
||
def create_selective_authenticator(self, model: SelectiveAuthenticatorModel, config: Config, **kwargs: Any) -> DeclarativeAuthenticator: | ||
authenticators = {name: self._create_component_from_model(model=auth, config=config) for name, auth in model.authenticators.items()} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import dpath.exceptions | ||
import dpath.util | ||
from airbyte_cdk.sources.declarative.interpolation.interpolated_boolean import InterpolatedBoolean | ||
from airbyte_cdk.sources.declarative.transformations import RecordTransformation | ||
from airbyte_cdk.sources.declarative.types import Config, FieldPointer, StreamSlice, StreamState | ||
|
||
|
@@ -40,6 +41,10 @@ class RemoveFields(RecordTransformation): | |
|
||
field_pointers: List[FieldPointer] | ||
parameters: InitVar[Mapping[str, Any]] | ||
condition: str = "" | ||
|
||
def __post_init__(self, parameters: Mapping[str, Any]) -> None: | ||
self._filter_interpolator = InterpolatedBoolean(condition=self.condition, parameters=parameters) | ||
|
||
def transform( | ||
self, | ||
|
@@ -55,7 +60,11 @@ def transform( | |
for pointer in self.field_pointers: | ||
# the dpath library by default doesn't delete fields from arrays | ||
try: | ||
dpath.util.delete(record, pointer) | ||
dpath.util.delete( | ||
artem1205 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
record, | ||
pointer, | ||
afilter=(lambda x: self._filter_interpolator.eval(config or {}, property=x)) if self.condition else None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's just what the parameter is called in the dpath library https://pypi.org/project/dpath/ |
||
) | ||
except dpath.exceptions.PathNotFound: | ||
# if the (potentially nested) property does not exist, silently skip | ||
pass | ||
|
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.
That seems like a docs mistake from previous things, right?
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, gradle
format
tast does not exist anymore.airbyte-ci format fix
should be used instead