-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
instantiate a declarative connector and allow for reads to be invoked…
… from the connector builder server (#19333) * instantiate a declarative connector and allow for reads to be invoked from the connector builder server * various pr feedback and cleaning up the code a bit * refactor grouping logic into a separate function to illustrate how groups are being emitted * fix the webapp to also pass config to the stream list endpoint * fix dereference field * replace error message handling with default FastAPI HTTPException * pr feedback: more error messaging and some code reuse * formatting * regenerate open api spec
- Loading branch information
Showing
11 changed files
with
876 additions
and
9 deletions.
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
30 changes: 30 additions & 0 deletions
30
...nnector-builder-server/connector_builder/generated/models/stream_read_slice_descriptor.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,30 @@ | ||
# | ||
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
# coding: utf-8 | ||
|
||
from __future__ import annotations | ||
from datetime import date, datetime # noqa: F401 | ||
|
||
import re # noqa: F401 | ||
from typing import Any, Dict, List, Optional # noqa: F401 | ||
|
||
from pydantic import AnyUrl, BaseModel, EmailStr, validator # noqa: F401 | ||
|
||
|
||
class StreamReadSliceDescriptor(BaseModel): | ||
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
Do not edit the class manually. | ||
StreamReadSliceDescriptor - a model defined in OpenAPI | ||
start_datetime: The start_datetime of this StreamReadSliceDescriptor [Optional]. | ||
list_item: The list_item of this StreamReadSliceDescriptor [Optional]. | ||
""" | ||
|
||
start_datetime: Optional[datetime] = None | ||
list_item: Optional[str] = None | ||
|
||
StreamReadSliceDescriptor.update_forward_refs() |
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
49 changes: 49 additions & 0 deletions
49
airbyte-connector-builder-server/connector_builder/impl/low_code_cdk_adapter.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,49 @@ | ||
# | ||
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from typing import Any, Dict, Iterable, List | ||
|
||
from airbyte_cdk.models import AirbyteMessage, ConfiguredAirbyteCatalog | ||
from airbyte_cdk.sources.declarative.declarative_stream import DeclarativeStream | ||
from airbyte_cdk.sources.declarative.yaml_declarative_source import ManifestDeclarativeSource | ||
from airbyte_cdk.sources.streams.http import HttpStream | ||
|
||
|
||
class LowCodeSourceAdapter: | ||
def __init__(self, manifest: Dict[str, Any]): | ||
# Request and response messages are only emitted for a sources that have debug turned on | ||
self._source = ManifestDeclarativeSource(manifest, debug=True) | ||
|
||
def get_http_streams(self, config: Dict[str, Any]) -> List[HttpStream]: | ||
http_streams = [] | ||
for stream in self._source.streams(config=config): | ||
if isinstance(stream, DeclarativeStream): | ||
if isinstance(stream.retriever, HttpStream): | ||
http_streams.append(stream.retriever) | ||
else: | ||
raise TypeError( | ||
f"A declarative stream should only have a retriever of type HttpStream, but received: {stream.retriever.__class__}") | ||
else: | ||
raise TypeError(f"A declarative source should only contain streams of type DeclarativeStream, but received: {stream.__class__}") | ||
return http_streams | ||
|
||
def read_stream(self, stream: str, config: Dict[str, Any]) -> Iterable[AirbyteMessage]: | ||
configured_catalog = ConfiguredAirbyteCatalog.parse_obj( | ||
{ | ||
"streams": [ | ||
{ | ||
"stream": { | ||
"name": stream, | ||
"json_schema": {}, | ||
"supported_sync_modes": ["full_refresh", "incremental"], | ||
}, | ||
"sync_mode": "full_refresh", | ||
"destination_sync_mode": "overwrite", | ||
} | ||
] | ||
} | ||
) | ||
generator = self._source.read(logger=self._source.logger, config=config, catalog=configured_catalog) | ||
for message in generator: | ||
yield message |
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.