Пример #1
0
	textfile := ctx.TextFileExt("./", ".go")
	f := textfile.Map(fnMap_line)
	log := f.Filter(filter_fn).Cache()
	results := log.Collect()
	fmt.Printf("results.: %#v\n", results)
	fmt.Printf("glog.: %d\n", log.Count())
	fmt.Printf("fatal: %d\n", log.Filter(filter_fatal).Count())
	for _, line := range log.Filter(filter_info).Collect() {
		fmt.Println(line)
	}

}

var fnLess = gopark.NewLessFunc("fnLess",
	func(x, y interface{}) bool {
		a := x.(*gopark.KeyValue).Value.(int)
		b := y.(*gopark.KeyValue).Value.(int)
		return a < b
	})

func init() {
	gopark.RegisterFunc(fnLess)
}

func Top10() {
	ctx := gopark.NewContext("gopark")
	defer ctx.Stop()
	file := ctx.TextFile("wc.go")
	words := file.FlatMap(fn).Map(fnMap)

	fm := words.ReduceByKey(fnReduce)
Пример #2
0
	gopark.RegisterFunc(less_func)
}

var map_func = gopark.NewMapperFunc("map_func",
	func(x interface{}) interface{} {
		return &gopark.KeyValue{x, 1}
	})

var filter_func = gopark.NewFilterFunc("filter_func",
	func(x interface{}) bool {
		result := x.(*gopark.KeyValue).Value.(int) > 30
		return result
	})
var less_func = gopark.NewLessFunc("less_func",
	func(x, y interface{}) bool {
		a := x.(*gopark.KeyValue).Value.(int)
		b := y.(*gopark.KeyValue).Value.(int)
		return a < b
	})

func testTextFile() {
	flag.Parse()
	ctx := gopark.NewContext("gopark")
	defer ctx.Stop()
	p := "."
	txt := ctx.TextFileExt(p, "")
	fm := txt.FlatMap(flatmap_func)
	fm = fm.Map(map_func)
	fm = fm.ReduceByKey(reducer_func)
	counts := fm

	ff := counts.Filter(filter_func)