| 253 | * @param type - The type of join to perform |
| 254 | */ |
| 255 | export function join< |
| 256 | K, |
| 257 | V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never, |
| 258 | V2, |
| 259 | T, |
| 260 | >( |
| 261 | other: IStreamBuilder<KeyValue<K, V2>>, |
| 262 | type: JoinType = `inner`, |
| 263 | ): PipedOperator<T, KeyValue<K, [V1 | null, V2 | null]>> { |
| 264 | return ( |
| 265 | stream: IStreamBuilder<T>, |
| 266 | ): IStreamBuilder<KeyValue<K, [V1 | null, V2 | null]>> => { |
| 267 | if (stream.graph !== other.graph) { |
| 268 | throw new Error(`Cannot join streams from different graphs`) |
| 269 | } |
| 270 | const output = new StreamBuilder<KeyValue<K, [V1 | null, V2 | null]>>( |
| 271 | stream.graph, |
| 272 | new DifferenceStreamWriter<KeyValue<K, [V1 | null, V2 | null]>>(), |
| 273 | ) |
| 274 | const operator = new JoinOperator<K, V1, V2>( |
| 275 | stream.graph.getNextOperatorId(), |
| 276 | stream.connectReader() as DifferenceStreamReader<KeyValue<K, V1>>, |
| 277 | other.connectReader(), |
| 278 | output.writer, |
| 279 | type, |
| 280 | ) |
| 281 | stream.graph.addOperator(operator) |
| 282 | return output |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Joins two input streams (inner join) |