airbyte-cdk 0.72.1__py3-none-any.whl → 6.17.1.dev1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- airbyte_cdk/__init__.py +355 -6
- 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 +230 -0
- airbyte_cdk/cli/source_declarative_manifest/spec.json +17 -0
- airbyte_cdk/config_observation.py +29 -10
- airbyte_cdk/connector.py +24 -24
- airbyte_cdk/connector_builder/README.md +53 -0
- airbyte_cdk/connector_builder/connector_builder_handler.py +37 -11
- airbyte_cdk/connector_builder/main.py +45 -13
- airbyte_cdk/connector_builder/message_grouper.py +189 -50
- airbyte_cdk/connector_builder/models.py +3 -2
- airbyte_cdk/destinations/__init__.py +4 -3
- airbyte_cdk/destinations/destination.py +54 -20
- airbyte_cdk/destinations/vector_db_based/README.md +37 -0
- airbyte_cdk/destinations/vector_db_based/config.py +40 -17
- airbyte_cdk/destinations/vector_db_based/document_processor.py +56 -17
- airbyte_cdk/destinations/vector_db_based/embedder.py +57 -15
- airbyte_cdk/destinations/vector_db_based/test_utils.py +14 -4
- airbyte_cdk/destinations/vector_db_based/utils.py +8 -2
- airbyte_cdk/destinations/vector_db_based/writer.py +24 -5
- airbyte_cdk/entrypoint.py +153 -44
- airbyte_cdk/exception_handler.py +21 -3
- airbyte_cdk/logger.py +30 -44
- airbyte_cdk/models/__init__.py +13 -2
- airbyte_cdk/models/airbyte_protocol.py +86 -1
- airbyte_cdk/models/airbyte_protocol_serializers.py +44 -0
- airbyte_cdk/models/file_transfer_record_message.py +13 -0
- airbyte_cdk/models/well_known_types.py +1 -1
- airbyte_cdk/sources/__init__.py +5 -1
- airbyte_cdk/sources/abstract_source.py +125 -79
- airbyte_cdk/sources/concurrent_source/__init__.py +7 -2
- airbyte_cdk/sources/concurrent_source/concurrent_read_processor.py +102 -36
- airbyte_cdk/sources/concurrent_source/concurrent_source.py +29 -36
- airbyte_cdk/sources/concurrent_source/concurrent_source_adapter.py +94 -10
- airbyte_cdk/sources/concurrent_source/stream_thread_exception.py +25 -0
- airbyte_cdk/sources/concurrent_source/thread_pool_manager.py +20 -14
- airbyte_cdk/sources/config.py +3 -2
- airbyte_cdk/sources/connector_state_manager.py +49 -83
- airbyte_cdk/sources/declarative/async_job/job.py +52 -0
- airbyte_cdk/sources/declarative/async_job/job_orchestrator.py +497 -0
- airbyte_cdk/sources/declarative/async_job/job_tracker.py +75 -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 +2 -3
- airbyte_cdk/sources/declarative/auth/declarative_authenticator.py +3 -1
- airbyte_cdk/sources/declarative/auth/jwt.py +191 -0
- airbyte_cdk/sources/declarative/auth/oauth.py +60 -20
- airbyte_cdk/sources/declarative/auth/selective_authenticator.py +10 -2
- airbyte_cdk/sources/declarative/auth/token.py +28 -10
- airbyte_cdk/sources/declarative/auth/token_provider.py +9 -8
- airbyte_cdk/sources/declarative/checks/check_stream.py +16 -8
- airbyte_cdk/sources/declarative/checks/connection_checker.py +4 -2
- 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 +490 -0
- airbyte_cdk/sources/declarative/datetime/datetime_parser.py +4 -0
- airbyte_cdk/sources/declarative/datetime/min_max_datetime.py +26 -6
- airbyte_cdk/sources/declarative/declarative_component_schema.yaml +1185 -85
- airbyte_cdk/sources/declarative/declarative_source.py +5 -2
- airbyte_cdk/sources/declarative/declarative_stream.py +95 -9
- airbyte_cdk/sources/declarative/decoders/__init__.py +23 -2
- airbyte_cdk/sources/declarative/decoders/composite_raw_decoder.py +97 -0
- airbyte_cdk/sources/declarative/decoders/decoder.py +11 -4
- airbyte_cdk/sources/declarative/decoders/json_decoder.py +92 -5
- 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/extractors/__init__.py +12 -1
- airbyte_cdk/sources/declarative/extractors/dpath_extractor.py +29 -24
- airbyte_cdk/sources/declarative/extractors/http_selector.py +4 -5
- airbyte_cdk/sources/declarative/extractors/record_extractor.py +2 -3
- airbyte_cdk/sources/declarative/extractors/record_filter.py +63 -8
- airbyte_cdk/sources/declarative/extractors/record_selector.py +85 -26
- airbyte_cdk/sources/declarative/extractors/response_to_file_extractor.py +177 -0
- airbyte_cdk/sources/declarative/extractors/type_transformer.py +55 -0
- airbyte_cdk/sources/declarative/incremental/__init__.py +31 -3
- airbyte_cdk/sources/declarative/incremental/concurrent_partition_cursor.py +340 -0
- airbyte_cdk/sources/declarative/incremental/datetime_based_cursor.py +156 -48
- airbyte_cdk/sources/declarative/incremental/declarative_cursor.py +13 -0
- airbyte_cdk/sources/declarative/incremental/global_substream_cursor.py +350 -0
- airbyte_cdk/sources/declarative/incremental/per_partition_cursor.py +174 -74
- 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/filters.py +27 -1
- airbyte_cdk/sources/declarative/interpolation/interpolated_boolean.py +23 -5
- airbyte_cdk/sources/declarative/interpolation/interpolated_mapping.py +12 -8
- airbyte_cdk/sources/declarative/interpolation/interpolated_nested_mapping.py +13 -6
- airbyte_cdk/sources/declarative/interpolation/interpolated_string.py +21 -6
- airbyte_cdk/sources/declarative/interpolation/interpolation.py +9 -3
- airbyte_cdk/sources/declarative/interpolation/jinja.py +72 -37
- airbyte_cdk/sources/declarative/interpolation/macros.py +72 -17
- airbyte_cdk/sources/declarative/manifest_declarative_source.py +193 -52
- 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 +1 -1
- airbyte_cdk/sources/declarative/models/declarative_component_schema.py +1319 -603
- airbyte_cdk/sources/declarative/parsers/custom_exceptions.py +2 -2
- airbyte_cdk/sources/declarative/parsers/manifest_component_transformer.py +26 -4
- airbyte_cdk/sources/declarative/parsers/manifest_reference_resolver.py +26 -15
- airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py +1759 -225
- airbyte_cdk/sources/declarative/partition_routers/__init__.py +24 -4
- 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 +39 -9
- airbyte_cdk/sources/declarative/partition_routers/partition_router.py +62 -0
- airbyte_cdk/sources/declarative/partition_routers/single_partition_router.py +15 -3
- airbyte_cdk/sources/declarative/partition_routers/substream_partition_router.py +222 -39
- airbyte_cdk/sources/declarative/requesters/error_handlers/__init__.py +19 -5
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/__init__.py +3 -1
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/constant_backoff_strategy.py +19 -7
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/exponential_backoff_strategy.py +19 -7
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/header_helper.py +4 -2
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/wait_time_from_header_backoff_strategy.py +41 -9
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/wait_until_time_from_header_backoff_strategy.py +29 -14
- airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategy.py +5 -13
- airbyte_cdk/sources/declarative/requesters/error_handlers/composite_error_handler.py +32 -16
- airbyte_cdk/sources/declarative/requesters/error_handlers/default_error_handler.py +46 -56
- airbyte_cdk/sources/declarative/requesters/error_handlers/default_http_response_filter.py +40 -0
- airbyte_cdk/sources/declarative/requesters/error_handlers/error_handler.py +6 -32
- airbyte_cdk/sources/declarative/requesters/error_handlers/http_response_filter.py +119 -41
- airbyte_cdk/sources/declarative/requesters/http_job_repository.py +228 -0
- airbyte_cdk/sources/declarative/requesters/http_requester.py +98 -344
- airbyte_cdk/sources/declarative/requesters/paginators/__init__.py +14 -3
- airbyte_cdk/sources/declarative/requesters/paginators/default_paginator.py +105 -46
- airbyte_cdk/sources/declarative/requesters/paginators/no_pagination.py +14 -8
- airbyte_cdk/sources/declarative/requesters/paginators/paginator.py +19 -8
- airbyte_cdk/sources/declarative/requesters/paginators/strategies/__init__.py +9 -3
- airbyte_cdk/sources/declarative/requesters/paginators/strategies/cursor_pagination_strategy.py +53 -21
- airbyte_cdk/sources/declarative/requesters/paginators/strategies/offset_increment.py +42 -19
- airbyte_cdk/sources/declarative/requesters/paginators/strategies/page_increment.py +25 -12
- airbyte_cdk/sources/declarative/requesters/paginators/strategies/pagination_strategy.py +13 -10
- airbyte_cdk/sources/declarative/requesters/paginators/strategies/stop_condition.py +26 -13
- airbyte_cdk/sources/declarative/requesters/request_options/__init__.py +15 -2
- airbyte_cdk/sources/declarative/requesters/request_options/datetime_based_request_options_provider.py +91 -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 +31 -14
- airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_input_provider.py +27 -15
- airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py +63 -10
- airbyte_cdk/sources/declarative/requesters/request_options/request_options_provider.py +1 -1
- airbyte_cdk/sources/declarative/requesters/requester.py +9 -17
- 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 +6 -2
- airbyte_cdk/sources/declarative/retrievers/async_retriever.py +100 -0
- airbyte_cdk/sources/declarative/retrievers/retriever.py +1 -3
- airbyte_cdk/sources/declarative/retrievers/simple_retriever.py +229 -73
- airbyte_cdk/sources/declarative/schema/__init__.py +14 -1
- airbyte_cdk/sources/declarative/schema/default_schema_loader.py +5 -3
- airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py +236 -0
- airbyte_cdk/sources/declarative/schema/json_file_schema_loader.py +8 -8
- airbyte_cdk/sources/declarative/spec/spec.py +12 -5
- airbyte_cdk/sources/declarative/stream_slicers/__init__.py +1 -2
- airbyte_cdk/sources/declarative/stream_slicers/declarative_partition_generator.py +88 -0
- airbyte_cdk/sources/declarative/stream_slicers/stream_slicer.py +9 -14
- airbyte_cdk/sources/declarative/transformations/add_fields.py +19 -11
- 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 +13 -10
- airbyte_cdk/sources/declarative/transformations/transformation.py +5 -5
- airbyte_cdk/sources/declarative/types.py +19 -110
- airbyte_cdk/sources/declarative/yaml_declarative_source.py +31 -10
- airbyte_cdk/sources/embedded/base_integration.py +16 -5
- airbyte_cdk/sources/embedded/catalog.py +16 -4
- airbyte_cdk/sources/embedded/runner.py +19 -3
- airbyte_cdk/sources/embedded/tools.py +5 -2
- 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 +9 -2
- airbyte_cdk/sources/file_based/availability_strategy/abstract_file_based_availability_strategy.py +22 -6
- airbyte_cdk/sources/file_based/availability_strategy/default_file_based_availability_strategy.py +46 -10
- airbyte_cdk/sources/file_based/config/abstract_file_based_spec.py +47 -10
- airbyte_cdk/sources/file_based/config/avro_format.py +2 -1
- airbyte_cdk/sources/file_based/config/csv_format.py +29 -10
- airbyte_cdk/sources/file_based/config/excel_format.py +18 -0
- airbyte_cdk/sources/file_based/config/file_based_stream_config.py +16 -4
- airbyte_cdk/sources/file_based/config/jsonl_format.py +2 -1
- airbyte_cdk/sources/file_based/config/parquet_format.py +2 -1
- airbyte_cdk/sources/file_based/config/unstructured_format.py +13 -5
- airbyte_cdk/sources/file_based/discovery_policy/__init__.py +6 -2
- airbyte_cdk/sources/file_based/discovery_policy/abstract_discovery_policy.py +2 -4
- airbyte_cdk/sources/file_based/discovery_policy/default_discovery_policy.py +7 -2
- airbyte_cdk/sources/file_based/exceptions.py +18 -15
- airbyte_cdk/sources/file_based/file_based_source.py +140 -33
- airbyte_cdk/sources/file_based/file_based_stream_reader.py +69 -5
- airbyte_cdk/sources/file_based/file_types/__init__.py +14 -1
- airbyte_cdk/sources/file_based/file_types/avro_parser.py +75 -24
- airbyte_cdk/sources/file_based/file_types/csv_parser.py +116 -34
- airbyte_cdk/sources/file_based/file_types/excel_parser.py +196 -0
- airbyte_cdk/sources/file_based/file_types/file_transfer.py +37 -0
- airbyte_cdk/sources/file_based/file_types/file_type_parser.py +4 -1
- airbyte_cdk/sources/file_based/file_types/jsonl_parser.py +24 -8
- airbyte_cdk/sources/file_based/file_types/parquet_parser.py +60 -18
- airbyte_cdk/sources/file_based/file_types/unstructured_parser.py +141 -41
- airbyte_cdk/sources/file_based/remote_file.py +1 -1
- airbyte_cdk/sources/file_based/schema_helpers.py +38 -10
- airbyte_cdk/sources/file_based/schema_validation_policies/__init__.py +3 -1
- airbyte_cdk/sources/file_based/schema_validation_policies/abstract_schema_validation_policy.py +3 -1
- airbyte_cdk/sources/file_based/schema_validation_policies/default_schema_validation_policies.py +16 -5
- airbyte_cdk/sources/file_based/stream/abstract_file_based_stream.py +50 -13
- airbyte_cdk/sources/file_based/stream/concurrent/adapters.py +67 -27
- airbyte_cdk/sources/file_based/stream/concurrent/cursor/__init__.py +5 -1
- airbyte_cdk/sources/file_based/stream/concurrent/cursor/abstract_concurrent_file_based_cursor.py +14 -23
- airbyte_cdk/sources/file_based/stream/concurrent/cursor/file_based_concurrent_cursor.py +54 -18
- airbyte_cdk/sources/file_based/stream/concurrent/cursor/file_based_final_state_cursor.py +21 -9
- airbyte_cdk/sources/file_based/stream/cursor/abstract_file_based_cursor.py +3 -1
- airbyte_cdk/sources/file_based/stream/cursor/default_file_based_cursor.py +27 -10
- airbyte_cdk/sources/file_based/stream/default_file_based_stream.py +147 -45
- airbyte_cdk/sources/http_logger.py +8 -3
- airbyte_cdk/sources/message/__init__.py +7 -1
- airbyte_cdk/sources/message/repository.py +18 -4
- airbyte_cdk/sources/source.py +42 -38
- airbyte_cdk/sources/streams/__init__.py +2 -2
- airbyte_cdk/sources/streams/availability_strategy.py +54 -3
- airbyte_cdk/sources/streams/call_rate.py +64 -21
- airbyte_cdk/sources/streams/checkpoint/__init__.py +26 -0
- airbyte_cdk/sources/streams/checkpoint/checkpoint_reader.py +335 -0
- airbyte_cdk/sources/{declarative/incremental → streams/checkpoint}/cursor.py +17 -14
- 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/abstract_stream.py +7 -2
- airbyte_cdk/sources/streams/concurrent/adapters.py +84 -75
- airbyte_cdk/sources/streams/concurrent/availability_strategy.py +30 -2
- airbyte_cdk/sources/streams/concurrent/cursor.py +313 -48
- airbyte_cdk/sources/streams/concurrent/default_stream.py +12 -3
- airbyte_cdk/sources/streams/concurrent/exceptions.py +3 -0
- airbyte_cdk/sources/streams/concurrent/helpers.py +14 -3
- airbyte_cdk/sources/streams/concurrent/partition_enqueuer.py +12 -3
- airbyte_cdk/sources/streams/concurrent/partition_reader.py +10 -3
- airbyte_cdk/sources/streams/concurrent/partitions/partition.py +1 -16
- airbyte_cdk/sources/streams/concurrent/partitions/stream_slicer.py +21 -0
- airbyte_cdk/sources/streams/concurrent/partitions/types.py +15 -5
- airbyte_cdk/sources/streams/concurrent/state_converters/abstract_stream_state_converter.py +109 -17
- airbyte_cdk/sources/streams/concurrent/state_converters/datetime_stream_state_converter.py +90 -72
- airbyte_cdk/sources/streams/core.py +412 -87
- airbyte_cdk/sources/streams/http/__init__.py +2 -1
- airbyte_cdk/sources/streams/http/availability_strategy.py +12 -101
- 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 +27 -7
- airbyte_cdk/sources/streams/http/http.py +369 -246
- airbyte_cdk/sources/streams/http/http_client.py +531 -0
- airbyte_cdk/sources/streams/http/rate_limiting.py +76 -12
- airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +28 -9
- airbyte_cdk/sources/streams/http/requests_native_auth/abstract_token.py +2 -1
- airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py +90 -35
- airbyte_cdk/sources/streams/http/requests_native_auth/token.py +13 -3
- airbyte_cdk/sources/types.py +154 -0
- airbyte_cdk/sources/utils/record_helper.py +36 -21
- airbyte_cdk/sources/utils/schema_helpers.py +13 -6
- airbyte_cdk/sources/utils/slice_logger.py +4 -1
- airbyte_cdk/sources/utils/transform.py +54 -20
- 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/catalog_builder.py +70 -18
- airbyte_cdk/test/entrypoint_wrapper.py +117 -42
- airbyte_cdk/test/mock_http/__init__.py +1 -1
- airbyte_cdk/test/mock_http/matcher.py +6 -0
- airbyte_cdk/test/mock_http/mocker.py +57 -10
- airbyte_cdk/test/mock_http/request.py +19 -3
- airbyte_cdk/test/mock_http/response.py +3 -1
- airbyte_cdk/test/mock_http/response_builder.py +32 -16
- airbyte_cdk/test/state_builder.py +18 -10
- 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 +60 -0
- airbyte_cdk/test/utils/reading.py +26 -0
- airbyte_cdk/utils/__init__.py +2 -1
- airbyte_cdk/utils/airbyte_secrets_utils.py +5 -3
- airbyte_cdk/utils/analytics_message.py +10 -2
- airbyte_cdk/utils/datetime_format_inferrer.py +4 -1
- airbyte_cdk/utils/event_timing.py +10 -10
- airbyte_cdk/utils/mapping_helpers.py +3 -1
- airbyte_cdk/utils/message_utils.py +20 -11
- airbyte_cdk/utils/print_buffer.py +75 -0
- airbyte_cdk/utils/schema_inferrer.py +198 -28
- airbyte_cdk/utils/slice_hasher.py +30 -0
- airbyte_cdk/utils/spec_schema_transformations.py +6 -3
- airbyte_cdk/utils/stream_status_utils.py +8 -1
- airbyte_cdk/utils/traced_exception.py +61 -21
- airbyte_cdk-6.17.1.dev1.dist-info/METADATA +109 -0
- airbyte_cdk-6.17.1.dev1.dist-info/RECORD +350 -0
- {airbyte_cdk-0.72.1.dist-info → airbyte_cdk-6.17.1.dev1.dist-info}/WHEEL +1 -2
- airbyte_cdk-6.17.1.dev1.dist-info/entry_points.txt +3 -0
- airbyte_cdk/sources/declarative/create_partial.py +0 -92
- airbyte_cdk/sources/declarative/parsers/class_types_registry.py +0 -102
- airbyte_cdk/sources/declarative/parsers/default_implementation_registry.py +0 -64
- airbyte_cdk/sources/declarative/requesters/error_handlers/response_action.py +0 -16
- airbyte_cdk/sources/declarative/requesters/error_handlers/response_status.py +0 -68
- airbyte_cdk/sources/declarative/stream_slicers/cartesian_product_stream_slicer.py +0 -114
- airbyte_cdk/sources/deprecated/base_source.py +0 -94
- airbyte_cdk/sources/deprecated/client.py +0 -99
- airbyte_cdk/sources/singer/__init__.py +0 -8
- airbyte_cdk/sources/singer/singer_helpers.py +0 -304
- airbyte_cdk/sources/singer/source.py +0 -186
- airbyte_cdk/sources/streams/concurrent/partitions/record.py +0 -23
- airbyte_cdk/sources/streams/http/auth/__init__.py +0 -17
- airbyte_cdk/sources/streams/http/auth/core.py +0 -29
- airbyte_cdk/sources/streams/http/auth/oauth.py +0 -113
- airbyte_cdk/sources/streams/http/auth/token.py +0 -47
- airbyte_cdk/sources/streams/utils/stream_helper.py +0 -40
- airbyte_cdk/sources/utils/catalog_helpers.py +0 -22
- airbyte_cdk/sources/utils/schema_models.py +0 -84
- airbyte_cdk-0.72.1.dist-info/METADATA +0 -243
- airbyte_cdk-0.72.1.dist-info/RECORD +0 -466
- airbyte_cdk-0.72.1.dist-info/top_level.txt +0 -3
- source_declarative_manifest/main.py +0 -29
- unit_tests/connector_builder/__init__.py +0 -3
- unit_tests/connector_builder/test_connector_builder_handler.py +0 -871
- unit_tests/connector_builder/test_message_grouper.py +0 -713
- unit_tests/connector_builder/utils.py +0 -27
- unit_tests/destinations/test_destination.py +0 -243
- unit_tests/singer/test_singer_helpers.py +0 -56
- unit_tests/singer/test_singer_source.py +0 -112
- unit_tests/sources/__init__.py +0 -0
- unit_tests/sources/concurrent_source/__init__.py +0 -3
- unit_tests/sources/concurrent_source/test_concurrent_source_adapter.py +0 -106
- unit_tests/sources/declarative/__init__.py +0 -3
- unit_tests/sources/declarative/auth/__init__.py +0 -3
- unit_tests/sources/declarative/auth/test_oauth.py +0 -331
- unit_tests/sources/declarative/auth/test_selective_authenticator.py +0 -39
- unit_tests/sources/declarative/auth/test_session_token_auth.py +0 -182
- unit_tests/sources/declarative/auth/test_token_auth.py +0 -200
- unit_tests/sources/declarative/auth/test_token_provider.py +0 -73
- unit_tests/sources/declarative/checks/__init__.py +0 -3
- unit_tests/sources/declarative/checks/test_check_stream.py +0 -146
- unit_tests/sources/declarative/decoders/__init__.py +0 -0
- unit_tests/sources/declarative/decoders/test_json_decoder.py +0 -16
- unit_tests/sources/declarative/external_component.py +0 -13
- unit_tests/sources/declarative/extractors/__init__.py +0 -3
- unit_tests/sources/declarative/extractors/test_dpath_extractor.py +0 -55
- unit_tests/sources/declarative/extractors/test_record_filter.py +0 -55
- unit_tests/sources/declarative/extractors/test_record_selector.py +0 -179
- unit_tests/sources/declarative/incremental/__init__.py +0 -0
- unit_tests/sources/declarative/incremental/test_datetime_based_cursor.py +0 -860
- unit_tests/sources/declarative/incremental/test_per_partition_cursor.py +0 -406
- unit_tests/sources/declarative/incremental/test_per_partition_cursor_integration.py +0 -332
- unit_tests/sources/declarative/interpolation/__init__.py +0 -3
- unit_tests/sources/declarative/interpolation/test_filters.py +0 -80
- unit_tests/sources/declarative/interpolation/test_interpolated_boolean.py +0 -40
- unit_tests/sources/declarative/interpolation/test_interpolated_mapping.py +0 -35
- unit_tests/sources/declarative/interpolation/test_interpolated_nested_mapping.py +0 -45
- unit_tests/sources/declarative/interpolation/test_interpolated_string.py +0 -25
- unit_tests/sources/declarative/interpolation/test_jinja.py +0 -240
- unit_tests/sources/declarative/interpolation/test_macros.py +0 -73
- unit_tests/sources/declarative/parsers/__init__.py +0 -3
- unit_tests/sources/declarative/parsers/test_manifest_component_transformer.py +0 -406
- unit_tests/sources/declarative/parsers/test_manifest_reference_resolver.py +0 -139
- unit_tests/sources/declarative/parsers/test_model_to_component_factory.py +0 -1847
- unit_tests/sources/declarative/parsers/testing_components.py +0 -36
- unit_tests/sources/declarative/partition_routers/__init__.py +0 -3
- unit_tests/sources/declarative/partition_routers/test_list_partition_router.py +0 -155
- unit_tests/sources/declarative/partition_routers/test_single_partition_router.py +0 -14
- unit_tests/sources/declarative/partition_routers/test_substream_partition_router.py +0 -404
- unit_tests/sources/declarative/requesters/__init__.py +0 -3
- unit_tests/sources/declarative/requesters/error_handlers/__init__.py +0 -3
- unit_tests/sources/declarative/requesters/error_handlers/backoff_strategies/__init__.py +0 -3
- unit_tests/sources/declarative/requesters/error_handlers/backoff_strategies/test_constant_backoff.py +0 -34
- unit_tests/sources/declarative/requesters/error_handlers/backoff_strategies/test_exponential_backoff.py +0 -36
- unit_tests/sources/declarative/requesters/error_handlers/backoff_strategies/test_header_helper.py +0 -38
- unit_tests/sources/declarative/requesters/error_handlers/backoff_strategies/test_wait_time_from_header.py +0 -35
- unit_tests/sources/declarative/requesters/error_handlers/backoff_strategies/test_wait_until_time_from_header.py +0 -64
- unit_tests/sources/declarative/requesters/error_handlers/test_composite_error_handler.py +0 -213
- unit_tests/sources/declarative/requesters/error_handlers/test_default_error_handler.py +0 -178
- unit_tests/sources/declarative/requesters/error_handlers/test_http_response_filter.py +0 -121
- unit_tests/sources/declarative/requesters/error_handlers/test_response_status.py +0 -44
- unit_tests/sources/declarative/requesters/paginators/__init__.py +0 -3
- unit_tests/sources/declarative/requesters/paginators/test_cursor_pagination_strategy.py +0 -64
- unit_tests/sources/declarative/requesters/paginators/test_default_paginator.py +0 -313
- unit_tests/sources/declarative/requesters/paginators/test_no_paginator.py +0 -12
- unit_tests/sources/declarative/requesters/paginators/test_offset_increment.py +0 -58
- unit_tests/sources/declarative/requesters/paginators/test_page_increment.py +0 -70
- unit_tests/sources/declarative/requesters/paginators/test_request_option.py +0 -43
- unit_tests/sources/declarative/requesters/paginators/test_stop_condition.py +0 -105
- unit_tests/sources/declarative/requesters/request_options/__init__.py +0 -3
- unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py +0 -101
- unit_tests/sources/declarative/requesters/test_http_requester.py +0 -974
- unit_tests/sources/declarative/requesters/test_interpolated_request_input_provider.py +0 -32
- unit_tests/sources/declarative/retrievers/__init__.py +0 -3
- unit_tests/sources/declarative/retrievers/test_simple_retriever.py +0 -542
- unit_tests/sources/declarative/schema/__init__.py +0 -6
- unit_tests/sources/declarative/schema/source_test/SourceTest.py +0 -8
- unit_tests/sources/declarative/schema/source_test/__init__.py +0 -3
- unit_tests/sources/declarative/schema/test_default_schema_loader.py +0 -32
- unit_tests/sources/declarative/schema/test_inline_schema_loader.py +0 -19
- unit_tests/sources/declarative/schema/test_json_file_schema_loader.py +0 -26
- unit_tests/sources/declarative/states/__init__.py +0 -3
- unit_tests/sources/declarative/stream_slicers/__init__.py +0 -3
- unit_tests/sources/declarative/stream_slicers/test_cartesian_product_stream_slicer.py +0 -225
- unit_tests/sources/declarative/test_create_partial.py +0 -83
- unit_tests/sources/declarative/test_declarative_stream.py +0 -103
- unit_tests/sources/declarative/test_manifest_declarative_source.py +0 -1260
- unit_tests/sources/declarative/test_types.py +0 -39
- unit_tests/sources/declarative/test_yaml_declarative_source.py +0 -148
- unit_tests/sources/file_based/__init__.py +0 -0
- unit_tests/sources/file_based/availability_strategy/__init__.py +0 -0
- unit_tests/sources/file_based/availability_strategy/test_default_file_based_availability_strategy.py +0 -100
- unit_tests/sources/file_based/config/__init__.py +0 -0
- unit_tests/sources/file_based/config/test_abstract_file_based_spec.py +0 -28
- unit_tests/sources/file_based/config/test_csv_format.py +0 -34
- unit_tests/sources/file_based/config/test_file_based_stream_config.py +0 -84
- unit_tests/sources/file_based/discovery_policy/__init__.py +0 -0
- unit_tests/sources/file_based/discovery_policy/test_default_discovery_policy.py +0 -31
- unit_tests/sources/file_based/file_types/__init__.py +0 -0
- unit_tests/sources/file_based/file_types/test_avro_parser.py +0 -243
- unit_tests/sources/file_based/file_types/test_csv_parser.py +0 -546
- unit_tests/sources/file_based/file_types/test_jsonl_parser.py +0 -158
- unit_tests/sources/file_based/file_types/test_parquet_parser.py +0 -274
- unit_tests/sources/file_based/file_types/test_unstructured_parser.py +0 -593
- unit_tests/sources/file_based/helpers.py +0 -70
- unit_tests/sources/file_based/in_memory_files_source.py +0 -211
- unit_tests/sources/file_based/scenarios/__init__.py +0 -0
- unit_tests/sources/file_based/scenarios/avro_scenarios.py +0 -744
- unit_tests/sources/file_based/scenarios/check_scenarios.py +0 -220
- unit_tests/sources/file_based/scenarios/concurrent_incremental_scenarios.py +0 -2844
- unit_tests/sources/file_based/scenarios/csv_scenarios.py +0 -3105
- unit_tests/sources/file_based/scenarios/file_based_source_builder.py +0 -91
- unit_tests/sources/file_based/scenarios/incremental_scenarios.py +0 -1926
- unit_tests/sources/file_based/scenarios/jsonl_scenarios.py +0 -930
- unit_tests/sources/file_based/scenarios/parquet_scenarios.py +0 -754
- unit_tests/sources/file_based/scenarios/scenario_builder.py +0 -234
- unit_tests/sources/file_based/scenarios/unstructured_scenarios.py +0 -608
- unit_tests/sources/file_based/scenarios/user_input_schema_scenarios.py +0 -746
- unit_tests/sources/file_based/scenarios/validation_policy_scenarios.py +0 -726
- unit_tests/sources/file_based/stream/__init__.py +0 -0
- unit_tests/sources/file_based/stream/concurrent/__init__.py +0 -0
- unit_tests/sources/file_based/stream/concurrent/test_adapters.py +0 -362
- unit_tests/sources/file_based/stream/concurrent/test_file_based_concurrent_cursor.py +0 -458
- unit_tests/sources/file_based/stream/test_default_file_based_cursor.py +0 -310
- unit_tests/sources/file_based/stream/test_default_file_based_stream.py +0 -244
- unit_tests/sources/file_based/test_file_based_scenarios.py +0 -320
- unit_tests/sources/file_based/test_file_based_stream_reader.py +0 -272
- unit_tests/sources/file_based/test_scenarios.py +0 -253
- unit_tests/sources/file_based/test_schema_helpers.py +0 -346
- unit_tests/sources/fixtures/__init__.py +0 -3
- unit_tests/sources/fixtures/source_test_fixture.py +0 -153
- unit_tests/sources/message/__init__.py +0 -0
- unit_tests/sources/message/test_repository.py +0 -153
- unit_tests/sources/streams/__init__.py +0 -0
- unit_tests/sources/streams/concurrent/__init__.py +0 -3
- unit_tests/sources/streams/concurrent/scenarios/__init__.py +0 -3
- unit_tests/sources/streams/concurrent/scenarios/incremental_scenarios.py +0 -250
- unit_tests/sources/streams/concurrent/scenarios/stream_facade_builder.py +0 -140
- unit_tests/sources/streams/concurrent/scenarios/stream_facade_scenarios.py +0 -452
- unit_tests/sources/streams/concurrent/scenarios/test_concurrent_scenarios.py +0 -76
- unit_tests/sources/streams/concurrent/scenarios/thread_based_concurrent_stream_scenarios.py +0 -418
- unit_tests/sources/streams/concurrent/scenarios/thread_based_concurrent_stream_source_builder.py +0 -142
- unit_tests/sources/streams/concurrent/scenarios/utils.py +0 -55
- unit_tests/sources/streams/concurrent/test_adapters.py +0 -380
- unit_tests/sources/streams/concurrent/test_concurrent_read_processor.py +0 -684
- unit_tests/sources/streams/concurrent/test_cursor.py +0 -139
- unit_tests/sources/streams/concurrent/test_datetime_state_converter.py +0 -369
- unit_tests/sources/streams/concurrent/test_default_stream.py +0 -197
- unit_tests/sources/streams/concurrent/test_partition_enqueuer.py +0 -90
- unit_tests/sources/streams/concurrent/test_partition_reader.py +0 -67
- unit_tests/sources/streams/concurrent/test_thread_pool_manager.py +0 -106
- unit_tests/sources/streams/http/__init__.py +0 -0
- unit_tests/sources/streams/http/auth/__init__.py +0 -0
- unit_tests/sources/streams/http/auth/test_auth.py +0 -173
- unit_tests/sources/streams/http/requests_native_auth/__init__.py +0 -0
- unit_tests/sources/streams/http/requests_native_auth/test_requests_native_auth.py +0 -423
- unit_tests/sources/streams/http/test_availability_strategy.py +0 -180
- unit_tests/sources/streams/http/test_http.py +0 -635
- unit_tests/sources/streams/test_availability_strategy.py +0 -70
- unit_tests/sources/streams/test_call_rate.py +0 -300
- unit_tests/sources/streams/test_stream_read.py +0 -405
- unit_tests/sources/streams/test_streams_core.py +0 -184
- unit_tests/sources/test_abstract_source.py +0 -1442
- unit_tests/sources/test_concurrent_source.py +0 -112
- unit_tests/sources/test_config.py +0 -92
- unit_tests/sources/test_connector_state_manager.py +0 -482
- unit_tests/sources/test_http_logger.py +0 -252
- unit_tests/sources/test_integration_source.py +0 -86
- unit_tests/sources/test_source.py +0 -684
- unit_tests/sources/test_source_read.py +0 -460
- unit_tests/test/__init__.py +0 -0
- unit_tests/test/mock_http/__init__.py +0 -0
- unit_tests/test/mock_http/test_matcher.py +0 -53
- unit_tests/test/mock_http/test_mocker.py +0 -214
- unit_tests/test/mock_http/test_request.py +0 -117
- unit_tests/test/mock_http/test_response_builder.py +0 -177
- unit_tests/test/test_entrypoint_wrapper.py +0 -240
- unit_tests/utils/__init__.py +0 -0
- unit_tests/utils/test_datetime_format_inferrer.py +0 -60
- unit_tests/utils/test_mapping_helpers.py +0 -54
- unit_tests/utils/test_message_utils.py +0 -91
- unit_tests/utils/test_rate_limiting.py +0 -26
- unit_tests/utils/test_schema_inferrer.py +0 -202
- unit_tests/utils/test_secret_utils.py +0 -135
- unit_tests/utils/test_stream_status_utils.py +0 -61
- unit_tests/utils/test_traced_exception.py +0 -107
- /airbyte_cdk/sources/{deprecated → declarative/async_job}/__init__.py +0 -0
- {source_declarative_manifest → airbyte_cdk/sources/declarative/migrations}/__init__.py +0 -0
- {unit_tests/destinations → airbyte_cdk/sql}/__init__.py +0 -0
- {unit_tests/singer → airbyte_cdk/sql/_util}/__init__.py +0 -0
- {airbyte_cdk-0.72.1.dist-info → airbyte_cdk-6.17.1.dev1.dist-info}/LICENSE.txt +0 -0
@@ -3,13 +3,17 @@
|
|
3
3
|
#
|
4
4
|
|
5
5
|
import logging
|
6
|
-
from typing import Any, Dict, Iterable, Mapping, Optional, Tuple
|
6
|
+
from typing import Any, Dict, Iterable, Mapping, Optional, Tuple, cast
|
7
7
|
|
8
8
|
import fastavro
|
9
|
+
|
9
10
|
from airbyte_cdk.sources.file_based.config.avro_format import AvroFormat
|
10
11
|
from airbyte_cdk.sources.file_based.config.file_based_stream_config import FileBasedStreamConfig
|
11
12
|
from airbyte_cdk.sources.file_based.exceptions import FileBasedSourceError, RecordParseError
|
12
|
-
from airbyte_cdk.sources.file_based.file_based_stream_reader import
|
13
|
+
from airbyte_cdk.sources.file_based.file_based_stream_reader import (
|
14
|
+
AbstractFileBasedStreamReader,
|
15
|
+
FileReadMode,
|
16
|
+
)
|
13
17
|
from airbyte_cdk.sources.file_based.file_types.file_type_parser import FileTypeParser
|
14
18
|
from airbyte_cdk.sources.file_based.remote_file import RemoteFile
|
15
19
|
from airbyte_cdk.sources.file_based.schema_helpers import SchemaType
|
@@ -60,19 +64,27 @@ class AvroParser(FileTypeParser):
|
|
60
64
|
raise ValueError(f"Expected ParquetFormat, got {avro_format}")
|
61
65
|
|
62
66
|
with stream_reader.open_file(file, self.file_read_mode, self.ENCODING, logger) as fp:
|
63
|
-
avro_reader = fastavro.reader(fp)
|
67
|
+
avro_reader = fastavro.reader(fp) # type: ignore [arg-type]
|
64
68
|
avro_schema = avro_reader.writer_schema
|
65
|
-
if not avro_schema["type"] == "record":
|
66
|
-
unsupported_type = avro_schema["type"]
|
67
|
-
raise ValueError(
|
69
|
+
if not avro_schema["type"] == "record": # type: ignore [index, call-overload]
|
70
|
+
unsupported_type = avro_schema["type"] # type: ignore [index, call-overload]
|
71
|
+
raise ValueError(
|
72
|
+
f"Only record based avro files are supported. Found {unsupported_type}"
|
73
|
+
)
|
68
74
|
json_schema = {
|
69
|
-
field["name"]: AvroParser._convert_avro_type_to_json(
|
70
|
-
|
75
|
+
field["name"]: AvroParser._convert_avro_type_to_json( # type: ignore [index]
|
76
|
+
avro_format,
|
77
|
+
field["name"], # type: ignore [index]
|
78
|
+
field["type"], # type: ignore [index]
|
79
|
+
)
|
80
|
+
for field in avro_schema["fields"] # type: ignore [index, call-overload]
|
71
81
|
}
|
72
82
|
return json_schema
|
73
83
|
|
74
84
|
@classmethod
|
75
|
-
def _convert_avro_type_to_json(
|
85
|
+
def _convert_avro_type_to_json(
|
86
|
+
cls, avro_format: AvroFormat, field_name: str, avro_field: str
|
87
|
+
) -> Mapping[str, Any]:
|
76
88
|
if isinstance(avro_field, str) and avro_field in AVRO_TYPE_TO_JSON_TYPE:
|
77
89
|
# Legacy behavior to retain backwards compatibility. Long term we should always represent doubles as strings
|
78
90
|
if avro_field == "double" and not avro_format.double_as_string:
|
@@ -83,17 +95,28 @@ class AvroParser(FileTypeParser):
|
|
83
95
|
return {
|
84
96
|
"type": "object",
|
85
97
|
"properties": {
|
86
|
-
object_field["name"]: AvroParser._convert_avro_type_to_json(
|
98
|
+
object_field["name"]: AvroParser._convert_avro_type_to_json(
|
99
|
+
avro_format, object_field["name"], object_field["type"]
|
100
|
+
)
|
87
101
|
for object_field in avro_field["fields"]
|
88
102
|
},
|
89
103
|
}
|
90
104
|
elif avro_field["type"] == "array":
|
91
105
|
if "items" not in avro_field:
|
92
|
-
raise ValueError(
|
93
|
-
|
106
|
+
raise ValueError(
|
107
|
+
f"{field_name} array type does not have a required field items"
|
108
|
+
)
|
109
|
+
return {
|
110
|
+
"type": "array",
|
111
|
+
"items": AvroParser._convert_avro_type_to_json(
|
112
|
+
avro_format, "", avro_field["items"]
|
113
|
+
),
|
114
|
+
}
|
94
115
|
elif avro_field["type"] == "enum":
|
95
116
|
if "symbols" not in avro_field:
|
96
|
-
raise ValueError(
|
117
|
+
raise ValueError(
|
118
|
+
f"{field_name} enum type does not have a required field symbols"
|
119
|
+
)
|
97
120
|
if "name" not in avro_field:
|
98
121
|
raise ValueError(f"{field_name} enum type does not have a required field name")
|
99
122
|
return {"type": "string", "enum": avro_field["symbols"]}
|
@@ -102,7 +125,9 @@ class AvroParser(FileTypeParser):
|
|
102
125
|
raise ValueError(f"{field_name} map type does not have a required field values")
|
103
126
|
return {
|
104
127
|
"type": "object",
|
105
|
-
"additionalProperties": AvroParser._convert_avro_type_to_json(
|
128
|
+
"additionalProperties": AvroParser._convert_avro_type_to_json(
|
129
|
+
avro_format, "", avro_field["values"]
|
130
|
+
),
|
106
131
|
}
|
107
132
|
elif avro_field["type"] == "fixed" and avro_field.get("logicalType") != "duration":
|
108
133
|
if "size" not in avro_field:
|
@@ -115,18 +140,27 @@ class AvroParser(FileTypeParser):
|
|
115
140
|
}
|
116
141
|
elif avro_field.get("logicalType") == "decimal":
|
117
142
|
if "precision" not in avro_field:
|
118
|
-
raise ValueError(
|
143
|
+
raise ValueError(
|
144
|
+
f"{field_name} decimal type does not have a required field precision"
|
145
|
+
)
|
119
146
|
if "scale" not in avro_field:
|
120
|
-
raise ValueError(
|
147
|
+
raise ValueError(
|
148
|
+
f"{field_name} decimal type does not have a required field scale"
|
149
|
+
)
|
121
150
|
max_whole_number_range = avro_field["precision"] - avro_field["scale"]
|
122
151
|
decimal_range = avro_field["scale"]
|
123
152
|
|
124
153
|
# This regex looks like a mess, but it is validation for at least one whole number and optional fractional numbers
|
125
154
|
# For example: ^-?\d{1,5}(?:\.\d{1,3})?$ would accept 12345.123 and 123456.12345 would be rejected
|
126
|
-
return {
|
155
|
+
return {
|
156
|
+
"type": "string",
|
157
|
+
"pattern": f"^-?\\d{{{1,max_whole_number_range}}}(?:\\.\\d{1,decimal_range})?$",
|
158
|
+
}
|
127
159
|
elif "logicalType" in avro_field:
|
128
160
|
if avro_field["logicalType"] not in AVRO_LOGICAL_TYPE_TO_JSON:
|
129
|
-
raise ValueError(
|
161
|
+
raise ValueError(
|
162
|
+
f"{avro_field['logicalType']} is not a valid Avro logical type"
|
163
|
+
)
|
130
164
|
return AVRO_LOGICAL_TYPE_TO_JSON[avro_field["logicalType"]]
|
131
165
|
else:
|
132
166
|
raise ValueError(f"Unsupported avro type: {avro_field}")
|
@@ -148,25 +182,38 @@ class AvroParser(FileTypeParser):
|
|
148
182
|
line_no = 0
|
149
183
|
try:
|
150
184
|
with stream_reader.open_file(file, self.file_read_mode, self.ENCODING, logger) as fp:
|
151
|
-
avro_reader = fastavro.reader(fp)
|
185
|
+
avro_reader = fastavro.reader(fp) # type: ignore [arg-type]
|
152
186
|
schema = avro_reader.writer_schema
|
153
|
-
schema_field_name_to_type = {
|
187
|
+
schema_field_name_to_type = {
|
188
|
+
field["name"]: cast(dict[str, Any], field["type"]) # type: ignore [index]
|
189
|
+
for field in schema["fields"] # type: ignore [index, call-overload] # If schema is not dict, it is not subscriptable by strings
|
190
|
+
}
|
154
191
|
for record in avro_reader:
|
155
192
|
line_no += 1
|
156
193
|
yield {
|
157
|
-
record_field: self._to_output_value(
|
194
|
+
record_field: self._to_output_value(
|
195
|
+
avro_format,
|
196
|
+
schema_field_name_to_type[record_field], # type: ignore [index] # Any not subscriptable
|
197
|
+
record[record_field], # type: ignore [index] # Any not subscriptable
|
198
|
+
)
|
158
199
|
for record_field, record_value in schema_field_name_to_type.items()
|
159
200
|
}
|
160
201
|
except Exception as exc:
|
161
|
-
raise RecordParseError(
|
202
|
+
raise RecordParseError(
|
203
|
+
FileBasedSourceError.ERROR_PARSING_RECORD, filename=file.uri, lineno=line_no
|
204
|
+
) from exc
|
162
205
|
|
163
206
|
@property
|
164
207
|
def file_read_mode(self) -> FileReadMode:
|
165
208
|
return FileReadMode.READ_BINARY
|
166
209
|
|
167
210
|
@staticmethod
|
168
|
-
def _to_output_value(
|
169
|
-
|
211
|
+
def _to_output_value(
|
212
|
+
avro_format: AvroFormat, record_type: Mapping[str, Any], record_value: Any
|
213
|
+
) -> Any:
|
214
|
+
if isinstance(record_value, bytes):
|
215
|
+
return record_value.decode()
|
216
|
+
elif not isinstance(record_type, Mapping):
|
170
217
|
if record_type == "double" and avro_format.double_as_string:
|
171
218
|
return str(record_value)
|
172
219
|
return record_value
|
@@ -174,6 +221,10 @@ class AvroParser(FileTypeParser):
|
|
174
221
|
return str(record_value)
|
175
222
|
elif record_type.get("logicalType") == "date":
|
176
223
|
return record_value.isoformat()
|
224
|
+
elif record_type.get("logicalType") == "timestamp-millis":
|
225
|
+
return record_value.isoformat(sep="T", timespec="milliseconds")
|
226
|
+
elif record_type.get("logicalType") == "timestamp-micros":
|
227
|
+
return record_value.isoformat(sep="T", timespec="microseconds")
|
177
228
|
elif record_type.get("logicalType") == "local-timestamp-millis":
|
178
229
|
return record_value.isoformat(sep="T", timespec="milliseconds")
|
179
230
|
elif record_type.get("logicalType") == "local-timestamp-micros":
|
@@ -12,11 +12,21 @@ from io import IOBase
|
|
12
12
|
from typing import Any, Callable, Dict, Generator, Iterable, List, Mapping, Optional, Set, Tuple
|
13
13
|
from uuid import uuid4
|
14
14
|
|
15
|
+
import orjson
|
16
|
+
|
15
17
|
from airbyte_cdk.models import FailureType
|
16
|
-
from airbyte_cdk.sources.file_based.config.csv_format import
|
18
|
+
from airbyte_cdk.sources.file_based.config.csv_format import (
|
19
|
+
CsvFormat,
|
20
|
+
CsvHeaderAutogenerated,
|
21
|
+
CsvHeaderUserProvided,
|
22
|
+
InferenceType,
|
23
|
+
)
|
17
24
|
from airbyte_cdk.sources.file_based.config.file_based_stream_config import FileBasedStreamConfig
|
18
25
|
from airbyte_cdk.sources.file_based.exceptions import FileBasedSourceError, RecordParseError
|
19
|
-
from airbyte_cdk.sources.file_based.file_based_stream_reader import
|
26
|
+
from airbyte_cdk.sources.file_based.file_based_stream_reader import (
|
27
|
+
AbstractFileBasedStreamReader,
|
28
|
+
FileReadMode,
|
29
|
+
)
|
20
30
|
from airbyte_cdk.sources.file_based.file_types.file_type_parser import FileTypeParser
|
21
31
|
from airbyte_cdk.sources.file_based.remote_file import RemoteFile
|
22
32
|
from airbyte_cdk.sources.file_based.schema_helpers import TYPE_PYTHON_MAPPING, SchemaType
|
@@ -52,7 +62,12 @@ class _CsvReader:
|
|
52
62
|
quoting=csv.QUOTE_MINIMAL,
|
53
63
|
)
|
54
64
|
with stream_reader.open_file(file, file_read_mode, config_format.encoding, logger) as fp:
|
55
|
-
|
65
|
+
try:
|
66
|
+
headers = self._get_headers(fp, config_format, dialect_name)
|
67
|
+
except UnicodeError:
|
68
|
+
raise AirbyteTracedException(
|
69
|
+
message=f"{FileBasedSourceError.ENCODING_ERROR.value} Expected encoding: {config_format.encoding}",
|
70
|
+
)
|
56
71
|
|
57
72
|
rows_to_skip = (
|
58
73
|
config_format.skip_rows_before_header
|
@@ -70,13 +85,27 @@ class _CsvReader:
|
|
70
85
|
# The row was not properly parsed if any of the values are None. This will most likely occur if there are more columns
|
71
86
|
# than headers or more headers dans columns
|
72
87
|
if None in row:
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
88
|
+
if config_format.ignore_errors_on_fields_mismatch:
|
89
|
+
logger.error(
|
90
|
+
f"Skipping record in line {lineno} of file {file.uri}; invalid CSV row with missing column."
|
91
|
+
)
|
92
|
+
else:
|
93
|
+
raise RecordParseError(
|
94
|
+
FileBasedSourceError.ERROR_PARSING_RECORD_MISMATCHED_COLUMNS,
|
95
|
+
filename=file.uri,
|
96
|
+
lineno=lineno,
|
97
|
+
)
|
78
98
|
if None in row.values():
|
79
|
-
|
99
|
+
if config_format.ignore_errors_on_fields_mismatch:
|
100
|
+
logger.error(
|
101
|
+
f"Skipping record in line {lineno} of file {file.uri}; invalid CSV row with extra column."
|
102
|
+
)
|
103
|
+
else:
|
104
|
+
raise RecordParseError(
|
105
|
+
FileBasedSourceError.ERROR_PARSING_RECORD_MISMATCHED_ROWS,
|
106
|
+
filename=file.uri,
|
107
|
+
lineno=lineno,
|
108
|
+
)
|
80
109
|
yield row
|
81
110
|
finally:
|
82
111
|
# due to RecordParseError or GeneratorExit
|
@@ -88,10 +117,12 @@ class _CsvReader:
|
|
88
117
|
"""
|
89
118
|
# Note that this method assumes the dialect has already been registered if we're parsing the headers
|
90
119
|
if isinstance(config_format.header_definition, CsvHeaderUserProvided):
|
91
|
-
return config_format.header_definition.column_names
|
120
|
+
return config_format.header_definition.column_names
|
92
121
|
|
93
122
|
if isinstance(config_format.header_definition, CsvHeaderAutogenerated):
|
94
|
-
self._skip_rows(
|
123
|
+
self._skip_rows(
|
124
|
+
fp, config_format.skip_rows_before_header + config_format.skip_rows_after_header
|
125
|
+
)
|
95
126
|
headers = self._auto_generate_headers(fp, dialect_name)
|
96
127
|
else:
|
97
128
|
# Then read the header
|
@@ -123,7 +154,11 @@ class _CsvReader:
|
|
123
154
|
class CsvParser(FileTypeParser):
|
124
155
|
_MAX_BYTES_PER_FILE_FOR_SCHEMA_INFERENCE = 1_000_000
|
125
156
|
|
126
|
-
def __init__(self, csv_reader: Optional[_CsvReader] = None):
|
157
|
+
def __init__(self, csv_reader: Optional[_CsvReader] = None, csv_field_max_bytes: int = 2**31):
|
158
|
+
# Increase the maximum length of data that can be parsed in a single CSV field. The default is 128k, which is typically sufficient
|
159
|
+
# but given the use of Airbyte in loading a large variety of data it is best to allow for a larger maximum field size to avoid
|
160
|
+
# skipping data on load. https://stackoverflow.com/questions/15063936/csv-error-field-larger-than-field-limit-131072
|
161
|
+
csv.field_size_limit(csv_field_max_bytes)
|
127
162
|
self._csv_reader = csv_reader if csv_reader else _CsvReader()
|
128
163
|
|
129
164
|
def check_config(self, config: FileBasedStreamConfig) -> Tuple[bool, Optional[str]]:
|
@@ -147,11 +182,15 @@ class CsvParser(FileTypeParser):
|
|
147
182
|
# sources will likely require one. Rather than modify the interface now we can wait until the real use case
|
148
183
|
config_format = _extract_format(config)
|
149
184
|
type_inferrer_by_field: Dict[str, _TypeInferrer] = defaultdict(
|
150
|
-
lambda: _JsonTypeInferrer(
|
185
|
+
lambda: _JsonTypeInferrer(
|
186
|
+
config_format.true_values, config_format.false_values, config_format.null_values
|
187
|
+
)
|
151
188
|
if config_format.inference_type != InferenceType.NONE
|
152
189
|
else _DisabledTypeInferrer()
|
153
190
|
)
|
154
|
-
data_generator = self._csv_reader.read_data(
|
191
|
+
data_generator = self._csv_reader.read_data(
|
192
|
+
config, file, stream_reader, logger, self.file_read_mode
|
193
|
+
)
|
155
194
|
read_bytes = 0
|
156
195
|
for row in data_generator:
|
157
196
|
for header, value in row.items():
|
@@ -169,7 +208,10 @@ class CsvParser(FileTypeParser):
|
|
169
208
|
f"Else, please contact Airbyte.",
|
170
209
|
failure_type=FailureType.config_error,
|
171
210
|
)
|
172
|
-
schema = {
|
211
|
+
schema = {
|
212
|
+
header.strip(): {"type": type_inferred.infer()}
|
213
|
+
for header, type_inferred in type_inferrer_by_field.items()
|
214
|
+
}
|
173
215
|
data_generator.close()
|
174
216
|
return schema
|
175
217
|
|
@@ -185,19 +227,30 @@ class CsvParser(FileTypeParser):
|
|
185
227
|
try:
|
186
228
|
config_format = _extract_format(config)
|
187
229
|
if discovered_schema:
|
188
|
-
property_types = {
|
230
|
+
property_types = {
|
231
|
+
col: prop["type"] for col, prop in discovered_schema["properties"].items()
|
232
|
+
}
|
189
233
|
deduped_property_types = CsvParser._pre_propcess_property_types(property_types)
|
190
234
|
else:
|
191
235
|
deduped_property_types = {}
|
192
|
-
cast_fn = CsvParser._get_cast_function(
|
193
|
-
|
236
|
+
cast_fn = CsvParser._get_cast_function(
|
237
|
+
deduped_property_types, config_format, logger, config.schemaless
|
238
|
+
)
|
239
|
+
data_generator = self._csv_reader.read_data(
|
240
|
+
config, file, stream_reader, logger, self.file_read_mode
|
241
|
+
)
|
194
242
|
for row in data_generator:
|
195
243
|
line_no += 1
|
196
244
|
yield CsvParser._to_nullable(
|
197
|
-
cast_fn(row),
|
245
|
+
cast_fn(row),
|
246
|
+
deduped_property_types,
|
247
|
+
config_format.null_values,
|
248
|
+
config_format.strings_can_be_null,
|
198
249
|
)
|
199
250
|
except RecordParseError as parse_err:
|
200
|
-
raise RecordParseError(
|
251
|
+
raise RecordParseError(
|
252
|
+
FileBasedSourceError.ERROR_PARSING_RECORD, filename=file.uri, lineno=line_no
|
253
|
+
) from parse_err
|
201
254
|
finally:
|
202
255
|
data_generator.close()
|
203
256
|
|
@@ -207,27 +260,47 @@ class CsvParser(FileTypeParser):
|
|
207
260
|
|
208
261
|
@staticmethod
|
209
262
|
def _get_cast_function(
|
210
|
-
deduped_property_types: Mapping[str, str],
|
263
|
+
deduped_property_types: Mapping[str, str],
|
264
|
+
config_format: CsvFormat,
|
265
|
+
logger: logging.Logger,
|
266
|
+
schemaless: bool,
|
211
267
|
) -> Callable[[Mapping[str, str]], Mapping[str, str]]:
|
212
268
|
# Only cast values if the schema is provided
|
213
269
|
if deduped_property_types and not schemaless:
|
214
|
-
return partial(
|
270
|
+
return partial(
|
271
|
+
CsvParser._cast_types,
|
272
|
+
deduped_property_types=deduped_property_types,
|
273
|
+
config_format=config_format,
|
274
|
+
logger=logger,
|
275
|
+
)
|
215
276
|
else:
|
216
277
|
# If no schema is provided, yield the rows as they are
|
217
278
|
return _no_cast
|
218
279
|
|
219
280
|
@staticmethod
|
220
281
|
def _to_nullable(
|
221
|
-
row: Mapping[str, str],
|
282
|
+
row: Mapping[str, str],
|
283
|
+
deduped_property_types: Mapping[str, str],
|
284
|
+
null_values: Set[str],
|
285
|
+
strings_can_be_null: bool,
|
222
286
|
) -> Dict[str, Optional[str]]:
|
223
287
|
nullable = {
|
224
|
-
k: None
|
288
|
+
k: None
|
289
|
+
if CsvParser._value_is_none(
|
290
|
+
v, deduped_property_types.get(k), null_values, strings_can_be_null
|
291
|
+
)
|
292
|
+
else v
|
225
293
|
for k, v in row.items()
|
226
294
|
}
|
227
295
|
return nullable
|
228
296
|
|
229
297
|
@staticmethod
|
230
|
-
def _value_is_none(
|
298
|
+
def _value_is_none(
|
299
|
+
value: Any,
|
300
|
+
deduped_property_type: Optional[str],
|
301
|
+
null_values: Set[str],
|
302
|
+
strings_can_be_null: bool,
|
303
|
+
) -> bool:
|
231
304
|
return value in null_values and (strings_can_be_null or deduped_property_type != "string")
|
232
305
|
|
233
306
|
@staticmethod
|
@@ -262,7 +335,10 @@ class CsvParser(FileTypeParser):
|
|
262
335
|
|
263
336
|
@staticmethod
|
264
337
|
def _cast_types(
|
265
|
-
row: Dict[str, str],
|
338
|
+
row: Dict[str, str],
|
339
|
+
deduped_property_types: Mapping[str, str],
|
340
|
+
config_format: CsvFormat,
|
341
|
+
logger: logging.Logger,
|
266
342
|
) -> Dict[str, Any]:
|
267
343
|
"""
|
268
344
|
Casts the values in the input 'row' dictionary according to the types defined in the JSON schema.
|
@@ -287,20 +363,22 @@ class CsvParser(FileTypeParser):
|
|
287
363
|
else:
|
288
364
|
warnings.append(_format_warning(key, value, prop_type))
|
289
365
|
|
290
|
-
elif python_type
|
366
|
+
elif python_type is bool:
|
291
367
|
try:
|
292
|
-
cast_value = _value_to_bool(
|
368
|
+
cast_value = _value_to_bool(
|
369
|
+
value, config_format.true_values, config_format.false_values
|
370
|
+
)
|
293
371
|
except ValueError:
|
294
372
|
warnings.append(_format_warning(key, value, prop_type))
|
295
373
|
|
296
|
-
elif python_type
|
374
|
+
elif python_type is dict:
|
297
375
|
try:
|
298
376
|
# we don't re-use _value_to_object here because we type the column as object as long as there is only one object
|
299
|
-
cast_value =
|
300
|
-
except
|
377
|
+
cast_value = orjson.loads(value)
|
378
|
+
except orjson.JSONDecodeError:
|
301
379
|
warnings.append(_format_warning(key, value, prop_type))
|
302
380
|
|
303
|
-
elif python_type
|
381
|
+
elif python_type is list:
|
304
382
|
try:
|
305
383
|
cast_value = _value_to_list(value)
|
306
384
|
except (ValueError, json.JSONDecodeError):
|
@@ -346,7 +424,9 @@ class _JsonTypeInferrer(_TypeInferrer):
|
|
346
424
|
_NUMBER_TYPE = "number"
|
347
425
|
_STRING_TYPE = "string"
|
348
426
|
|
349
|
-
def __init__(
|
427
|
+
def __init__(
|
428
|
+
self, boolean_trues: Set[str], boolean_falses: Set[str], null_values: Set[str]
|
429
|
+
) -> None:
|
350
430
|
self._boolean_trues = boolean_trues
|
351
431
|
self._boolean_falses = boolean_falses
|
352
432
|
self._null_values = null_values
|
@@ -357,7 +437,9 @@ class _JsonTypeInferrer(_TypeInferrer):
|
|
357
437
|
|
358
438
|
def infer(self) -> str:
|
359
439
|
types_by_value = {value: self._infer_type(value) for value in self._values}
|
360
|
-
types_excluding_null_values = [
|
440
|
+
types_excluding_null_values = [
|
441
|
+
types for types in types_by_value.values() if self._NULL_TYPE not in types
|
442
|
+
]
|
361
443
|
if not types_excluding_null_values:
|
362
444
|
# this is highly unusual but we will consider the column as a string
|
363
445
|
return self._STRING_TYPE
|
@@ -0,0 +1,196 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
|
3
|
+
#
|
4
|
+
|
5
|
+
import logging
|
6
|
+
from io import IOBase
|
7
|
+
from pathlib import Path
|
8
|
+
from typing import Any, Dict, Iterable, Mapping, Optional, Tuple, Union
|
9
|
+
|
10
|
+
import orjson
|
11
|
+
import pandas as pd
|
12
|
+
from numpy import datetime64, issubdtype
|
13
|
+
from numpy import dtype as dtype_
|
14
|
+
from pydantic.v1 import BaseModel
|
15
|
+
|
16
|
+
from airbyte_cdk.sources.file_based.config.file_based_stream_config import (
|
17
|
+
ExcelFormat,
|
18
|
+
FileBasedStreamConfig,
|
19
|
+
)
|
20
|
+
from airbyte_cdk.sources.file_based.exceptions import (
|
21
|
+
ConfigValidationError,
|
22
|
+
FileBasedSourceError,
|
23
|
+
RecordParseError,
|
24
|
+
)
|
25
|
+
from airbyte_cdk.sources.file_based.file_based_stream_reader import (
|
26
|
+
AbstractFileBasedStreamReader,
|
27
|
+
FileReadMode,
|
28
|
+
)
|
29
|
+
from airbyte_cdk.sources.file_based.file_types.file_type_parser import FileTypeParser
|
30
|
+
from airbyte_cdk.sources.file_based.remote_file import RemoteFile
|
31
|
+
from airbyte_cdk.sources.file_based.schema_helpers import SchemaType
|
32
|
+
|
33
|
+
|
34
|
+
class ExcelParser(FileTypeParser):
|
35
|
+
ENCODING = None
|
36
|
+
|
37
|
+
def check_config(self, config: FileBasedStreamConfig) -> Tuple[bool, Optional[str]]:
|
38
|
+
"""
|
39
|
+
ExcelParser does not require config checks, implicit pydantic validation is enough.
|
40
|
+
"""
|
41
|
+
return True, None
|
42
|
+
|
43
|
+
async def infer_schema(
|
44
|
+
self,
|
45
|
+
config: FileBasedStreamConfig,
|
46
|
+
file: RemoteFile,
|
47
|
+
stream_reader: AbstractFileBasedStreamReader,
|
48
|
+
logger: logging.Logger,
|
49
|
+
) -> SchemaType:
|
50
|
+
"""
|
51
|
+
Infers the schema of the Excel file by examining its contents.
|
52
|
+
|
53
|
+
Args:
|
54
|
+
config (FileBasedStreamConfig): Configuration for the file-based stream.
|
55
|
+
file (RemoteFile): The remote file to be read.
|
56
|
+
stream_reader (AbstractFileBasedStreamReader): Reader to read the file.
|
57
|
+
logger (logging.Logger): Logger for logging information and errors.
|
58
|
+
|
59
|
+
Returns:
|
60
|
+
SchemaType: Inferred schema of the Excel file.
|
61
|
+
"""
|
62
|
+
|
63
|
+
# Validate the format of the config
|
64
|
+
self.validate_format(config.format, logger)
|
65
|
+
|
66
|
+
fields: Dict[str, str] = {}
|
67
|
+
|
68
|
+
with stream_reader.open_file(file, self.file_read_mode, self.ENCODING, logger) as fp:
|
69
|
+
df = self.open_and_parse_file(fp)
|
70
|
+
for column, df_type in df.dtypes.items():
|
71
|
+
# Choose the broadest data type if the column's data type differs in dataframes
|
72
|
+
prev_frame_column_type = fields.get(column) # type: ignore [call-overload]
|
73
|
+
fields[column] = self.dtype_to_json_type( # type: ignore [index]
|
74
|
+
prev_frame_column_type,
|
75
|
+
df_type,
|
76
|
+
)
|
77
|
+
|
78
|
+
schema = {
|
79
|
+
field: (
|
80
|
+
{"type": "string", "format": "date-time"}
|
81
|
+
if fields[field] == "date-time"
|
82
|
+
else {"type": fields[field]}
|
83
|
+
)
|
84
|
+
for field in fields
|
85
|
+
}
|
86
|
+
return schema
|
87
|
+
|
88
|
+
def parse_records(
|
89
|
+
self,
|
90
|
+
config: FileBasedStreamConfig,
|
91
|
+
file: RemoteFile,
|
92
|
+
stream_reader: AbstractFileBasedStreamReader,
|
93
|
+
logger: logging.Logger,
|
94
|
+
discovered_schema: Optional[Mapping[str, SchemaType]] = None,
|
95
|
+
) -> Iterable[Dict[str, Any]]:
|
96
|
+
"""
|
97
|
+
Parses records from an Excel file based on the provided configuration.
|
98
|
+
|
99
|
+
Args:
|
100
|
+
config (FileBasedStreamConfig): Configuration for the file-based stream.
|
101
|
+
file (RemoteFile): The remote file to be read.
|
102
|
+
stream_reader (AbstractFileBasedStreamReader): Reader to read the file.
|
103
|
+
logger (logging.Logger): Logger for logging information and errors.
|
104
|
+
discovered_schema (Optional[Mapping[str, SchemaType]]): Discovered schema for validation.
|
105
|
+
|
106
|
+
Yields:
|
107
|
+
Iterable[Dict[str, Any]]: Parsed records from the Excel file.
|
108
|
+
"""
|
109
|
+
|
110
|
+
# Validate the format of the config
|
111
|
+
self.validate_format(config.format, logger)
|
112
|
+
|
113
|
+
try:
|
114
|
+
# Open and parse the file using the stream reader
|
115
|
+
with stream_reader.open_file(file, self.file_read_mode, self.ENCODING, logger) as fp:
|
116
|
+
df = self.open_and_parse_file(fp)
|
117
|
+
# Yield records as dictionaries
|
118
|
+
# DataFrame.to_dict() method returns datetime values in pandas.Timestamp values, which are not serializable by orjson
|
119
|
+
# DataFrame.to_json() returns string with datetime values serialized to iso8601 with microseconds to align with pydantic behavior
|
120
|
+
# see PR description: https://github.com/airbytehq/airbyte/pull/44444/
|
121
|
+
yield from orjson.loads(
|
122
|
+
df.to_json(orient="records", date_format="iso", date_unit="us")
|
123
|
+
)
|
124
|
+
|
125
|
+
except Exception as exc:
|
126
|
+
# Raise a RecordParseError if any exception occurs during parsing
|
127
|
+
raise RecordParseError(
|
128
|
+
FileBasedSourceError.ERROR_PARSING_RECORD, filename=file.uri
|
129
|
+
) from exc
|
130
|
+
|
131
|
+
@property
|
132
|
+
def file_read_mode(self) -> FileReadMode:
|
133
|
+
"""
|
134
|
+
Returns the file read mode for the Excel file.
|
135
|
+
|
136
|
+
Returns:
|
137
|
+
FileReadMode: The file read mode (binary).
|
138
|
+
"""
|
139
|
+
return FileReadMode.READ_BINARY
|
140
|
+
|
141
|
+
@staticmethod
|
142
|
+
def dtype_to_json_type(
|
143
|
+
current_type: Optional[str],
|
144
|
+
dtype: dtype_, # type: ignore [type-arg]
|
145
|
+
) -> str:
|
146
|
+
"""
|
147
|
+
Convert Pandas DataFrame types to Airbyte Types.
|
148
|
+
|
149
|
+
Args:
|
150
|
+
current_type (Optional[str]): One of the previous types based on earlier dataframes.
|
151
|
+
dtype: Pandas DataFrame type.
|
152
|
+
|
153
|
+
Returns:
|
154
|
+
str: Corresponding Airbyte Type.
|
155
|
+
"""
|
156
|
+
number_types = ("int64", "float64")
|
157
|
+
if current_type == "string":
|
158
|
+
# Previous column values were of the string type, no need to look further.
|
159
|
+
return current_type
|
160
|
+
if dtype is object:
|
161
|
+
return "string"
|
162
|
+
if dtype in number_types and (not current_type or current_type == "number"):
|
163
|
+
return "number"
|
164
|
+
if dtype == "bool" and (not current_type or current_type == "boolean"):
|
165
|
+
return "boolean"
|
166
|
+
if issubdtype(dtype, datetime64):
|
167
|
+
return "date-time"
|
168
|
+
return "string"
|
169
|
+
|
170
|
+
@staticmethod
|
171
|
+
def validate_format(excel_format: BaseModel, logger: logging.Logger) -> None:
|
172
|
+
"""
|
173
|
+
Validates if the given format is of type ExcelFormat.
|
174
|
+
|
175
|
+
Args:
|
176
|
+
excel_format (Any): The format to be validated.
|
177
|
+
|
178
|
+
Raises:
|
179
|
+
ConfigValidationError: If the format is not ExcelFormat.
|
180
|
+
"""
|
181
|
+
if not isinstance(excel_format, ExcelFormat):
|
182
|
+
logger.info(f"Expected ExcelFormat, got {excel_format}")
|
183
|
+
raise ConfigValidationError(FileBasedSourceError.CONFIG_VALIDATION_ERROR)
|
184
|
+
|
185
|
+
@staticmethod
|
186
|
+
def open_and_parse_file(fp: Union[IOBase, str, Path]) -> pd.DataFrame:
|
187
|
+
"""
|
188
|
+
Opens and parses the Excel file.
|
189
|
+
|
190
|
+
Args:
|
191
|
+
fp: File pointer to the Excel file.
|
192
|
+
|
193
|
+
Returns:
|
194
|
+
pd.DataFrame: Parsed data from the Excel file.
|
195
|
+
"""
|
196
|
+
return pd.ExcelFile(fp, engine="calamine").parse() # type: ignore [arg-type, call-overload, no-any-return]
|