From d1763a357b3fb9b749130bf2e0b49633e3fcd254 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sat, 20 Jan 2024 13:21:38 -0500 Subject: [PATCH] iterate --- pkg/transformers/reorder.go | 53 +++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/pkg/transformers/reorder.go b/pkg/transformers/reorder.go index b8f816abb2..3c0402b40c 100644 --- a/pkg/transformers/reorder.go +++ b/pkg/transformers/reorder.go @@ -214,13 +214,38 @@ func (tr *TransformerReorder) reorderToStart( ) { if !inrecAndContext.EndOfStream { inrec := inrecAndContext.Record + if tr.regexes == nil { for _, fieldName := range tr.fieldNames { inrec.MoveToHead(fieldName) } outputRecordsAndContexts.PushBack(inrecAndContext) + } else { - // XXX TO DO + outrec := mlrval.NewMlrmapAsRecord() + atEnds := list.New() + for pe := inrec.Head; pe != nil; pe = pe.Next { + found := false + for _, regex := range tr.regexes { + if regex.MatchString(pe.Key) { + outrec.PutReference(pe.Key, pe.Value) + found = true + break + } + } + if !found { + atEnds.PushBack(pe) + } + } + + for atEnd := atEnds.Front(); atEnd != nil; atEnd = atEnd.Next() { + // Ownership transfer; no copy needed + pe := atEnd.Value.(*mlrval.MlrmapEntry) + outrec.PutReference(pe.Key, pe.Value) + } + + outrecAndContext := types.NewRecordAndContext(outrec, &inrecAndContext.Context) + outputRecordsAndContexts.PushBack(outrecAndContext) } } else { @@ -242,8 +267,32 @@ func (tr *TransformerReorder) reorderToEnd( inrec.MoveToTail(fieldName) } outputRecordsAndContexts.PushBack(inrecAndContext) + } else { - // XXX TO DO + outrec := mlrval.NewMlrmapAsRecord() + atEnds := list.New() + for pe := inrec.Head; pe != nil; pe = pe.Next { + found := false + for _, regex := range tr.regexes { + if regex.MatchString(pe.Key) { + atEnds.PushBack(pe) + found = true + break + } + } + if !found { + outrec.PutReference(pe.Key, pe.Value) + } + } + + for atEnd := atEnds.Front(); atEnd != nil; atEnd = atEnd.Next() { + // Ownership transfer; no copy needed + pe := atEnd.Value.(*mlrval.MlrmapEntry) + outrec.PutReference(pe.Key, pe.Value) + } + + outrecAndContext := types.NewRecordAndContext(outrec, &inrecAndContext.Context) + outputRecordsAndContexts.PushBack(outrecAndContext) } } else { outputRecordsAndContexts.PushBack(inrecAndContext) // end-of-stream marker