Exemplo n.º 1
0
func main() {

	if len(os.Args) < 2 {
		log.Printf("Error! No arguments provided.")
		log.Printf(genericError)
		return
	}
	parseExpression := os.Args[1]
	numExtractions := findNumExtractions(parseExpression)
	//         (parse, str)	(as)  (foo, bar, baz)
	expectedArgs := 2 + 1 + numExtractions
	if len(os.Args) < expectedArgs {
		log.Printf(genericError)
		log.Printf("Expected more arguments\n")
		return
	}
	as := os.Args[2]
	if as != "as" {
		log.Printf(genericError)
		log.Printf("Expected `as`\n")
		return
	}
	extractions := make([]string, len(os.Args)-3)
	for i, arg := range os.Args[3:] {
		extractions[i] = strings.Trim(arg, ",")
	}
	util.ConnectToStdIn(Parser{parseExpression, extractions,
		regexFromPat(parseExpression), util.NewJsonWriter()})
}
Exemplo n.º 2
0
func NewMerger() Merger {
	mu := &sync.Mutex{}
	m := Merger{make(map[int]map[string]interface{}), util.NewJsonWriter(), mu}
	ticker := time.NewTicker(100 * time.Millisecond)
	go flush(m, ticker)
	return m
}
Exemplo n.º 3
0
func makeAverage(key string) average {
	samp := 0
	v := 0.0
	ready := false
	return average{&samp, &v, key, make(map[string]interface{}), &ready, util.NewJsonWriter().Write}

}
Exemplo n.º 4
0
func Build(args []string) (util.SumoOperator, error) {
	// [parse x as y, z, w]
	if len(args) < 2 {
		log.Printf("Error! No arguments provided.")
		log.Printf(genericError)
		return nil, util.ParseError("Error! No arguments provided\n" + genericError)
	}
	parseExpression := args[1]
	numExtractions := findNumExtractions(parseExpression)
	//         (parse pattern)	(as)  (foo, bar, baz)
	expectedArgs := 2 + 1 + numExtractions
	if len(args) < expectedArgs {
		return nil, util.ParseError("Expected more arguments\n" + genericError)
	}
	as := args[2]
	if as != "as" {
		return nil, util.ParseError("Expacted `as` got " + as + "\n" + genericError)
	}
	extractions := make([]string, len(args)-3)
	for i, arg := range args[3:] {
		extractions[i] = strings.Trim(arg, ",")
	}
	ret := Parser{parseExpression, extractions, regexFromPat(parseExpression), util.NewJsonWriter()}
	return &ret, nil
}
Exemplo n.º 5
0
func Build(args []string) (util.SumoOperator, error) {

	lsh := args[1]
	eq := args[2]
	if eq != "=" {
		return nil, util.ParseError("Expected `=` found `" + eq + "`\n" + genericError)
	}
	value := strings.Join(args[3:], " ")

	return &ExprOperator{lsh, value, util.NewJsonWriter()}, nil
}
Exemplo n.º 6
0
func read(filterString string) {
	r, w := io.Pipe()
	handler := util.NewRawInputHandler(w)
	go util.ConnectToReader(SumoFilter{filterString, util.NewJsonWriter()}, r)
	bio := bufio.NewReader(os.Stdin)
	var line, hasMoreInLine, err = bio.ReadLine()
	for err != io.EOF || hasMoreInLine {
		handler.Process(line)
		line, hasMoreInLine, err = bio.ReadLine()
	}
	handler.Flush()
}
Exemplo n.º 7
0
func main() {
	if len(os.Args) < 4 {
		log.Printf("Error! Not enough arguments provided.")
		log.Printf(genericError)
		return
	}

	key := os.Args[1]
	value := os.Args[3]

	util.ConnectToStdIn(FilterOperator{key, value, util.NewJsonWriter()})
}
Exemplo n.º 8
0
func Build(args []string) (util.SumoOperator, error) {
	if len(args) < 4 {
		return nil, util.ParseError("Error! Not enough arguments provided.\n" + genericError)
	}

	key := args[1]
	eq := args[2]
	if eq != "=" {
		return nil, util.ParseError("Expected `=` found `" + eq + "`\n" + genericError)
	}
	value := args[3]

	return &FilterOperator{key, value, util.NewJsonWriter()}, nil
}
Exemplo n.º 9
0
func makeSum(key string) sum {
	sumV := 0.0
	return sum{&sumV, key, make(map[string]interface{}), util.NewJsonWriter().Write}

}
Exemplo n.º 10
0
func makeCount() count {
	ct := 0
	return count{&ct, make(map[string]interface{}), util.NewJsonWriter().Write}
}