diff options
| author | sangtran <tranquangsang12.7@gmail.com> | 2026-08-29 01:08:28 +0700 |
|---|---|---|
| committer | sangtran <tranquangsang12.7@gmail.com> | 2026-08-29 01:08:28 +0700 |
| commit | 96c07bab1086510a55a004e9a1b90c30bc723a5c (patch) | |
| tree | 7abbc615c51667e111fdef7b2ef69a9fc663f2ca /core/operator/keyby.go | |
| signature | Verified sangtran <tranquangsang12.7@gmail.com> Key: 8DD79823D235E1BB ultimate trust | |
| download | flux-96c07bab1086510a55a004e9a1b90c30bc723a5c.tar.gz flux-96c07bab1086510a55a004e9a1b90c30bc723a5c.zip | |
Verified feat: init base draft support window
Diffstat (limited to 'core/operator/keyby.go')
| -rw-r--r-- | core/operator/keyby.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/core/operator/keyby.go b/core/operator/keyby.go new file mode 100644 index 0000000..56ef34e --- /dev/null +++ b/core/operator/keyby.go | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | package operator | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "context" | ||
| 5 | "flux/core" | ||
| 6 | ) | ||
| 7 | |||
| 8 | type KeySelector[IN any] func(in IN) string | ||
| 9 | type KeyByOperator[IN any] struct { | ||
| 10 | selector KeySelector[IN] | ||
| 11 | } | ||
| 12 | |||
| 13 | func NewKeyByOperator[IN any](selector KeySelector[IN]) *KeyByOperator[IN] { | ||
| 14 | return &KeyByOperator[IN]{selector: selector} | ||
| 15 | } | ||
| 16 | |||
| 17 | func (k *KeyByOperator[IN]) Open(ctx context.Context) error { | ||
| 18 | return nil | ||
| 19 | } | ||
| 20 | |||
| 21 | func (k *KeyByOperator[IN]) Process(ctx context.Context, record core.StreamRecord[IN], out Emitter[IN]) error { | ||
| 22 | if record.Type != core.RecordData { | ||
| 23 | return out.Emit(ctx, record) | ||
| 24 | } | ||
| 25 | |||
| 26 | record.Key = k.selector(record.Value) | ||
| 27 | return out.Emit(ctx, record) | ||
| 28 | } | ||
| 29 | |||
| 30 | func (k *KeyByOperator[IN]) Close(ctx context.Context) error { | ||
| 31 | return nil | ||
| 32 | } | ||
