9494 ClientSideIncrementalRecordFilterDecorator ,
9595)
9696from airbyte_cdk .sources .declarative .incremental import (
97- ChildPartitionResumableFullRefreshCursor ,
9897 ConcurrentCursorFactory ,
9998 ConcurrentPerPartitionCursor ,
10099 CursorFactory ,
101100 DatetimeBasedCursor ,
102101 DeclarativeCursor ,
103102 GlobalSubstreamCursor ,
104- PerPartitionCursor ,
105103 PerPartitionWithGlobalCursor ,
106- ResumableFullRefreshCursor ,
107104)
108105from airbyte_cdk .sources .declarative .interpolation import InterpolatedString
109106from airbyte_cdk .sources .declarative .interpolation .interpolated_mapping import InterpolatedMapping
446443from airbyte_cdk .sources .declarative .models .declarative_component_schema import (
447444 ZipfileDecoder as ZipfileDecoderModel ,
448445)
449- from airbyte_cdk .sources .declarative .parsers .custom_code_compiler import (
450- COMPONENTS_MODULE_NAME ,
451- SDM_COMPONENTS_MODULE_NAME ,
452- )
453446from airbyte_cdk .sources .declarative .partition_routers import (
454447 CartesianProductStreamSlicer ,
455448 GroupingPartitionRouter ,
508501 RequestOptionsProvider ,
509502)
510503from airbyte_cdk .sources .declarative .requesters .request_path import RequestPath
511- from airbyte_cdk .sources .declarative .requesters .requester import HttpMethod , Requester
504+ from airbyte_cdk .sources .declarative .requesters .requester import HttpMethod
512505from airbyte_cdk .sources .declarative .resolvers import (
513506 ComponentMappingDefinition ,
514507 ConfigComponentsResolver ,
@@ -1941,10 +1934,10 @@ def create_declarative_stream(
19411934
19421935 primary_key = model .primary_key .__root__ if model .primary_key else None
19431936
1944- stream_slicer = self ._build_stream_slicer_from_partition_router (
1937+ partition_router = self ._build_stream_slicer_from_partition_router (
19451938 model .retriever , config , stream_name = model .name
19461939 )
1947- concurrent_cursor = self ._build_concurrent_cursor (model , stream_slicer , config )
1940+ concurrent_cursor = self ._build_concurrent_cursor (model , partition_router , config )
19481941
19491942 if model .incremental_sync and isinstance (model .incremental_sync , DatetimeBasedCursorModel ):
19501943 cursor_model = model .incremental_sync
@@ -2019,7 +2012,9 @@ def create_declarative_stream(
20192012 primary_key = primary_key ,
20202013 stream_slicer = combined_slicers ,
20212014 request_options_provider = request_options_provider ,
2022- stop_condition_cursor = concurrent_cursor if self ._is_stop_condition_on_cursor (model ) else None ,
2015+ stop_condition_cursor = concurrent_cursor
2016+ if self ._is_stop_condition_on_cursor (model )
2017+ else None ,
20232018 client_side_incremental_sync = {"cursor" : concurrent_cursor }
20242019 if self ._is_client_side_filtering_enabled (model )
20252020 else None ,
@@ -2055,7 +2050,10 @@ def create_declarative_stream(
20552050 schema_loader = DefaultSchemaLoader (config = config , parameters = options )
20562051
20572052 if (
2058- (isinstance (combined_slicers , PartitionRouter ) or isinstance (concurrent_cursor , ConcurrentCursor ))
2053+ (
2054+ isinstance (combined_slicers , PartitionRouter )
2055+ or isinstance (concurrent_cursor , ConcurrentCursor )
2056+ )
20592057 and not is_parent
20602058 and not self ._emit_connector_builder_messages
20612059 ):
@@ -2067,7 +2065,9 @@ def create_declarative_stream(
20672065 # We specifically exclude parent streams here because SubstreamPartitionRouter has not been updated yet
20682066 # We specifically exclude Connector Builder stuff for now as Brian is working on this anyway
20692067
2068+ stream_name = model .name or ""
20702069 stream_slicer = concurrent_cursor
2070+ cursor = FinalStateCursor (stream_name , None , self ._message_repository )
20712071 if isinstance (retriever , AsyncRetriever ):
20722072 # The AsyncRetriever only ever worked with a cursor from the concurrent package. Hence, the method
20732073 # `_build_incremental_cursor` which we would usually think would return only declarative stuff has a
@@ -2076,10 +2076,13 @@ def create_declarative_stream(
20762076 # We can't re-use `concurrent_cursor` because it is a different instance than the one passed in
20772077 # AsyncJobPartitionRouter.
20782078 stream_slicer = retriever .stream_slicer
2079+ if isinstance (combined_slicers , Cursor ):
2080+ cursor = combined_slicers
20792081 elif isinstance (combined_slicers , PartitionRouter ):
20802082 stream_slicer = combined_slicers
2083+ else :
2084+ cursor = concurrent_cursor
20812085
2082- stream_name = model .name or ""
20832086 partition_generator = StreamSlicerPartitionGenerator (
20842087 DeclarativePartitionFactory (
20852088 stream_name ,
@@ -2089,16 +2092,17 @@ def create_declarative_stream(
20892092 ),
20902093 stream_slicer ,
20912094 )
2092- cursor = concurrent_cursor if concurrent_cursor else FinalStateCursor ( stream_name , None , self . _message_repository )
2095+
20932096 return DefaultStream (
20942097 partition_generator = partition_generator ,
20952098 name = stream_name ,
20962099 json_schema = schema_loader .get_json_schema ,
20972100 primary_key = get_primary_key_from_stream (primary_key ),
2098- cursor_field = cursor .cursor_field .cursor_field_key if hasattr (cursor , "cursor_field" ) else "" , # FIXME we should have the cursor field has part of the interface of cursor,
2099- # FIXME we should have the cursor field has part of the interface of cursor
2101+ cursor_field = cursor .cursor_field .cursor_field_key
2102+ if hasattr (cursor , "cursor_field" )
2103+ else "" , # FIXME we should have the cursor field has part of the interface of cursor,
21002104 logger = logging .getLogger (f"airbyte.{ stream_name } " ),
2101- # FIXME this is a breaking change compared to the old implementation,
2105+ # FIXME this is a breaking change compared to the old implementation which used the source name instead
21022106 cursor = cursor ,
21032107 )
21042108
@@ -2121,18 +2125,18 @@ def create_declarative_stream(
21212125 parameters = model .parameters or {},
21222126 )
21232127
2124- def _is_stop_condition_on_cursor (self , model ) :
2128+ def _is_stop_condition_on_cursor (self , model : DeclarativeStreamModel ) -> bool :
21252129 return (
2126- model .incremental_sync
2127- and hasattr (model .incremental_sync , "is_data_feed" )
2128- and model .incremental_sync .is_data_feed
2130+ model .incremental_sync
2131+ and hasattr (model .incremental_sync , "is_data_feed" )
2132+ and model .incremental_sync .is_data_feed
21292133 )
21302134
2131- def _is_client_side_filtering_enabled (self , model ) :
2135+ def _is_client_side_filtering_enabled (self , model : DeclarativeStreamModel ) -> bool :
21322136 client_side_filtering_enabled = (
2133- model .incremental_sync
2134- and hasattr (model .incremental_sync , "is_client_side_incremental" )
2135- and model .incremental_sync .is_client_side_incremental
2137+ model .incremental_sync
2138+ and hasattr (model .incremental_sync , "is_client_side_incremental" )
2139+ and model .incremental_sync .is_client_side_incremental
21362140 )
21372141 return client_side_filtering_enabled
21382142
0 commit comments