mirror of
https://github.com/johnkerl/miller.git
synced 2026-08-03 21:13:09 +00:00
mappers cat & tac
This commit is contained in:
parent
a80040b560
commit
eb9c10efbc
4 changed files with 53 additions and 4 deletions
|
|
@ -11,10 +11,9 @@ func ChannelMapper(
|
|||
) {
|
||||
for {
|
||||
lrec := <-inrecs
|
||||
if lrec == nil {
|
||||
outrecs <- nil
|
||||
recordMapper.Map(lrec, outrecs)
|
||||
if lrec == nil { // end of stream
|
||||
break
|
||||
}
|
||||
recordMapper.Map(lrec, outrecs)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
18
go/src/mapping/mapper_cat.go
Normal file
18
go/src/mapping/mapper_cat.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package mapping
|
||||
|
||||
import (
|
||||
"containers"
|
||||
)
|
||||
|
||||
type MapperCat struct {
|
||||
// stateless
|
||||
}
|
||||
|
||||
func NewMapperCat() *MapperCat {
|
||||
return &MapperCat {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *MapperCat) Map(inrec *containers.Lrec, outrecs chan<- *containers.Lrec) {
|
||||
outrecs <- inrec
|
||||
}
|
||||
30
go/src/mapping/mapper_tac.go
Normal file
30
go/src/mapping/mapper_tac.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package mapping
|
||||
|
||||
import (
|
||||
// System:
|
||||
"container/list"
|
||||
// Miller:
|
||||
"containers"
|
||||
)
|
||||
|
||||
type MapperTac struct {
|
||||
lrecs *list.List
|
||||
}
|
||||
|
||||
func NewMapperTac() *MapperTac {
|
||||
return &MapperTac {
|
||||
list.New(),
|
||||
}
|
||||
}
|
||||
|
||||
func (this *MapperTac) Map(inrec *containers.Lrec, outrecs chan<- *containers.Lrec) {
|
||||
if inrec != nil {
|
||||
this.lrecs.PushFront(inrec)
|
||||
} else {
|
||||
// end of stream
|
||||
for e := this.lrecs.Front(); e != nil; e = e.Next() {
|
||||
outrecs <- e.Value.(*containers.Lrec)
|
||||
}
|
||||
outrecs <- nil
|
||||
}
|
||||
}
|
||||
|
|
@ -26,7 +26,9 @@ func Stream(filenames []string) error {
|
|||
outrecs := make(chan *containers.Lrec, 1)
|
||||
donechan := make(chan bool, 1)
|
||||
|
||||
recordMapper := mapping.NewMapperFoo();
|
||||
//recordMapper := mapping.NewMapperFoo();
|
||||
//recordMapper := mapping.NewMapperCat();
|
||||
recordMapper := mapping.NewMapperTac();
|
||||
|
||||
go input.ChannelReader(reader, inrecs, echan)
|
||||
go mapping.ChannelMapper(inrecs, recordMapper, outrecs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue