@@ -22,7 +22,7 @@ class DataFrameRegistry:
22
22
23
23
def __init__ (self ) -> None :
24
24
self ._registry : dict [str , Stream ] = {}
25
- self ._wall_clock_registry : dict [str , Stream ] = {}
25
+ self ._wall_clock_registry : dict [str , tuple [ tuple [ Topic , ...], Stream ] ] = {}
26
26
self ._topics : list [Topic ] = []
27
27
self ._repartition_origins : set [str ] = set ()
28
28
self ._topics_to_stream_ids : dict [str , set [str ]] = {}
@@ -74,15 +74,11 @@ def register_wall_clock(
74
74
self , dataframe : "StreamingDataFrame" , stream : Stream
75
75
) -> None :
76
76
"""
77
- Register a wall clock stream for the given topic.
77
+ Register a wall clock stream root for the given dataframe.
78
+ Stores the Stream itself to be composed later with an optional sink.
78
79
"""
79
- topics = dataframe .topics
80
- if len (topics ) > 1 :
81
- raise ValueError (
82
- f"Expected a StreamingDataFrame with one topic, got { len (topics )} "
83
- )
84
- topic = topics [0 ]
85
- self ._wall_clock_registry [topic .name ] = stream
80
+ # TODO: What if there are more wall clock streams for the same stream_id?
81
+ self ._wall_clock_registry [dataframe .stream_id ] = (dataframe .topics , stream )
86
82
87
83
def register_groupby (
88
84
self ,
@@ -128,28 +124,27 @@ def compose_all(
128
124
:param sink: callable to accumulate the results of the execution, optional.
129
125
:return: a {topic_name: composed} dict, where composed is a callable
130
126
"""
131
- return self ._compose (registry = self ._registry , sink = sink )
132
-
133
- def compose_wall_clock (self ) -> dict [str , VoidExecutor ]:
134
- """
135
- Composes all the wall clock streams and returns a dict of format {<topic>: <VoidExecutor>}
136
- :return: a {topic_name: composed} dict, where composed is a callable
137
- """
138
- return self ._compose (registry = self ._wall_clock_registry )
139
-
140
- def _compose (
141
- self , registry : dict [str , Stream ], sink : Optional [VoidExecutor ] = None
142
- ) -> dict [str , VoidExecutor ]:
143
127
executors = {}
144
128
# Go over the registered topics with root Streams and compose them
145
- for topic , root_stream in registry .items ():
129
+ for topic , root_stream in self . _registry .items ():
146
130
# If a root stream is connected to other roots, ".compose()" will
147
131
# return them all.
148
132
# Use the registered root Stream to filter them out.
149
133
root_executors = root_stream .compose (sink = sink )
150
134
executors [topic ] = root_executors [root_stream ]
151
135
return executors
152
136
137
+ def compose_wall_clock (self ) -> dict [tuple [Topic , ...], VoidExecutor ]:
138
+ """
139
+ Compose all wall clock Streams and return executors keyed by stream_id.
140
+ Returns mapping: {stream_id: (topics, executor)}
141
+ """
142
+ executors = {}
143
+ for _ , (topics , root_stream ) in self ._wall_clock_registry .items ():
144
+ root_executors = root_stream .compose ()
145
+ executors [topics ] = root_executors [root_stream ]
146
+ return executors
147
+
153
148
def register_stream_id (self , stream_id : str , topic_names : list [str ]):
154
149
"""
155
150
Register a mapping between the stream_id and topic names.
0 commit comments