-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
305 additions
and
120 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
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 |
---|---|---|
@@ -1,57 +1,88 @@ | ||
from gaianet_rag_api_pipeline.config import get_settings, Settings | ||
from gaianet_rag_api_pipeline.io.airbyte import AirbyteAPIConnector | ||
from gaianet_rag_api_pipeline.schema import BoardroomAPI # TODO: | ||
from gaianet_rag_api_pipeline.schema import PaginationSchemas | ||
|
||
import airbyte as ab | ||
import pathlib | ||
import pathway as pw | ||
import typing | ||
|
||
|
||
def input( | ||
def create_endpoint_stream( | ||
api_name: str, | ||
settings: Settings, | ||
cache_name: str, | ||
cache_dir: str, | ||
source_manifest: dict | pathlib.Path, | ||
stream_id: str, | ||
pagination_schema: PaginationSchemas, | ||
config: dict[str, typing.Any] | None = None, | ||
source_manifest: bool | dict | pathlib.Path | str = False, | ||
endpoint_text_fields: dict = dict(), | ||
streams: str | list[str] | None = None, | ||
force_full_refresh: bool = False | ||
): | ||
# settings = get_settings() | ||
# class InputSchema(pw.Schema): | ||
# value: int | ||
# format="json" | ||
# return pw.io.python.read( | ||
# InfiniteStream(), | ||
# schema=InputSchema, | ||
# format=format, | ||
# autocommit_duration_ms=get_settings().autocommit_duration_ms, | ||
# ) | ||
|
||
) -> pw.Table: | ||
cache = ab.caches.new_local_cache( | ||
cache_name=f"{api_name}_cache", | ||
cache_dir='./connector_cache', # NOTICE: parametrize | ||
cleanup=force_full_refresh # NOTICE: CLI param | ||
cache_name=cache_name, | ||
cache_dir=cache_dir, | ||
cleanup=force_full_refresh | ||
) | ||
|
||
api_connector = AirbyteAPIConnector( | ||
stream_connector = AirbyteAPIConnector( | ||
name=api_name, | ||
cache=cache, | ||
config=config, | ||
source_manifest=source_manifest, | ||
# streams="proposals", # NOTICE: doing just an individual stream | ||
streams=streams, | ||
force_full_refresh=force_full_refresh, # NOTICE: CLI param | ||
check_source=False, # NOTICE: enforce to not check manifest during initialization | ||
streams=stream_id, | ||
force_full_refresh=force_full_refresh, | ||
check_source=False, | ||
) | ||
|
||
try: | ||
api_connector.check() | ||
stream_connector.check() | ||
except Exception as error: | ||
print("FATAL error: manifest error", error) # TODO: logger | ||
print(f"FATAL error: manifest error when creating {stream_id} stream", error) # TODO: logger | ||
raise error | ||
|
||
return pw.io.python.read( | ||
api_connector, | ||
schema=BoardroomAPI # TODO: get this from mappings? or define standard base schema | ||
stream_connector, | ||
schema=pagination_schema.value | ||
) | ||
|
||
|
||
def input( | ||
api_name: str, | ||
settings: Settings, | ||
source_manifest: dict | pathlib.Path, | ||
endpoints: dict, | ||
pagination_schema: PaginationSchemas, | ||
cache_dir: str = "./output/cache", | ||
config: dict[str, typing.Any] | None = None, | ||
force_full_refresh: bool = False | ||
) -> typing.List[pw.Table]: | ||
# settings = get_settings() | ||
# class InputSchema(pw.Schema): | ||
# value: int | ||
# format="json" | ||
# return pw.io.python.read( | ||
# InfiniteStream(), | ||
# schema=InputSchema, | ||
# format=format, | ||
# autocommit_duration_ms=get_settings().autocommit_duration_ms, | ||
# ) | ||
|
||
streams = [details.get("stream_id", "") for endpoint, details in endpoints.items()] | ||
|
||
print(f"input streams - {streams}") # TODO: logger | ||
|
||
stream_tables = list() | ||
for stream_id in streams: | ||
stream = create_endpoint_stream( | ||
api_name=api_name, | ||
cache_name=f"{api_name}_{stream_id}_cache", | ||
cache_dir=cache_dir, | ||
source_manifest=source_manifest, | ||
stream_id=stream_id, | ||
pagination_schema=pagination_schema, | ||
config=config, | ||
force_full_refresh=force_full_refresh, | ||
) | ||
stream_tables.append(stream) | ||
|
||
return stream_tables |
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.