Exemplo n.º 1
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.º 2
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.º 3
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.º 4
0
func Build(args []string) (util.SumoAggOperator, error) {
	args = args[1:]

	if len(args) == 1 {
		return makeAverage(args[0]), nil
	} else if len(args) > 1 {
		key := args[0]
		//_ := args[1]
		keyFields := args[2:]
		return grouper.NewAggregate(aggregateAverage, keyFields, key), nil
	} else {
		return nil, util.ParseError("Need a argument to average (`avg keyname`)")
	}
}
Exemplo n.º 5
0
func Build(args []string) (util.SumoAggOperator, error) {
	// Fist arg is "sum"
	args = args[1:]
	if len(args) == 1 {
		return makeSum(args[0]), nil
	} else if len(args) > 1 {
		key := args[0]
		//_ := relevantArgs[1]
		keyFields := args[2:]
		return grouper.NewAggregate(aggregateSum, keyFields, key), nil
	} else {
		return nil, util.ParseError("Need a argument to average (`sum field`)")
	}
}