airbyte-cdk 0.0.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- airbyte_cdk/__init__.py +358 -0
- airbyte_cdk/cli/__init__.py +1 -0
- airbyte_cdk/cli/source_declarative_manifest/__init__.py +5 -0
- airbyte_cdk/cli/source_declarative_manifest/_run.py +236 -0
- airbyte_cdk/cli/source_declarative_manifest/spec.json +17 -0
- airbyte_cdk/config_observation.py +104 -0
- airbyte_cdk/connector.py +123 -0
- airbyte_cdk/connector_builder/README.md +53 -0
- airbyte_cdk/connector_builder/__init__.py +3 -0
- airbyte_cdk/connector_builder/connector_builder_handler.py +121 -0
- airbyte_cdk/connector_builder/main.py +107 -0
- airbyte_cdk/connector_builder/models.py +73 -0
- airbyte_cdk/connector_builder/test_reader/__init__.py +7 -0
- airbyte_cdk/connector_builder/test_reader/helpers.py +689 -0
- airbyte_cdk/connector_builder/test_reader/message_grouper.py +173 -0
- airbyte_cdk/connector_builder/test_reader/reader.py +441 -0
- airbyte_cdk/connector_builder/test_reader/types.py +83 -0
- airbyte_cdk/destinations/__init__.py +8 -0
- airbyte_cdk/destinations/destination.py +154 -0
- airbyte_cdk/destinations/vector_db_based/README.md +37 -0
- airbyte_cdk/destinations/vector_db_based/__init__.py +38 -0
- airbyte_cdk/destinations/vector_db_based/config.py +298 -0
- airbyte_cdk/destinations/vector_db_based/document_processor.py +223 -0
- airbyte_cdk/destinations/vector_db_based/embedder.py +303 -0
- airbyte_cdk/destinations/vector_db_based/indexer.py +78 -0
- airbyte_cdk/destinations/vector_db_based/test_utils.py +63 -0
- airbyte_cdk/destinations/vector_db_based/utils.py +35 -0
- airbyte_cdk/destinations/vector_db_based/writer.py +104 -0
- airbyte_cdk/entrypoint.py +414 -0
- airbyte_cdk/exception_handler.py +56 -0
- airbyte_cdk/logger.py +109 -0
- airbyte_cdk/models/__init__.py +72 -0
- airbyte_cdk/models/airbyte_protocol.py +88 -0
- airbyte_cdk/models/airbyte_protocol_serializers.py +44 -0
- airbyte_cdk/models/well_known_types.py +5 -0
- airbyte_cdk/py.typed +0 -0
- airbyte_cdk/sources/__init__.py +26 -0
- airbyte_cdk/sources/abstract_source.py +326 -0
- airbyte_cdk/sources/concurrent_source/__init__.py +8 -0
- airbyte_cdk/sources/concurrent_source/concurrent_read_processor.py +255 -0
- airbyte_cdk/sources/concurrent_source/concurrent_source.py +165 -0
- airbyte_cdk/sources/concurrent_source/concurrent_source_adapter.py +147 -0
- airbyte_cdk/sources/concurrent_source/partition_generation_completed_sentinel.py +24 -0
- airbyte_cdk/sources/concurrent_source/stream_thread_exception.py +25 -0
- airbyte_cdk/sources/concurrent_source/thread_pool_manager.py +115 -0
- airbyte_cdk/sources/config.py +27 -0
- airbyte_cdk/sources/connector_state_manager.py +161 -0
- airbyte_cdk/sources/declarative/__init__.py +3 -0
- airbyte_cdk/sources/declarative/async_job/__init__.py +0 -0
- airbyte_cdk/sources/declarative/async_job/job.py +52 -0
- airbyte_cdk/sources/declarative/async_job/job_orchestrator.py +525 -0
- airbyte_cdk/sources/declarative/async_job/job_tracker.py +79 -0
- airbyte_cdk/sources/declarative/async_job/repository.py +35 -0
- airbyte_cdk/sources/declarative/async_job/status.py +24 -0
- airbyte_cdk/sources/declarative/async_job/timer.py +39 -0
- airbyte_cdk/sources/declarative/auth/__init__.py +8 -0
- airbyte_cdk/sources/declarative/auth/declarative_authenticator.py +42 -0
- airbyte_cdk/sources/declarative/auth/jwt.py +197 -0
- airbyte_cdk/sources/declarative/auth/oauth.py +293 -0
- airbyte_cdk/sources/declarative/auth/selective_authenticator.py +45 -0
- airbyte_cdk/sources/declarative/auth/token.py +267 -0
- airbyte_cdk/sources/declarative/auth/token_provider.py +82 -0
- airbyte_cdk/sources/declarative/checks/__init__.py +24 -0
- airbyte_cdk/sources/declarative/checks/check_dynamic_stream.py +61 -0
- airbyte_cdk/sources/declarative/checks/check_stream.py +56 -0
- airbyte_cdk/sources/declarative/checks/connection_checker.py +35 -0
- airbyte_cdk/sources/declarative/concurrency_level/__init__.py +7 -0
- airbyte_cdk/sources/declarative/concurrency_level/concurrency_level.py +50 -0
- airbyte_cdk/sources/declarative/concurrent_declarative_source.py +526 -0
- airbyte_cdk/sources/declarative/datetime/__init__.py +3 -0
- airbyte_cdk/sources/declarative/datetime/datetime_parser.py +65 -0
- airbyte_cdk/sources/declarative/datetime/min_max_datetime.py +118 -0
- airbyte_cdk/sources/declarative/declarative_component_schema.yaml +3975 -0
- airbyte_cdk/sources/declarative/declarative_source.py +36 -0
- airbyte_cdk/sources/declarative/declarative_stream.py +241 -0
- airbyte_cdk/sources/declarative/decoders/__init__.py +33 -0
- airbyte_cdk/sources/declarative/decoders/composite_raw_decoder.py +218 -0
- airbyte_cdk/sources/declarative/decoders/decoder.py +32 -0
- airbyte_cdk/sources/declarative/decoders/decoder_parser.py +30 -0
- airbyte_cdk/sources/declarative/decoders/json_decoder.py +65 -0
- airbyte_cdk/sources/declarative/decoders/noop_decoder.py +21 -0
- airbyte_cdk/sources/declarative/decoders/pagination_decoder_decorator.py +39 -0
- airbyte_cdk/sources/declarative/decoders/xml_decoder.py +98 -0
- airbyte_cdk/sources/declarative/decoders/zipfile_decoder.py +56 -0
- airbyte_cdk/sources/declarative/exceptions.py +9 -0
- airbyte_cdk/sources/declarative/extractors/__init__.py +21 -0
- airbyte_cdk/sources/declarative/extractors/dpath_extractor.py +86 -0
- airbyte_cdk/sources/declarative/extractors/http_selector.py +37 -0
- airbyte_cdk/sources/declarative/extractors/record_extractor.py +27 -0
- airbyte_cdk/sources/declarative/extractors/record_filter.py +91 -0
- airbyte_cdk/sources/declarative/extractors/record_selector.py +170 -0
- airbyte_cdk/sources/declarative/extractors/response_to_file_extractor.py +176 -0
- airbyte_cdk/sources/declarative/extractors/type_transformer.py +55 -0
- airbyte_cdk/sources/declarative/incremental/__init__.py +37 -0
- airbyte_cdk/sources/declarative/incremental/concurrent_partition_cursor.py +497 -0
- airbyte_cdk/sources/declarative/incremental/datetime_based_cursor.py +459 -0
- airbyte_cdk/sources/declarative/incremental/declarative_cursor.py +13 -0
- airbyte_cdk/sources/declarative/incremental/global_substream_cursor.py +357 -0
- airbyte_cdk/sources/declarative/incremental/per_partition_cursor.py +380 -0
- airbyte_cdk/sources/declarative/incremental/per_partition_with_global.py +200 -0
- airbyte_cdk/sources/declarative/incremental/resumable_full_refresh_cursor.py +122 -0
- airbyte_cdk/sources/declarative/interpolation/__init__.py +9 -0
- airbyte_cdk/sources/declarative/interpolation/filters.py +139 -0
- airbyte_cdk/sources/declarative/interpolation/interpolated_boolean.py +66 -0
- airbyte_cdk/sources/declarative/interpolation/interpolated_mapping.py +56 -0
- airbyte_cdk/sources/declarative/interpolation/interpolated_nested_mapping.py +52 -0
- airbyte_cdk/sources/declarative/interpolation/interpolated_string.py +79 -0
- airbyte_cdk/sources/declarative/interpolation/interpolation.py +34 -0
- airbyte_cdk/sources/declarative/interpolation/jinja.py +161 -0
- airbyte_cdk/sources/declarative/interpolation/macros.py +191 -0
- airbyte_cdk/sources/declarative/manifest_declarative_source.py +421 -0
- airbyte_cdk/sources/declarative/migrations/__init__.py +0 -0
- airbyte_cdk/sources/declarative/migrations/legacy_to_per_partition_state_migration.py +98 -0
- airbyte_cdk/sources/declarative/migrations/state_migration.py +24 -0
- airbyte_cdk/sources/declarative/models/__init__.py +2 -0
- airbyte_cdk/sources/declarative/models/declarative_component_schema.py +2503 -0
- airbyte_cdk/sources/declarative/parsers/__init__.py +3 -0
- airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py +157 -0
- airbyte_cdk/sources/declarative/parsers/custom_exceptions.py +21 -0
- airbyte_cdk/sources/declarative/parsers/manifest_component_transformer.py +172 -0
- airbyte_cdk/sources/declarative/parsers/manifest_reference_resolver.py +213 -0
- airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py +3407 -0
- airbyte_cdk/sources/declarative/partition_routers/__init__.py +29 -0
- airbyte_cdk/sources/declarative/partition_routers/async_job_partition_router.py +65 -0
- airbyte_cdk/sources/declarative/partition_routers/cartesian_product_stream_slicer.py +176 -0
- airbyte_cdk/sources/declarative/partition_routers/list_partition_router.py +121 -0
- airbyte_cdk/sources/declarative/partition_routers/partition_router.py +62 -0
- airbyte_cdk/sources/declarative/partition_routers/single_partition_router.py +63 -0
- airbyte_cdk/sources/declarative/partition_routers/substream_partition_router.py +437 -0
- airbyte_cdk/sources/declarative/requesters/README.md +56 -0
- airbyte_cdk/sources/declarative/requesters/__init__.py +9 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/__init__.py +25 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/__init__.py +23 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/constant_backoff_strategy.py +45 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/exponential_backoff_strategy.py +45 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/header_helper.py +41 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/wait_time_from_header_backoff_strategy.py +70 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/wait_until_time_from_header_backoff_strategy.py +77 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategy.py +17 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/composite_error_handler.py +101 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/default_error_handler.py +147 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/default_http_response_filter.py +40 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/error_handler.py +17 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/http_response_filter.py +179 -0
- airbyte_cdk/sources/declarative/requesters/http_job_repository.py +350 -0
- airbyte_cdk/sources/declarative/requesters/http_requester.py +433 -0
- airbyte_cdk/sources/declarative/requesters/paginators/__init__.py +21 -0
- airbyte_cdk/sources/declarative/requesters/paginators/default_paginator.py +327 -0
- airbyte_cdk/sources/declarative/requesters/paginators/no_pagination.py +76 -0
- airbyte_cdk/sources/declarative/requesters/paginators/paginator.py +65 -0
- airbyte_cdk/sources/declarative/requesters/paginators/strategies/__init__.py +25 -0
- airbyte_cdk/sources/declarative/requesters/paginators/strategies/cursor_pagination_strategy.py +98 -0
- airbyte_cdk/sources/declarative/requesters/paginators/strategies/offset_increment.py +102 -0
- airbyte_cdk/sources/declarative/requesters/paginators/strategies/page_increment.py +71 -0
- airbyte_cdk/sources/declarative/requesters/paginators/strategies/pagination_strategy.py +48 -0
- airbyte_cdk/sources/declarative/requesters/paginators/strategies/stop_condition.py +66 -0
- airbyte_cdk/sources/declarative/requesters/request_option.py +117 -0
- airbyte_cdk/sources/declarative/requesters/request_options/__init__.py +23 -0
- airbyte_cdk/sources/declarative/requesters/request_options/datetime_based_request_options_provider.py +92 -0
- airbyte_cdk/sources/declarative/requesters/request_options/default_request_options_provider.py +60 -0
- airbyte_cdk/sources/declarative/requesters/request_options/interpolated_nested_request_input_provider.py +59 -0
- airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_input_provider.py +68 -0
- airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py +119 -0
- airbyte_cdk/sources/declarative/requesters/request_options/request_options_provider.py +79 -0
- airbyte_cdk/sources/declarative/requesters/request_path.py +15 -0
- airbyte_cdk/sources/declarative/requesters/requester.py +144 -0
- airbyte_cdk/sources/declarative/resolvers/__init__.py +41 -0
- airbyte_cdk/sources/declarative/resolvers/components_resolver.py +55 -0
- airbyte_cdk/sources/declarative/resolvers/config_components_resolver.py +136 -0
- airbyte_cdk/sources/declarative/resolvers/http_components_resolver.py +112 -0
- airbyte_cdk/sources/declarative/retrievers/__init__.py +19 -0
- airbyte_cdk/sources/declarative/retrievers/async_retriever.py +124 -0
- airbyte_cdk/sources/declarative/retrievers/file_uploader.py +89 -0
- airbyte_cdk/sources/declarative/retrievers/retriever.py +54 -0
- airbyte_cdk/sources/declarative/retrievers/simple_retriever.py +702 -0
- airbyte_cdk/sources/declarative/schema/__init__.py +25 -0
- airbyte_cdk/sources/declarative/schema/default_schema_loader.py +47 -0
- airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py +285 -0
- airbyte_cdk/sources/declarative/schema/inline_schema_loader.py +19 -0
- airbyte_cdk/sources/declarative/schema/json_file_schema_loader.py +92 -0
- airbyte_cdk/sources/declarative/schema/schema_loader.py +17 -0
- airbyte_cdk/sources/declarative/spec/__init__.py +7 -0
- airbyte_cdk/sources/declarative/spec/spec.py +48 -0
- airbyte_cdk/sources/declarative/stream_slicers/__init__.py +7 -0
- airbyte_cdk/sources/declarative/stream_slicers/declarative_partition_generator.py +93 -0
- airbyte_cdk/sources/declarative/stream_slicers/stream_slicer.py +25 -0
- airbyte_cdk/sources/declarative/transformations/__init__.py +17 -0
- airbyte_cdk/sources/declarative/transformations/add_fields.py +146 -0
- airbyte_cdk/sources/declarative/transformations/dpath_flatten_fields.py +61 -0
- airbyte_cdk/sources/declarative/transformations/flatten_fields.py +52 -0
- airbyte_cdk/sources/declarative/transformations/keys_replace_transformation.py +61 -0
- airbyte_cdk/sources/declarative/transformations/keys_to_lower_transformation.py +22 -0
- airbyte_cdk/sources/declarative/transformations/keys_to_snake_transformation.py +68 -0
- airbyte_cdk/sources/declarative/transformations/remove_fields.py +75 -0
- airbyte_cdk/sources/declarative/transformations/transformation.py +37 -0
- airbyte_cdk/sources/declarative/types.py +25 -0
- airbyte_cdk/sources/declarative/yaml_declarative_source.py +67 -0
- airbyte_cdk/sources/file_based/README.md +152 -0
- airbyte_cdk/sources/file_based/__init__.py +24 -0
- airbyte_cdk/sources/file_based/availability_strategy/__init__.py +11 -0
- airbyte_cdk/sources/file_based/availability_strategy/abstract_file_based_availability_strategy.py +73 -0
- airbyte_cdk/sources/file_based/availability_strategy/default_file_based_availability_strategy.py +149 -0
- airbyte_cdk/sources/file_based/config/__init__.py +0 -0
- airbyte_cdk/sources/file_based/config/abstract_file_based_spec.py +153 -0
- airbyte_cdk/sources/file_based/config/avro_format.py +25 -0
- airbyte_cdk/sources/file_based/config/csv_format.py +210 -0
- airbyte_cdk/sources/file_based/config/excel_format.py +18 -0
- airbyte_cdk/sources/file_based/config/file_based_stream_config.py +99 -0
- airbyte_cdk/sources/file_based/config/jsonl_format.py +18 -0
- airbyte_cdk/sources/file_based/config/parquet_format.py +25 -0
- airbyte_cdk/sources/file_based/config/unstructured_format.py +102 -0
- airbyte_cdk/sources/file_based/config/validate_config_transfer_modes.py +81 -0
- airbyte_cdk/sources/file_based/discovery_policy/__init__.py +8 -0
- airbyte_cdk/sources/file_based/discovery_policy/abstract_discovery_policy.py +21 -0
- airbyte_cdk/sources/file_based/discovery_policy/default_discovery_policy.py +33 -0
- airbyte_cdk/sources/file_based/exceptions.py +159 -0
- airbyte_cdk/sources/file_based/file_based_source.py +466 -0
- airbyte_cdk/sources/file_based/file_based_stream_permissions_reader.py +123 -0
- airbyte_cdk/sources/file_based/file_based_stream_reader.py +209 -0
- airbyte_cdk/sources/file_based/file_record_data.py +22 -0
- airbyte_cdk/sources/file_based/file_types/__init__.py +37 -0
- airbyte_cdk/sources/file_based/file_types/avro_parser.py +233 -0
- airbyte_cdk/sources/file_based/file_types/csv_parser.py +527 -0
- airbyte_cdk/sources/file_based/file_types/excel_parser.py +196 -0
- airbyte_cdk/sources/file_based/file_types/file_transfer.py +30 -0
- airbyte_cdk/sources/file_based/file_types/file_type_parser.py +86 -0
- airbyte_cdk/sources/file_based/file_types/jsonl_parser.py +145 -0
- airbyte_cdk/sources/file_based/file_types/parquet_parser.py +275 -0
- airbyte_cdk/sources/file_based/file_types/unstructured_parser.py +480 -0
- airbyte_cdk/sources/file_based/remote_file.py +18 -0
- airbyte_cdk/sources/file_based/schema_helpers.py +281 -0
- airbyte_cdk/sources/file_based/schema_validation_policies/__init__.py +17 -0
- airbyte_cdk/sources/file_based/schema_validation_policies/abstract_schema_validation_policy.py +20 -0
- airbyte_cdk/sources/file_based/schema_validation_policies/default_schema_validation_policies.py +52 -0
- airbyte_cdk/sources/file_based/stream/__init__.py +13 -0
- airbyte_cdk/sources/file_based/stream/abstract_file_based_stream.py +197 -0
- airbyte_cdk/sources/file_based/stream/concurrent/__init__.py +0 -0
- airbyte_cdk/sources/file_based/stream/concurrent/adapters.py +343 -0
- airbyte_cdk/sources/file_based/stream/concurrent/cursor/__init__.py +9 -0
- airbyte_cdk/sources/file_based/stream/concurrent/cursor/abstract_concurrent_file_based_cursor.py +59 -0
- airbyte_cdk/sources/file_based/stream/concurrent/cursor/file_based_concurrent_cursor.py +313 -0
- airbyte_cdk/sources/file_based/stream/concurrent/cursor/file_based_final_state_cursor.py +83 -0
- airbyte_cdk/sources/file_based/stream/cursor/__init__.py +4 -0
- airbyte_cdk/sources/file_based/stream/cursor/abstract_file_based_cursor.py +66 -0
- airbyte_cdk/sources/file_based/stream/cursor/default_file_based_cursor.py +149 -0
- airbyte_cdk/sources/file_based/stream/default_file_based_stream.py +396 -0
- airbyte_cdk/sources/file_based/stream/identities_stream.py +49 -0
- airbyte_cdk/sources/file_based/stream/permissions_file_based_stream.py +92 -0
- airbyte_cdk/sources/file_based/types.py +10 -0
- airbyte_cdk/sources/http_config.py +10 -0
- airbyte_cdk/sources/http_logger.py +55 -0
- airbyte_cdk/sources/message/__init__.py +19 -0
- airbyte_cdk/sources/message/repository.py +137 -0
- airbyte_cdk/sources/source.py +95 -0
- airbyte_cdk/sources/specs/transfer_modes.py +26 -0
- airbyte_cdk/sources/streams/__init__.py +8 -0
- airbyte_cdk/sources/streams/availability_strategy.py +84 -0
- airbyte_cdk/sources/streams/call_rate.py +704 -0
- airbyte_cdk/sources/streams/checkpoint/__init__.py +26 -0
- airbyte_cdk/sources/streams/checkpoint/checkpoint_reader.py +335 -0
- airbyte_cdk/sources/streams/checkpoint/cursor.py +77 -0
- airbyte_cdk/sources/streams/checkpoint/per_partition_key_serializer.py +22 -0
- airbyte_cdk/sources/streams/checkpoint/resumable_full_refresh_cursor.py +51 -0
- airbyte_cdk/sources/streams/checkpoint/substream_resumable_full_refresh_cursor.py +110 -0
- airbyte_cdk/sources/streams/concurrent/README.md +7 -0
- airbyte_cdk/sources/streams/concurrent/__init__.py +3 -0
- airbyte_cdk/sources/streams/concurrent/abstract_stream.py +96 -0
- airbyte_cdk/sources/streams/concurrent/abstract_stream_facade.py +37 -0
- airbyte_cdk/sources/streams/concurrent/adapters.py +397 -0
- airbyte_cdk/sources/streams/concurrent/availability_strategy.py +94 -0
- airbyte_cdk/sources/streams/concurrent/clamping.py +99 -0
- airbyte_cdk/sources/streams/concurrent/cursor.py +481 -0
- airbyte_cdk/sources/streams/concurrent/cursor_types.py +32 -0
- airbyte_cdk/sources/streams/concurrent/default_stream.py +102 -0
- airbyte_cdk/sources/streams/concurrent/exceptions.py +18 -0
- airbyte_cdk/sources/streams/concurrent/helpers.py +42 -0
- airbyte_cdk/sources/streams/concurrent/partition_enqueuer.py +64 -0
- airbyte_cdk/sources/streams/concurrent/partition_reader.py +45 -0
- airbyte_cdk/sources/streams/concurrent/partitions/__init__.py +3 -0
- airbyte_cdk/sources/streams/concurrent/partitions/partition.py +48 -0
- airbyte_cdk/sources/streams/concurrent/partitions/partition_generator.py +18 -0
- airbyte_cdk/sources/streams/concurrent/partitions/stream_slicer.py +21 -0
- airbyte_cdk/sources/streams/concurrent/partitions/types.py +38 -0
- airbyte_cdk/sources/streams/concurrent/state_converters/__init__.py +0 -0
- airbyte_cdk/sources/streams/concurrent/state_converters/abstract_stream_state_converter.py +182 -0
- airbyte_cdk/sources/streams/concurrent/state_converters/datetime_stream_state_converter.py +223 -0
- airbyte_cdk/sources/streams/concurrent/state_converters/incrementing_count_stream_state_converter.py +92 -0
- airbyte_cdk/sources/streams/core.py +703 -0
- airbyte_cdk/sources/streams/http/__init__.py +10 -0
- airbyte_cdk/sources/streams/http/availability_strategy.py +54 -0
- airbyte_cdk/sources/streams/http/error_handlers/__init__.py +22 -0
- airbyte_cdk/sources/streams/http/error_handlers/backoff_strategy.py +28 -0
- airbyte_cdk/sources/streams/http/error_handlers/default_backoff_strategy.py +17 -0
- airbyte_cdk/sources/streams/http/error_handlers/default_error_mapping.py +86 -0
- airbyte_cdk/sources/streams/http/error_handlers/error_handler.py +42 -0
- airbyte_cdk/sources/streams/http/error_handlers/error_message_parser.py +19 -0
- airbyte_cdk/sources/streams/http/error_handlers/http_status_error_handler.py +110 -0
- airbyte_cdk/sources/streams/http/error_handlers/json_error_message_parser.py +52 -0
- airbyte_cdk/sources/streams/http/error_handlers/response_models.py +65 -0
- airbyte_cdk/sources/streams/http/exceptions.py +61 -0
- airbyte_cdk/sources/streams/http/http.py +673 -0
- airbyte_cdk/sources/streams/http/http_client.py +531 -0
- airbyte_cdk/sources/streams/http/rate_limiting.py +158 -0
- airbyte_cdk/sources/streams/http/requests_native_auth/__init__.py +14 -0
- airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +479 -0
- airbyte_cdk/sources/streams/http/requests_native_auth/abstract_token.py +34 -0
- airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py +436 -0
- airbyte_cdk/sources/streams/http/requests_native_auth/token.py +83 -0
- airbyte_cdk/sources/streams/permissions/identities_stream.py +75 -0
- airbyte_cdk/sources/streams/utils/__init__.py +3 -0
- airbyte_cdk/sources/types.py +169 -0
- airbyte_cdk/sources/utils/__init__.py +7 -0
- airbyte_cdk/sources/utils/casing.py +12 -0
- airbyte_cdk/sources/utils/files_directory.py +15 -0
- airbyte_cdk/sources/utils/record_helper.py +53 -0
- airbyte_cdk/sources/utils/schema_helpers.py +230 -0
- airbyte_cdk/sources/utils/slice_logger.py +57 -0
- airbyte_cdk/sources/utils/transform.py +277 -0
- airbyte_cdk/sources/utils/types.py +7 -0
- airbyte_cdk/sql/__init__.py +0 -0
- airbyte_cdk/sql/_util/__init__.py +0 -0
- airbyte_cdk/sql/_util/hashing.py +34 -0
- airbyte_cdk/sql/_util/name_normalizers.py +92 -0
- airbyte_cdk/sql/constants.py +32 -0
- airbyte_cdk/sql/exceptions.py +235 -0
- airbyte_cdk/sql/secrets.py +123 -0
- airbyte_cdk/sql/shared/__init__.py +15 -0
- airbyte_cdk/sql/shared/catalog_providers.py +145 -0
- airbyte_cdk/sql/shared/sql_processor.py +786 -0
- airbyte_cdk/sql/types.py +160 -0
- airbyte_cdk/test/__init__.py +7 -0
- airbyte_cdk/test/catalog_builder.py +81 -0
- airbyte_cdk/test/entrypoint_wrapper.py +250 -0
- airbyte_cdk/test/mock_http/__init__.py +6 -0
- airbyte_cdk/test/mock_http/matcher.py +41 -0
- airbyte_cdk/test/mock_http/mocker.py +185 -0
- airbyte_cdk/test/mock_http/request.py +103 -0
- airbyte_cdk/test/mock_http/response.py +28 -0
- airbyte_cdk/test/mock_http/response_builder.py +237 -0
- airbyte_cdk/test/state_builder.py +33 -0
- airbyte_cdk/test/utils/__init__.py +1 -0
- airbyte_cdk/test/utils/data.py +24 -0
- airbyte_cdk/test/utils/http_mocking.py +16 -0
- airbyte_cdk/test/utils/manifest_only_fixtures.py +59 -0
- airbyte_cdk/test/utils/reading.py +26 -0
- airbyte_cdk/utils/__init__.py +10 -0
- airbyte_cdk/utils/airbyte_secrets_utils.py +80 -0
- airbyte_cdk/utils/analytics_message.py +25 -0
- airbyte_cdk/utils/constants.py +5 -0
- airbyte_cdk/utils/datetime_format_inferrer.py +94 -0
- airbyte_cdk/utils/datetime_helpers.py +499 -0
- airbyte_cdk/utils/event_timing.py +85 -0
- airbyte_cdk/utils/is_cloud_environment.py +18 -0
- airbyte_cdk/utils/mapping_helpers.py +162 -0
- airbyte_cdk/utils/message_utils.py +26 -0
- airbyte_cdk/utils/oneof_option_config.py +33 -0
- airbyte_cdk/utils/print_buffer.py +75 -0
- airbyte_cdk/utils/schema_inferrer.py +270 -0
- airbyte_cdk/utils/slice_hasher.py +37 -0
- airbyte_cdk/utils/spec_schema_transformations.py +26 -0
- airbyte_cdk/utils/stream_status_utils.py +43 -0
- airbyte_cdk/utils/traced_exception.py +145 -0
- airbyte_cdk-0.0.0.dev0.dist-info/LICENSE.txt +19 -0
- airbyte_cdk-0.0.0.dev0.dist-info/LICENSE_SHORT +1 -0
- airbyte_cdk-0.0.0.dev0.dist-info/METADATA +111 -0
- airbyte_cdk-0.0.0.dev0.dist-info/RECORD +368 -0
- airbyte_cdk-0.0.0.dev0.dist-info/WHEEL +4 -0
- airbyte_cdk-0.0.0.dev0.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
from dataclasses import InitVar, dataclass
|
|
6
|
+
from typing import Any, Mapping, Optional, Set, Union
|
|
7
|
+
|
|
8
|
+
import requests
|
|
9
|
+
|
|
10
|
+
from airbyte_cdk.models import FailureType
|
|
11
|
+
from airbyte_cdk.sources.declarative.interpolation import InterpolatedString
|
|
12
|
+
from airbyte_cdk.sources.declarative.interpolation.interpolated_boolean import InterpolatedBoolean
|
|
13
|
+
from airbyte_cdk.sources.streams.http.error_handlers import JsonErrorMessageParser
|
|
14
|
+
from airbyte_cdk.sources.streams.http.error_handlers.default_error_mapping import (
|
|
15
|
+
DEFAULT_ERROR_MAPPING,
|
|
16
|
+
)
|
|
17
|
+
from airbyte_cdk.sources.streams.http.error_handlers.response_models import (
|
|
18
|
+
ErrorResolution,
|
|
19
|
+
ResponseAction,
|
|
20
|
+
)
|
|
21
|
+
from airbyte_cdk.sources.types import Config
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class HttpResponseFilter:
|
|
26
|
+
"""
|
|
27
|
+
Filter to select a response based on its HTTP status code, error message or a predicate.
|
|
28
|
+
If a response matches the filter, the response action, failure_type, and error message are returned as an ErrorResolution object.
|
|
29
|
+
For http_codes declared in the filter, the failure_type will default to `system_error`.
|
|
30
|
+
To override default failure_type use configured failure_type with ResponseAction.FAIL.
|
|
31
|
+
|
|
32
|
+
Attributes:
|
|
33
|
+
action (Union[ResponseAction, str]): action to execute if a request matches
|
|
34
|
+
failure_type (Union[ResponseAction, str]): failure type of traced exception if a response matches the filter
|
|
35
|
+
http_codes (Set[int]): http code of matching requests
|
|
36
|
+
error_message_contains (str): error substring of matching requests
|
|
37
|
+
predicate (str): predicate to apply to determine if a request is matching
|
|
38
|
+
error_message (Union[InterpolatedString, str): error message to display if the response matches the filter
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
config: Config
|
|
42
|
+
parameters: InitVar[Mapping[str, Any]]
|
|
43
|
+
action: Optional[Union[ResponseAction, str]] = None
|
|
44
|
+
failure_type: Optional[Union[FailureType, str]] = None
|
|
45
|
+
http_codes: Optional[Set[int]] = None
|
|
46
|
+
error_message_contains: Optional[str] = None
|
|
47
|
+
predicate: Union[InterpolatedBoolean, str] = ""
|
|
48
|
+
error_message: Union[InterpolatedString, str] = ""
|
|
49
|
+
|
|
50
|
+
def __post_init__(self, parameters: Mapping[str, Any]) -> None:
|
|
51
|
+
if self.action is not None:
|
|
52
|
+
if (
|
|
53
|
+
self.http_codes is None
|
|
54
|
+
and self.predicate is None
|
|
55
|
+
and self.error_message_contains is None
|
|
56
|
+
):
|
|
57
|
+
raise ValueError(
|
|
58
|
+
"HttpResponseFilter requires a filter condition if an action is specified"
|
|
59
|
+
)
|
|
60
|
+
elif isinstance(self.action, str):
|
|
61
|
+
self.action = ResponseAction[self.action]
|
|
62
|
+
self.http_codes = self.http_codes or set()
|
|
63
|
+
if isinstance(self.predicate, str):
|
|
64
|
+
self.predicate = InterpolatedBoolean(condition=self.predicate, parameters=parameters)
|
|
65
|
+
self.error_message = InterpolatedString.create(
|
|
66
|
+
string_or_interpolated=self.error_message, parameters=parameters
|
|
67
|
+
)
|
|
68
|
+
self._error_message_parser = JsonErrorMessageParser()
|
|
69
|
+
if self.failure_type and isinstance(self.failure_type, str):
|
|
70
|
+
self.failure_type = FailureType[self.failure_type]
|
|
71
|
+
|
|
72
|
+
def matches(
|
|
73
|
+
self, response_or_exception: Optional[Union[requests.Response, Exception]]
|
|
74
|
+
) -> Optional[ErrorResolution]:
|
|
75
|
+
filter_action = self._matches_filter(response_or_exception)
|
|
76
|
+
mapped_key = (
|
|
77
|
+
response_or_exception.status_code
|
|
78
|
+
if isinstance(response_or_exception, requests.Response)
|
|
79
|
+
else response_or_exception.__class__
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if isinstance(mapped_key, (int, Exception)):
|
|
83
|
+
default_mapped_error_resolution = self._match_default_error_mapping(mapped_key)
|
|
84
|
+
else:
|
|
85
|
+
default_mapped_error_resolution = None
|
|
86
|
+
|
|
87
|
+
if filter_action is not None:
|
|
88
|
+
default_error_message = (
|
|
89
|
+
default_mapped_error_resolution.error_message
|
|
90
|
+
if default_mapped_error_resolution
|
|
91
|
+
else ""
|
|
92
|
+
)
|
|
93
|
+
error_message = None
|
|
94
|
+
if isinstance(response_or_exception, requests.Response):
|
|
95
|
+
error_message = self._create_error_message(response_or_exception)
|
|
96
|
+
error_message = error_message or default_error_message
|
|
97
|
+
|
|
98
|
+
if self.failure_type and filter_action == ResponseAction.FAIL:
|
|
99
|
+
failure_type = self.failure_type
|
|
100
|
+
elif default_mapped_error_resolution:
|
|
101
|
+
failure_type = default_mapped_error_resolution.failure_type
|
|
102
|
+
else:
|
|
103
|
+
failure_type = FailureType.system_error
|
|
104
|
+
|
|
105
|
+
return ErrorResolution(
|
|
106
|
+
response_action=filter_action,
|
|
107
|
+
failure_type=failure_type,
|
|
108
|
+
error_message=error_message,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
if (
|
|
112
|
+
(isinstance(self.http_codes, list) and len(self.http_codes)) is None
|
|
113
|
+
and self.predicate is None
|
|
114
|
+
and self.error_message_contains is None
|
|
115
|
+
) and default_mapped_error_resolution:
|
|
116
|
+
return default_mapped_error_resolution
|
|
117
|
+
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
def _match_default_error_mapping(
|
|
121
|
+
self, mapped_key: Union[int, type[Exception]]
|
|
122
|
+
) -> Optional[ErrorResolution]:
|
|
123
|
+
return DEFAULT_ERROR_MAPPING.get(mapped_key)
|
|
124
|
+
|
|
125
|
+
def _matches_filter(
|
|
126
|
+
self, response_or_exception: Optional[Union[requests.Response, Exception]]
|
|
127
|
+
) -> Optional[ResponseAction]:
|
|
128
|
+
"""
|
|
129
|
+
Apply the HTTP filter on the response and return the action to execute if it matches
|
|
130
|
+
:param response: The HTTP response to evaluate
|
|
131
|
+
:return: The action to execute. None if the response does not match the filter
|
|
132
|
+
"""
|
|
133
|
+
if isinstance(response_or_exception, requests.Response) and (
|
|
134
|
+
response_or_exception.status_code in self.http_codes # type: ignore # http_codes set is always initialized to a value in __post_init__
|
|
135
|
+
or self._response_matches_predicate(response_or_exception)
|
|
136
|
+
or self._response_contains_error_message(response_or_exception)
|
|
137
|
+
):
|
|
138
|
+
return self.action # type: ignore # action is always cast to a ResponseAction not a str
|
|
139
|
+
return None
|
|
140
|
+
|
|
141
|
+
@staticmethod
|
|
142
|
+
def _safe_response_json(response: requests.Response) -> dict[str, Any]:
|
|
143
|
+
try:
|
|
144
|
+
return response.json() # type: ignore # Response.json() returns a dictionary even if the signature does not
|
|
145
|
+
except requests.exceptions.JSONDecodeError:
|
|
146
|
+
return {}
|
|
147
|
+
|
|
148
|
+
def _create_error_message(self, response: requests.Response) -> Optional[str]:
|
|
149
|
+
"""
|
|
150
|
+
Construct an error message based on the specified message template of the filter.
|
|
151
|
+
:param response: The HTTP response which can be used during interpolation
|
|
152
|
+
:return: The evaluated error message string to be emitted
|
|
153
|
+
"""
|
|
154
|
+
return self.error_message.eval( # type: ignore[no-any-return, union-attr]
|
|
155
|
+
self.config, response=self._safe_response_json(response), headers=response.headers
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
def _response_matches_predicate(self, response: requests.Response) -> bool:
|
|
159
|
+
return (
|
|
160
|
+
bool(
|
|
161
|
+
self.predicate.condition # type:ignore[union-attr]
|
|
162
|
+
and self.predicate.eval( # type:ignore[union-attr]
|
|
163
|
+
None, # type: ignore[arg-type]
|
|
164
|
+
response=self._safe_response_json(response),
|
|
165
|
+
headers=response.headers,
|
|
166
|
+
)
|
|
167
|
+
)
|
|
168
|
+
if self.predicate
|
|
169
|
+
else False
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
def _response_contains_error_message(self, response: requests.Response) -> bool:
|
|
173
|
+
if not self.error_message_contains:
|
|
174
|
+
return False
|
|
175
|
+
else:
|
|
176
|
+
error_message = self._error_message_parser.parse_response_error_message(
|
|
177
|
+
response=response
|
|
178
|
+
)
|
|
179
|
+
return bool(error_message and self.error_message_contains in error_message)
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
|
|
2
|
+
import logging
|
|
3
|
+
import uuid
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
from typing import Any, Dict, Iterable, Mapping, Optional
|
|
7
|
+
|
|
8
|
+
import requests
|
|
9
|
+
from requests import Response
|
|
10
|
+
|
|
11
|
+
from airbyte_cdk import AirbyteMessage
|
|
12
|
+
from airbyte_cdk.logger import lazy_log
|
|
13
|
+
from airbyte_cdk.models import FailureType, Type
|
|
14
|
+
from airbyte_cdk.sources.declarative.async_job.job import AsyncJob
|
|
15
|
+
from airbyte_cdk.sources.declarative.async_job.repository import AsyncJobRepository
|
|
16
|
+
from airbyte_cdk.sources.declarative.async_job.status import AsyncJobStatus
|
|
17
|
+
from airbyte_cdk.sources.declarative.extractors.dpath_extractor import (
|
|
18
|
+
DpathExtractor,
|
|
19
|
+
RecordExtractor,
|
|
20
|
+
)
|
|
21
|
+
from airbyte_cdk.sources.declarative.extractors.response_to_file_extractor import (
|
|
22
|
+
ResponseToFileExtractor,
|
|
23
|
+
)
|
|
24
|
+
from airbyte_cdk.sources.declarative.requesters.requester import Requester
|
|
25
|
+
from airbyte_cdk.sources.declarative.retrievers.simple_retriever import SimpleRetriever
|
|
26
|
+
from airbyte_cdk.sources.http_logger import format_http_message
|
|
27
|
+
from airbyte_cdk.sources.types import Record, StreamSlice
|
|
28
|
+
from airbyte_cdk.utils import AirbyteTracedException
|
|
29
|
+
|
|
30
|
+
LOGGER = logging.getLogger("airbyte")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass
|
|
34
|
+
class AsyncHttpJobRepository(AsyncJobRepository):
|
|
35
|
+
"""
|
|
36
|
+
See Readme file for more details about flow.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
creation_requester: Requester
|
|
40
|
+
polling_requester: Requester
|
|
41
|
+
download_retriever: SimpleRetriever
|
|
42
|
+
abort_requester: Optional[Requester]
|
|
43
|
+
delete_requester: Optional[Requester]
|
|
44
|
+
status_extractor: DpathExtractor
|
|
45
|
+
status_mapping: Mapping[str, AsyncJobStatus]
|
|
46
|
+
download_target_extractor: DpathExtractor
|
|
47
|
+
|
|
48
|
+
# timeout for the job to be completed, passed from `polling_job_timeout`
|
|
49
|
+
job_timeout: Optional[timedelta] = None
|
|
50
|
+
|
|
51
|
+
record_extractor: RecordExtractor = field(
|
|
52
|
+
init=False, repr=False, default_factory=lambda: ResponseToFileExtractor({})
|
|
53
|
+
)
|
|
54
|
+
download_target_requester: Optional[Requester] = (
|
|
55
|
+
None # use it in case polling_requester provides some <id> and extra request is needed to obtain list of urls to download from
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
def __post_init__(self) -> None:
|
|
59
|
+
self._create_job_response_by_id: Dict[str, Response] = {}
|
|
60
|
+
self._polling_job_response_by_id: Dict[str, Response] = {}
|
|
61
|
+
|
|
62
|
+
def _get_validated_polling_response(self, stream_slice: StreamSlice) -> requests.Response:
|
|
63
|
+
"""
|
|
64
|
+
Validates and retrieves the pooling response for a given stream slice.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
stream_slice (StreamSlice): The stream slice to send the pooling request for.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
requests.Response: The validated pooling response.
|
|
71
|
+
|
|
72
|
+
Raises:
|
|
73
|
+
AirbyteTracedException: If the polling request returns an empty response.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
polling_response: Optional[requests.Response] = self.polling_requester.send_request(
|
|
77
|
+
stream_slice=stream_slice,
|
|
78
|
+
log_formatter=lambda polling_response: format_http_message(
|
|
79
|
+
response=polling_response,
|
|
80
|
+
title="Async Job -- Polling",
|
|
81
|
+
description="Poll the status of the server-side async job.",
|
|
82
|
+
stream_name=None,
|
|
83
|
+
is_auxiliary=True,
|
|
84
|
+
type="ASYNC_POLL",
|
|
85
|
+
),
|
|
86
|
+
)
|
|
87
|
+
if polling_response is None:
|
|
88
|
+
raise AirbyteTracedException(
|
|
89
|
+
internal_message="Polling Requester received an empty Response.",
|
|
90
|
+
failure_type=FailureType.system_error,
|
|
91
|
+
)
|
|
92
|
+
return polling_response
|
|
93
|
+
|
|
94
|
+
def _get_validated_job_status(self, response: requests.Response) -> AsyncJobStatus:
|
|
95
|
+
"""
|
|
96
|
+
Validates the job status extracted from the API response.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
response (requests.Response): The API response.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
AsyncJobStatus: The validated job status.
|
|
103
|
+
|
|
104
|
+
Raises:
|
|
105
|
+
ValueError: If the API status is unknown.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
api_status = next(iter(self.status_extractor.extract_records(response)), None)
|
|
109
|
+
job_status = self.status_mapping.get(str(api_status), None)
|
|
110
|
+
if job_status is None:
|
|
111
|
+
raise ValueError(
|
|
112
|
+
f"API status `{api_status}` is unknown. Contact the connector developer to make sure this status is supported."
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
return job_status
|
|
116
|
+
|
|
117
|
+
def _start_job_and_validate_response(self, stream_slice: StreamSlice) -> requests.Response:
|
|
118
|
+
"""
|
|
119
|
+
Starts a job and validates the response.
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
stream_slice (StreamSlice): The stream slice to be used for the job.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
requests.Response: The response from the job creation requester.
|
|
126
|
+
|
|
127
|
+
Raises:
|
|
128
|
+
AirbyteTracedException: If no response is received from the creation requester.
|
|
129
|
+
"""
|
|
130
|
+
|
|
131
|
+
response: Optional[requests.Response] = self.creation_requester.send_request(
|
|
132
|
+
stream_slice=stream_slice,
|
|
133
|
+
log_formatter=lambda response: format_http_message(
|
|
134
|
+
response=response,
|
|
135
|
+
title="Async Job -- Create",
|
|
136
|
+
description=f"Create the server-side async job. Timeout after: {self.job_timeout}",
|
|
137
|
+
stream_name=None,
|
|
138
|
+
is_auxiliary=True,
|
|
139
|
+
type="ASYNC_CREATE",
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
if not response:
|
|
144
|
+
raise AirbyteTracedException(
|
|
145
|
+
internal_message="Always expect a response or an exception from creation_requester",
|
|
146
|
+
failure_type=FailureType.system_error,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
return response
|
|
150
|
+
|
|
151
|
+
def start(self, stream_slice: StreamSlice) -> AsyncJob:
|
|
152
|
+
"""
|
|
153
|
+
Starts a job for the given stream slice.
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
stream_slice (StreamSlice): The stream slice to start the job for.
|
|
157
|
+
|
|
158
|
+
Returns:
|
|
159
|
+
AsyncJob: The asynchronous job object representing the started job.
|
|
160
|
+
"""
|
|
161
|
+
|
|
162
|
+
response: requests.Response = self._start_job_and_validate_response(stream_slice)
|
|
163
|
+
job_id: str = str(uuid.uuid4())
|
|
164
|
+
self._create_job_response_by_id[job_id] = response
|
|
165
|
+
|
|
166
|
+
return AsyncJob(api_job_id=job_id, job_parameters=stream_slice, timeout=self.job_timeout)
|
|
167
|
+
|
|
168
|
+
def update_jobs_status(self, jobs: Iterable[AsyncJob]) -> None:
|
|
169
|
+
"""
|
|
170
|
+
Updates the status of multiple jobs.
|
|
171
|
+
|
|
172
|
+
Because we don't have interpolation on random fields, we have this hack which consist on using the stream_slice to allow for
|
|
173
|
+
interpolation. We are looking at enabling interpolation on more field which would require a change to those three layers:
|
|
174
|
+
HttpRequester, RequestOptionProvider, RequestInputProvider.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
jobs (Iterable[AsyncJob]): An iterable of AsyncJob objects representing the jobs to update.
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
None
|
|
181
|
+
"""
|
|
182
|
+
for job in jobs:
|
|
183
|
+
stream_slice = self._get_create_job_stream_slice(job)
|
|
184
|
+
polling_response: requests.Response = self._get_validated_polling_response(stream_slice)
|
|
185
|
+
job_status: AsyncJobStatus = self._get_validated_job_status(polling_response)
|
|
186
|
+
|
|
187
|
+
if job_status != job.status():
|
|
188
|
+
lazy_log(
|
|
189
|
+
LOGGER,
|
|
190
|
+
logging.DEBUG,
|
|
191
|
+
lambda: f"Status of job {job.api_job_id()} changed from {job.status()} to {job_status}",
|
|
192
|
+
)
|
|
193
|
+
else:
|
|
194
|
+
lazy_log(
|
|
195
|
+
LOGGER,
|
|
196
|
+
logging.DEBUG,
|
|
197
|
+
lambda: f"Status of job {job.api_job_id()} is still {job.status()}",
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
job.update_status(job_status)
|
|
201
|
+
if job_status == AsyncJobStatus.COMPLETED:
|
|
202
|
+
self._polling_job_response_by_id[job.api_job_id()] = polling_response
|
|
203
|
+
|
|
204
|
+
def fetch_records(self, job: AsyncJob) -> Iterable[Mapping[str, Any]]:
|
|
205
|
+
"""
|
|
206
|
+
Fetches records from the given job.
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
job (AsyncJob): The job to fetch records from.
|
|
210
|
+
|
|
211
|
+
Yields:
|
|
212
|
+
Iterable[Mapping[str, Any]]: A generator that yields records as dictionaries.
|
|
213
|
+
|
|
214
|
+
"""
|
|
215
|
+
|
|
216
|
+
for target_url in self._get_download_targets(job):
|
|
217
|
+
job_slice = job.job_parameters()
|
|
218
|
+
stream_slice = StreamSlice(
|
|
219
|
+
partition=job_slice.partition,
|
|
220
|
+
cursor_slice=job_slice.cursor_slice,
|
|
221
|
+
extra_fields={
|
|
222
|
+
**job_slice.extra_fields,
|
|
223
|
+
"download_target": target_url,
|
|
224
|
+
},
|
|
225
|
+
)
|
|
226
|
+
for message in self.download_retriever.read_records({}, stream_slice):
|
|
227
|
+
if isinstance(message, Record):
|
|
228
|
+
yield message.data
|
|
229
|
+
elif isinstance(message, AirbyteMessage):
|
|
230
|
+
if message.type == Type.RECORD:
|
|
231
|
+
yield message.record.data # type: ignore # message.record won't be None here as the message is a record
|
|
232
|
+
elif isinstance(message, (dict, Mapping)):
|
|
233
|
+
yield message
|
|
234
|
+
else:
|
|
235
|
+
raise TypeError(f"Unknown type `{type(message)}` for message")
|
|
236
|
+
|
|
237
|
+
yield from []
|
|
238
|
+
|
|
239
|
+
def abort(self, job: AsyncJob) -> None:
|
|
240
|
+
if not self.abort_requester:
|
|
241
|
+
return
|
|
242
|
+
|
|
243
|
+
abort_response = self.abort_requester.send_request(
|
|
244
|
+
stream_slice=self._get_create_job_stream_slice(job),
|
|
245
|
+
log_formatter=lambda abort_response: format_http_message(
|
|
246
|
+
response=abort_response,
|
|
247
|
+
title="Async Job -- Abort",
|
|
248
|
+
description="Abort the running server-side async job.",
|
|
249
|
+
stream_name=None,
|
|
250
|
+
is_auxiliary=True,
|
|
251
|
+
type="ASYNC_ABORT",
|
|
252
|
+
),
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
def delete(self, job: AsyncJob) -> None:
|
|
256
|
+
if not self.delete_requester:
|
|
257
|
+
return
|
|
258
|
+
|
|
259
|
+
delete_job_reponse = self.delete_requester.send_request(
|
|
260
|
+
stream_slice=self._get_create_job_stream_slice(job),
|
|
261
|
+
log_formatter=lambda delete_job_reponse: format_http_message(
|
|
262
|
+
response=delete_job_reponse,
|
|
263
|
+
title="Async Job -- Delete",
|
|
264
|
+
description="Delete the specified job from the list of Jobs.",
|
|
265
|
+
stream_name=None,
|
|
266
|
+
is_auxiliary=True,
|
|
267
|
+
type="ASYNC_DELETE",
|
|
268
|
+
),
|
|
269
|
+
)
|
|
270
|
+
self._clean_up_job(job.api_job_id())
|
|
271
|
+
|
|
272
|
+
def _clean_up_job(self, job_id: str) -> None:
|
|
273
|
+
del self._create_job_response_by_id[job_id]
|
|
274
|
+
del self._polling_job_response_by_id[job_id]
|
|
275
|
+
|
|
276
|
+
def _get_creation_response_interpolation_context(self, job: AsyncJob) -> Dict[str, Any]:
|
|
277
|
+
"""
|
|
278
|
+
Returns the interpolation context for the creation response.
|
|
279
|
+
|
|
280
|
+
Args:
|
|
281
|
+
job (AsyncJob): The job for which to get the creation response interpolation context.
|
|
282
|
+
|
|
283
|
+
Returns:
|
|
284
|
+
Dict[str, Any]: The interpolation context as a dictionary.
|
|
285
|
+
"""
|
|
286
|
+
# TODO: currently we support only JsonDecoder to decode the response to track the ids or the status
|
|
287
|
+
# of the Jobs. We should consider to add the support of other decoders like XMLDecoder, in the future
|
|
288
|
+
creation_response_context = dict(self._create_job_response_by_id[job.api_job_id()].json())
|
|
289
|
+
if not "headers" in creation_response_context:
|
|
290
|
+
creation_response_context["headers"] = self._create_job_response_by_id[
|
|
291
|
+
job.api_job_id()
|
|
292
|
+
].headers
|
|
293
|
+
if not "request" in creation_response_context:
|
|
294
|
+
creation_response_context["request"] = self._create_job_response_by_id[
|
|
295
|
+
job.api_job_id()
|
|
296
|
+
].request
|
|
297
|
+
return creation_response_context
|
|
298
|
+
|
|
299
|
+
def _get_polling_response_interpolation_context(self, job: AsyncJob) -> Dict[str, Any]:
|
|
300
|
+
"""
|
|
301
|
+
Returns the interpolation context for the polling response.
|
|
302
|
+
|
|
303
|
+
Args:
|
|
304
|
+
job (AsyncJob): The job for which to get the polling response interpolation context.
|
|
305
|
+
|
|
306
|
+
Returns:
|
|
307
|
+
Dict[str, Any]: The interpolation context as a dictionary.
|
|
308
|
+
"""
|
|
309
|
+
# TODO: currently we support only JsonDecoder to decode the response to track the ids or the status
|
|
310
|
+
# of the Jobs. We should consider to add the support of other decoders like XMLDecoder, in the future
|
|
311
|
+
polling_response_context = dict(self._polling_job_response_by_id[job.api_job_id()].json())
|
|
312
|
+
if not "headers" in polling_response_context:
|
|
313
|
+
polling_response_context["headers"] = self._polling_job_response_by_id[
|
|
314
|
+
job.api_job_id()
|
|
315
|
+
].headers
|
|
316
|
+
if not "request" in polling_response_context:
|
|
317
|
+
polling_response_context["request"] = self._polling_job_response_by_id[
|
|
318
|
+
job.api_job_id()
|
|
319
|
+
].request
|
|
320
|
+
return polling_response_context
|
|
321
|
+
|
|
322
|
+
def _get_create_job_stream_slice(self, job: AsyncJob) -> StreamSlice:
|
|
323
|
+
stream_slice = StreamSlice(
|
|
324
|
+
partition={},
|
|
325
|
+
cursor_slice={},
|
|
326
|
+
extra_fields={
|
|
327
|
+
"creation_response": self._get_creation_response_interpolation_context(job),
|
|
328
|
+
},
|
|
329
|
+
)
|
|
330
|
+
return stream_slice
|
|
331
|
+
|
|
332
|
+
def _get_download_targets(self, job: AsyncJob) -> Iterable[str]:
|
|
333
|
+
if not self.download_target_requester:
|
|
334
|
+
url_response = self._polling_job_response_by_id[job.api_job_id()]
|
|
335
|
+
else:
|
|
336
|
+
stream_slice: StreamSlice = StreamSlice(
|
|
337
|
+
partition={},
|
|
338
|
+
cursor_slice={},
|
|
339
|
+
extra_fields={
|
|
340
|
+
"polling_response": self._get_polling_response_interpolation_context(job),
|
|
341
|
+
},
|
|
342
|
+
)
|
|
343
|
+
url_response = self.download_target_requester.send_request(stream_slice=stream_slice) # type: ignore # we expect download_target_requester to always be presented, otherwise raise an exception as we cannot proceed with the report
|
|
344
|
+
if not url_response:
|
|
345
|
+
raise AirbyteTracedException(
|
|
346
|
+
internal_message="Always expect a response or an exception from download_target_requester",
|
|
347
|
+
failure_type=FailureType.system_error,
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
yield from self.download_target_extractor.extract_records(url_response) # type: ignore # we expect download_target_extractor to always return list of strings
|