how to create one polymorphic model

Đang mở
#489 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
stream-processing

Hướng nghiên cứu

The request centres on the polymorphic_fields=True option of faust.Record and on passing such a model as value_type to app.topic, so start by finding where Record options and topic value deserialization are handled. Before any change, decide what the maintainers want: the issue asks whether this is feasible and never states a design, and it has been open for about 1,290 days with no decision. Done would mean a written design agreed in the thread, then a test that deserializes a type-tagged event into the matching subclass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

I want to be able to process 1 event that can have multiple schemas based on type.
for example

class Event(faust.Record, serializer="json"):
    track_id: str

class InsertDataEvent(Event):
    file_path: str
    type: str = "INSERT"

class CreateTableEvent(Event):
    table_name: str
    type: str = "CREATE_TABLE"

class PolyEvent(faust.Record, polymorphic_fields=True):
     ...

And when I process the event, I want it to automatically be parsed by the type, and validated against the leaf class (AKA CreateTableEvent or InsertDataEvent).

ingestion_topic = app.topic("my-topic", key_type=str, value_type=PolyEvent)

@app.agent(channel=ingestion_topic)
async def process(stream) -> None:
    async for value in stream.events():
        event = value.value
        if event.type == "INSERT":
            insert_data(event.file_path)
        if event.type == "CREATE_TABLE":
            create_table(event.table_name)

Is this feasible? how would I write PolyEvent in that case?

Checklist

  • I have included information about relevant versions
  • I have verified that the issue persists when using the master branch of Faust.

Versions

  • Python version - 3.11.0
  • Faust version - 0.10.3
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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của faust-streaming/faust

Tất cả issue của faust-streaming/faust

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.