-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[low-code] Propagate options to InterpolatedRequestInputProvider #18050
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2f26c50
properly propagate options
girarda 25fa471
cleanup
girarda 0301d90
turn into dataclass
girarda 4700f73
rename
girarda 66ce614
no need for deepcopy
girarda 404ea2b
Merge branch 'master' into alex/request_params_options
girarda 9309252
fix test
girarda 919d87c
Merge branch 'master' into alex/request_params_options
girarda f379756
bump
girarda 6a3d084
cleaner
girarda 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,37 +2,38 @@ | |
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from dataclasses import InitVar, dataclass, field | ||
from typing import Any, Mapping, Optional, Union | ||
|
||
from airbyte_cdk.sources.declarative.interpolation.interpolated_mapping import InterpolatedMapping | ||
from airbyte_cdk.sources.declarative.interpolation.interpolated_string import InterpolatedString | ||
from airbyte_cdk.sources.declarative.types import Config, StreamSlice, StreamState | ||
|
||
|
||
@dataclass | ||
class InterpolatedRequestInputProvider: | ||
""" | ||
Helper class that generically performs string interpolation on the provided dictionary or string input | ||
""" | ||
|
||
def __init__( | ||
self, *, config: Config, request_inputs: Optional[Union[str, Mapping[str, str]]] = None, **options: Optional[Mapping[str, Any]] | ||
): | ||
""" | ||
:param config: The user-provided configuration as specified by the source's spec | ||
:param request_inputs: The dictionary to interpolate | ||
:param options: Additional runtime parameters to be used for string interpolation | ||
""" | ||
options: InitVar[Mapping[str, Any]] | ||
request_inputs: Optional[Union[str, Mapping[str, str]]] = field(default=None) | ||
config: Config = field(default_factory=dict) | ||
_interpolator: Union[InterpolatedString, InterpolatedMapping] = field(init=False, repr=False, default=None) | ||
_request_inputs: Union[str, Mapping[str, str]] = field(init=False, repr=False, default=None) | ||
|
||
self._config = config | ||
def __post_init__(self, options: Mapping[str, Any]): | ||
|
||
if request_inputs is None: | ||
request_inputs = {} | ||
if isinstance(request_inputs, str): | ||
self._interpolator = InterpolatedString(request_inputs, default="", options=options) | ||
if self.request_inputs is 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. can this just be simplified to |
||
self._request_inputs = {} | ||
else: | ||
self._request_inputs = self.request_inputs | ||
if isinstance(self.request_inputs, str): | ||
self._interpolator = InterpolatedString(self.request_inputs, default="", options=options) | ||
else: | ||
self._interpolator = InterpolatedMapping(request_inputs, options=options) | ||
self._interpolator = InterpolatedMapping(self._request_inputs, options=options) | ||
|
||
def request_inputs( | ||
def eval_request_inputs( | ||
self, stream_state: StreamState, stream_slice: Optional[StreamSlice] = None, next_page_token: Mapping[str, Any] = None | ||
) -> Mapping[str, Any]: | ||
""" | ||
|
@@ -44,7 +45,7 @@ def request_inputs( | |
:return: The request inputs to set on an outgoing HTTP request | ||
""" | ||
kwargs = {"stream_state": stream_state, "stream_slice": stream_slice, "next_page_token": next_page_token} | ||
interpolated_value = self._interpolator.eval(self._config, **kwargs) | ||
interpolated_value = self._interpolator.eval(self.config, **kwargs) | ||
|
||
if isinstance(interpolated_value, dict): | ||
non_null_tokens = {k: v for k, v in interpolated_value.items() if v} | ||
|
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
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.
this class isn't exposed in the DSL, but I still abstained from modifying the name of the parameters. I chose to rename the method instead