-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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 connectors] default types and default values #14004
Changes from all commits
642a727
0ce6b37
13262b1
c77626b
e51602a
f0240b1
9b83138
35d3def
c0427ff
d724000
4bd51a1
4fcf7ce
b2d734f
9a38dae
3b74432
4fac829
0f7c21c
4c2524d
0da87b3
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from typing import Mapping, Type | ||
|
||
from airbyte_cdk.sources.declarative.requesters.paginators.interpolated_paginator import InterpolatedPaginator | ||
from airbyte_cdk.sources.declarative.requesters.paginators.next_page_url_paginator import NextPageUrlPaginator | ||
from airbyte_cdk.sources.declarative.requesters.paginators.offset_paginator import OffsetPaginator | ||
from airbyte_cdk.sources.streams.http.requests_native_auth.token import TokenAuthenticator | ||
|
||
CLASS_TYPES_REGISTRY: Mapping[str, Type] = { | ||
"NextPageUrlPaginator": NextPageUrlPaginator, | ||
"InterpolatedPaginator": InterpolatedPaginator, | ||
"OffsetPaginator": OffsetPaginator, | ||
"TokenAuthenticator": TokenAuthenticator, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from typing import Mapping, Type | ||
|
||
from airbyte_cdk.sources.declarative.checks.check_stream import CheckStream | ||
from airbyte_cdk.sources.declarative.checks.connection_checker import ConnectionChecker | ||
from airbyte_cdk.sources.declarative.decoders.decoder import Decoder | ||
from airbyte_cdk.sources.declarative.decoders.json_decoder import JsonDecoder | ||
from airbyte_cdk.sources.declarative.extractors.http_selector import HttpSelector | ||
from airbyte_cdk.sources.declarative.extractors.jello import JelloExtractor | ||
from airbyte_cdk.sources.declarative.extractors.record_selector import RecordSelector | ||
from airbyte_cdk.sources.declarative.requesters.http_requester import HttpRequester | ||
from airbyte_cdk.sources.declarative.requesters.requester import Requester | ||
from airbyte_cdk.sources.declarative.requesters.retriers.default_retrier import DefaultRetrier | ||
from airbyte_cdk.sources.declarative.requesters.retriers.retrier import Retrier | ||
from airbyte_cdk.sources.declarative.retrievers.retriever import Retriever | ||
from airbyte_cdk.sources.declarative.retrievers.simple_retriever import SimpleRetriever | ||
from airbyte_cdk.sources.declarative.schema.json_schema import JsonSchema | ||
from airbyte_cdk.sources.declarative.schema.schema_loader import SchemaLoader | ||
|
||
DEFAULT_IMPLEMENTATIONS_REGISTRY: Mapping[Type, Type] = { | ||
Requester: HttpRequester, | ||
Retriever: SimpleRetriever, | ||
SchemaLoader: JsonSchema, | ||
HttpSelector: RecordSelector, | ||
ConnectionChecker: CheckStream, | ||
Retrier: DefaultRetrier, | ||
Decoder: JsonDecoder, | ||
JelloExtractor: JelloExtractor, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,17 @@ | |
|
||
import requests | ||
from airbyte_cdk.sources.declarative.decoders.decoder import Decoder | ||
from airbyte_cdk.sources.declarative.decoders.json_decoder import JsonDecoder | ||
from airbyte_cdk.sources.declarative.interpolation.interpolated_mapping import InterpolatedMapping | ||
from airbyte_cdk.sources.declarative.interpolation.jinja import JinjaInterpolation | ||
from airbyte_cdk.sources.declarative.requesters.paginators.paginator import Paginator | ||
from airbyte_cdk.sources.declarative.types import Config | ||
|
||
|
||
class InterpolatedPaginator(Paginator): | ||
def __init__(self, next_page_token_template: Mapping[str, str], decoder: Decoder, config): | ||
def __init__(self, *, next_page_token_template: Mapping[str, str], config: Config, decoder: Optional[Decoder] = 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. add type annotations and force the parameters to be passed by names to avoid accidentally mixing up the next_page_token_template and the config |
||
self._next_page_token_template = InterpolatedMapping(next_page_token_template, JinjaInterpolation()) | ||
self._decoder = decoder | ||
self._decoder = decoder or JsonDecoder() | ||
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. set default |
||
self._config = config | ||
|
||
def next_page_token(self, response: requests.Response, last_records: List[Mapping[str, Any]]) -> Optional[Mapping[str, Any]]: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,29 @@ | |
import requests | ||
from airbyte_cdk.sources.declarative.requesters.paginators.interpolated_paginator import InterpolatedPaginator | ||
from airbyte_cdk.sources.declarative.requesters.paginators.paginator import Paginator | ||
from airbyte_cdk.sources.declarative.types import Config | ||
|
||
|
||
class NextPageUrlPaginator(Paginator): | ||
def __init__(self, url_base: str = None, interpolated_paginator: InterpolatedPaginator = None, kwargs=None): | ||
if kwargs is None: | ||
kwargs = dict() | ||
self._url_base = url_base or kwargs.get("url_base") | ||
self._interpolated_paginator = interpolated_paginator or kwargs.get("interpolated_paginator") | ||
""" | ||
A paginator wrapper that delegates to an inner paginator and removes the base url from the next_page_token to only return the path to the next page | ||
""" | ||
|
||
def __init__( | ||
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. removed unused kwargs parameter |
||
self, | ||
url_base: str = None, | ||
next_page_token_template: Optional[Mapping[str, str]] = 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. either interpolated_paginator or next_page_token_template is expected. Passing
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. What if we did away with And this class itself will get simpler w/o needing to check for one or the other and error handling |
||
config: Optional[Config] = None, | ||
): | ||
""" | ||
:param url_base: url base to remove from the token | ||
:param interpolated_paginator: optional paginator to delegate to | ||
:param next_page_token_template: optional mapping to delegate to if interpolated_paginator is None | ||
:param config: connection config | ||
""" | ||
|
||
self._url_base = url_base | ||
self._interpolated_paginator = InterpolatedPaginator(next_page_token_template=next_page_token_template, config=config) | ||
|
||
def next_page_token(self, response: requests.Response, last_records: List[Mapping[str, Any]]) -> Optional[Mapping[str, Any]]: | ||
next_page_token = self._interpolated_paginator.next_page_token(response, last_records) | ||
|
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.
the code here looks good, but I will say that it is pretty complicated to understand. Even though it's a private method, I think a method header going over the different ways a subcomponent variations that are supported like class_name, dict, list, type -> class_name, or inference. Without your summary at the beginning of your PR, I would have been pretty lost. And we'll lose that once the PR is merged and not part of the code.