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()}) }
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 }
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} }
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 }
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 }
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() }
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()}) }
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 }
func makeSum(key string) sum { sumV := 0.0 return sum{&sumV, key, make(map[string]interface{}), util.NewJsonWriter().Write} }
func makeCount() count { ct := 0 return count{&ct, make(map[string]interface{}), util.NewJsonWriter().Write} }