mirror of
https://github.com/johnkerl/miller.git
synced 2026-08-03 21:13:09 +00:00
bulk label
This commit is contained in:
parent
1f9367858a
commit
dbfb2ab0e4
4 changed files with 42 additions and 21 deletions
|
|
@ -109,15 +109,7 @@ func (this *MapperLabel) Map(
|
|||
) {
|
||||
inrec := inrecAndContext.Record
|
||||
if inrec != nil { // not end of record stream
|
||||
|
||||
oldNames := inrec.GetKeys()
|
||||
numOld := len(oldNames)
|
||||
numNew := len(this.newNames)
|
||||
numToRename := lib.IntMin2(numOld, numNew)
|
||||
|
||||
for i := 0; i < numToRename; i++ {
|
||||
inrec.Rename(&oldNames[i], &this.newNames[i])
|
||||
}
|
||||
inrec.Label(this.newNames)
|
||||
}
|
||||
outputChannel <- inrecAndContext // end-of-stream marker
|
||||
}
|
||||
|
|
|
|||
|
|
@ -317,6 +317,36 @@ func (this *Mlrmap) Rename(oldKey *string, newKey *string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
func (this *Mlrmap) Label(newNames []string) {
|
||||
that := NewMlrmapAsRecord()
|
||||
|
||||
i := 0
|
||||
numNewNames := len(newNames)
|
||||
for {
|
||||
if i >= numNewNames {
|
||||
break
|
||||
}
|
||||
pe := this.pop()
|
||||
if pe == nil {
|
||||
break
|
||||
}
|
||||
// Old record will be GC'ed: just move pointers
|
||||
that.PutReference(&newNames[i], pe.Value)
|
||||
i++
|
||||
}
|
||||
|
||||
for {
|
||||
pe := this.pop()
|
||||
if pe == nil {
|
||||
break
|
||||
}
|
||||
that.PutReference(pe.Key, pe.Value)
|
||||
}
|
||||
|
||||
*this = *that
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// PRIVATE METHODS
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ TOP OF LIST:
|
|||
- default to absent (no hoisting)
|
||||
- no scope-walks needed for for-loops
|
||||
|
||||
* rename: bulk-edit for b,i,x vs x,i,b cases
|
||||
|
||||
! filter
|
||||
> bare-boolean LR-1 conflicts wut
|
||||
? erase BNF distinction between BaseLvalue and MlrvalOrFunction
|
||||
|
|
@ -164,3 +162,4 @@ NITS/NON-IMMEDIATE:
|
|||
* mlrdoc: there should have always been a >>> and >>>=, and now there are
|
||||
! systime printing out in scientific notation :(
|
||||
! head early-out -- cite the relevant issue & fix the right way ...
|
||||
* relnotes: label b,i,x vs x,i,b change
|
||||
|
|
|
|||
|
|
@ -259,19 +259,19 @@ eks wye 4 0.38139939387114097 0.13418874328430463
|
|||
|
||||
----------------------------------------------------------------
|
||||
mlr --opprint label b,i,x u/s.dkvp
|
||||
x y
|
||||
pan 0.7268028627434533
|
||||
eks 0.5221511083334797
|
||||
wye 0.33831852551664776
|
||||
eks 0.13418874328430463
|
||||
b i x y
|
||||
pan pan 0.3467901443380824 0.7268028627434533
|
||||
eks pan 0.7586799647899636 0.5221511083334797
|
||||
wye wye 0.20460330576630303 0.33831852551664776
|
||||
eks wye 0.38139939387114097 0.13418874328430463
|
||||
|
||||
----------------------------------------------------------------
|
||||
mlr --opprint label x,i,b u/s.dkvp
|
||||
b x y
|
||||
pan pan 0.7268028627434533
|
||||
pan eks 0.5221511083334797
|
||||
wye wye 0.33831852551664776
|
||||
wye eks 0.13418874328430463
|
||||
x i b y
|
||||
0.3467901443380824 pan 1 0.7268028627434533
|
||||
0.7586799647899636 pan 2 0.5221511083334797
|
||||
0.20460330576630303 wye 3 0.33831852551664776
|
||||
0.38139939387114097 wye 4 0.13418874328430463
|
||||
|
||||
----------------------------------------------------------------
|
||||
mlr --opprint --from u/s.dkvp sort -f nonesuch
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue