Polymorphic fields
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 12/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- stream-processing
Hướng nghiên cứu
The issue centres on the polymorphic_fields=True option of Faust's Record class and the _blessed_key attribute, plus the from_data override in the reporter's snippet; the payload names no specific files. Decide first whether a custom blessed key format is meant to be supported, since the issue asks that question rather than requesting a specific change. Done would mean a maintainer records that decision, with either a documented extension point or a closed issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I am in the process of converting a legacy system that was using an in-house streaming package to Faust. We had our own "polymorphic typing" implementation that made messages look like this:
{
"class": "MessageClassType",
"data": {"id": "1234", "other_field": "4321", ...}
}
I've been trying to match this to Faust's Polymorphic fields, but I'm stuck. From the documentation, I cannot understand if this feature should be used only when Faust has produced messages and added the blessed key, or if I can customize this. I am currently not yet producing messages using Faust, so it's unclear if Faust will always add the blessed key to the messages.
So far, I was able to come up with something like this:
class MyMessage(Record, polymorphic_fields=True, serializer='avroschema'):
_blessed_key = 'blessed_key'
class_: str
@classmethod
def from_data(cls, data: Mapping, **kwargs):
if 'class' in data:
data = {**data, "class_": data['class'], 'blessed_key': {"ns": data['class']}}
return super().from_data(data, **kwargs)
class PolymorphicMessageField(Record):
id: str
other_field: str
class MyMessagePolymorphic(MyMessage, namespace='MyMessagePolymorphic'):
class_ = "MyMessagePolymorphic"
data: PolymorphicMessageField
This seems to be working. If I receive a message with the contents {"class": "MyMessagePolymorphic", "data": {"id": "1234", "other_field": "4321"}}, I am able to check the type on both the message (matching MyMessagePolymorphic), and the data field (matching PolymorphicMessageField).
However, this seems overly clunky for a couple reasons:
- I am specifying the blessed key by overriding the underscore attribute
_blessed_key. - I need to set the namespace to the same class name which causes repetition, otherwise Faust automatically appends the module name into it.
- It is necessarily the case that the blessed key will be a dictionary with the class name inside a
nsfield, so I also need to override thefrom_datamethod.
Is there a better or more supported way to accomplish this?
- Ngôn ngữ chính
- Python
- Star
- 1.9k
- Fork
- 205
- Merge trung bình
- 2 giờ 2 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của faust-streaming/faust
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
faust-streaming/faust#804 ·
-
scripts/install script forces use of ./venv virtualenv, impossible to use with virtualenvwrapperĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
faust-streaming/faust#28 · 1 bình luận ·
-
[BUG] SASL PLAINTEXT producer initialization fails : missing sasl_plain_username/passwordCó thể đã có người làm @wbarnha đã nhận 56 ngày trước. Đang mở
faust-streaming/faust#794 · 2 bình luận · 1 reaction · 2 người được giao ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 18/100
faust-streaming/faust#670 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 18/100
faust-streaming/faust#666 ·
Tất cả issue của faust-streaming/faust
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Maintainer] task area:visualizer
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
RailtownAI/railtracks#1824 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
apache/datafusion#27688 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
heasarc/heasarc-tutorials#317 ·
-
bug good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
mloda-ai/mloda-registry#1664 ·
Maintainer thường phản hồi trong vòng 1 ngày