forked from robinhood/faust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoins.py
More file actions
48 lines (33 loc) · 1.07 KB
/
joins.py
File metadata and controls
48 lines (33 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Join strategies."""
from typing import Any, Optional, Tuple
from .types import EventT, FieldDescriptorT, JoinT, JoinableT
__all__ = [
'Join',
'RightJoin',
'LeftJoin',
'InnerJoin',
'OuterJoin',
]
class Join(JoinT):
"""Base class for join strategies."""
def __init__(self, *, stream: JoinableT,
fields: Tuple[FieldDescriptorT, ...]) -> None:
self.fields = {field.model: field for field in fields}
self.stream = stream
async def process(self, event: EventT) -> Optional[EventT]:
raise NotImplementedError()
def __eq__(self, other: Any) -> bool:
if isinstance(other, type(self)):
return (other.fields == self.fields and
other.stream is self.stream)
return False
def __ne__(self, other: Any) -> bool:
return not self.__eq__(other)
class RightJoin(Join):
"""Right-join strategy."""
class LeftJoin(Join):
"""Left-join strategy."""
class InnerJoin(Join):
"""Inner-join strategy."""
class OuterJoin(Join):
"""Outer-join strategy."""