|
35 | 35 | from airbyte_cdk.sources.declarative.checks import COMPONENTS_CHECKER_TYPE_MAPPING |
36 | 36 | from airbyte_cdk.sources.declarative.checks.connection_checker import ConnectionChecker |
37 | 37 | from airbyte_cdk.sources.declarative.declarative_source import DeclarativeSource |
| 38 | +from airbyte_cdk.sources.declarative.interpolation import InterpolatedBoolean |
38 | 39 | from airbyte_cdk.sources.declarative.models.declarative_component_schema import ( |
39 | 40 | ConditionalStreams as ConditionalStreamsModel, |
40 | 41 | ) |
@@ -303,43 +304,27 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]: |
303 | 304 | } |
304 | 305 | ) |
305 | 306 |
|
306 | | - stream_configs = self._stream_configs(self._source_config) + self.dynamic_streams |
| 307 | + stream_configs = ( |
| 308 | + self._stream_configs(self._source_config, config=config) + self.dynamic_streams |
| 309 | + ) |
307 | 310 |
|
308 | 311 | api_budget_model = self._source_config.get("api_budget") |
309 | 312 | if api_budget_model: |
310 | 313 | self._constructor.set_api_budget(api_budget_model, config) |
311 | 314 |
|
312 | | - source_streams = [] |
313 | | - for stream_config in self._initialize_cache_for_parent_streams(deepcopy(stream_configs)): |
314 | | - match stream_config.get("type"): |
315 | | - case StateDelegatingStreamModel.__name__: |
316 | | - source_streams.append( |
317 | | - self._constructor.create_component( |
318 | | - StateDelegatingStreamModel, |
319 | | - stream_config, |
320 | | - config, |
321 | | - emit_connector_builder_messages=self._emit_connector_builder_messages, |
322 | | - ) |
323 | | - ) |
324 | | - case ConditionalStreamsModel.__name__: |
325 | | - # ConditionalStreamsModel returns a list of DeclarativeStreams so it must be extended |
326 | | - source_streams.extend( |
327 | | - self._constructor.create_component( |
328 | | - ConditionalStreamsModel, |
329 | | - stream_config, |
330 | | - config, |
331 | | - emit_connector_builder_messages=self._emit_connector_builder_messages, |
332 | | - ) |
333 | | - ) |
334 | | - case DeclarativeStreamModel.__name__: |
335 | | - source_streams.append( |
336 | | - self._constructor.create_component( |
337 | | - DeclarativeStreamModel, |
338 | | - stream_config, |
339 | | - config, |
340 | | - emit_connector_builder_messages=self._emit_connector_builder_messages, |
341 | | - ) |
342 | | - ) |
| 315 | + source_streams = [ |
| 316 | + self._constructor.create_component( |
| 317 | + ( |
| 318 | + StateDelegatingStreamModel |
| 319 | + if stream_config.get("type") == StateDelegatingStreamModel.__name__ |
| 320 | + else DeclarativeStreamModel |
| 321 | + ), |
| 322 | + stream_config, |
| 323 | + config, |
| 324 | + emit_connector_builder_messages=self._emit_connector_builder_messages, |
| 325 | + ) |
| 326 | + for stream_config in self._initialize_cache_for_parent_streams(deepcopy(stream_configs)) |
| 327 | + ] |
343 | 328 | return source_streams |
344 | 329 |
|
345 | 330 | @staticmethod |
@@ -383,26 +368,16 @@ def update_with_cache_parent_configs( |
383 | 368 | update_with_cache_parent_configs(router["parent_stream_configs"]) |
384 | 369 |
|
385 | 370 | for stream_config in stream_configs: |
386 | | - current_stream_configs = [] |
387 | | - if stream_config.get("type") == ConditionalStreamsModel.__name__: |
388 | | - current_stream_configs = [ |
389 | | - conditional_stream_config |
390 | | - for conditional_stream_config in stream_config.get("streams") or [] |
391 | | - if conditional_stream_config["name"] in parent_streams |
392 | | - ] |
393 | | - elif stream_config["name"] in parent_streams: |
394 | | - current_stream_configs = [stream_config] |
395 | | - |
396 | | - for current_stream_config in current_stream_configs: |
397 | | - if current_stream_config["type"] == "StateDelegatingStream": |
398 | | - current_stream_config["full_refresh_stream"]["retriever"]["requester"][ |
399 | | - "use_cache" |
400 | | - ] = True |
401 | | - current_stream_config["incremental_stream"]["retriever"]["requester"][ |
402 | | - "use_cache" |
403 | | - ] = True |
| 371 | + if stream_config["name"] in parent_streams: |
| 372 | + if stream_config["type"] == "StateDelegatingStream": |
| 373 | + stream_config["full_refresh_stream"]["retriever"]["requester"]["use_cache"] = ( |
| 374 | + True |
| 375 | + ) |
| 376 | + stream_config["incremental_stream"]["retriever"]["requester"]["use_cache"] = ( |
| 377 | + True |
| 378 | + ) |
404 | 379 | else: |
405 | | - current_stream_config["retriever"]["requester"]["use_cache"] = True |
| 380 | + stream_config["retriever"]["requester"]["use_cache"] = True |
406 | 381 | return stream_configs |
407 | 382 |
|
408 | 383 | def spec(self, logger: logging.Logger) -> ConnectorSpecification: |
@@ -506,12 +481,27 @@ def _parse_version( |
506 | 481 | # No exception |
507 | 482 | return parsed_version |
508 | 483 |
|
509 | | - def _stream_configs(self, manifest: Mapping[str, Any]) -> List[Dict[str, Any]]: |
| 484 | + def _stream_configs( |
| 485 | + self, manifest: Mapping[str, Any], config: Mapping[str, Any] |
| 486 | + ) -> List[Dict[str, Any]]: |
510 | 487 | # This has a warning flag for static, but after we finish part 4 we'll replace manifest with self._source_config |
511 | | - stream_configs: List[Dict[str, Any]] = manifest.get("streams", []) |
512 | | - for s in stream_configs: |
513 | | - if "type" not in s: |
514 | | - s["type"] = "DeclarativeStream" |
| 488 | + stream_configs = [] |
| 489 | + for current_stream_config in manifest.get("streams", []): |
| 490 | + if ( |
| 491 | + "type" in current_stream_config |
| 492 | + and current_stream_config["type"] == "ConditionalStreams" |
| 493 | + ): |
| 494 | + interpolated_boolean = InterpolatedBoolean( |
| 495 | + condition=current_stream_config.get("condition"), |
| 496 | + parameters={}, |
| 497 | + ) |
| 498 | + |
| 499 | + if interpolated_boolean.eval(config=config): |
| 500 | + stream_configs.extend(current_stream_config.get("streams", [])) |
| 501 | + else: |
| 502 | + if "type" not in current_stream_config: |
| 503 | + current_stream_config["type"] = "DeclarativeStream" |
| 504 | + stream_configs.append(current_stream_config) |
515 | 505 | return stream_configs |
516 | 506 |
|
517 | 507 | def _dynamic_stream_configs( |
|
0 commit comments