how to create one polymorphic model

Aperta
#489 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
12/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
1.9k
Fork
205
Merge medio
2h 2m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di faust-streaming/faust

Tutte le issue di faust-streaming/faust

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.