Пример #1
0
func NewConnectedRenderState(flush func() error) *RenderState {
	messages := make([]map[string]interface{}, 0)
	meta := make(map[string]interface{})
	state := &RenderState{&messages, &meta, flush}
	go util.ConnectToStdIn(state)
	return state
}
Пример #2
0
func handleErrorOrWire(operator util.SumoOperator, err error) {
	if err != nil {
		fmt.Println(err)
	} else {
		util.ConnectToStdIn(operator)
	}
}
Пример #3
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()})
}
Пример #4
0
func main() {
	operators := map[string]Builder{
		"parse":  parse.Build,
		"filter": filter.Build,
		"expr":   expr.Build,
	}

	aggOperators := map[string]AggBuilder{
		"count":   count.Build,
		"average": average.Build,
		"sum":     sum.Build,
	}

	args := os.Args
	if len(args) == 1 {
		fmt.Println("Arguments expected")
	} else {
		selectingArg := args[1]
		builder, ok := operators[selectingArg]
		if !ok {
			aggBuilder, aggOk := aggOperators[selectingArg]
			if !aggOk {
				fmt.Println("Operator " + selectingArg + " not found")
				return
			}
			aggOperator, err := aggBuilder(os.Args[1:])
			if err != nil {
				fmt.Println(err)
			} else {
				ticker := time.NewTicker(100 * time.Millisecond)
				go flush(aggOperator, ticker)
				util.ConnectToStdIn(aggOperator)
				// Flush when the stream completes to ensure all data is accounted for
				aggOperator.Flush()
			}
			return
		}

		operator, err := builder(os.Args[1:])
		if err != nil {
			fmt.Println(err)
		} else {
			util.ConnectToStdIn(operator)
		}
	}
}
Пример #5
0
func main() {
	m := make(map[string]int)
	cols := []string{}
	cmd := exec.Command("stty", "size")
	cmd.Stdin = os.Stdout
	out, _ := cmd.Output()
	wh := strings.Split(string(out), " ")
	hstr := strings.Trim(wh[0], "\n")
	wstr := strings.Trim(wh[1], "\n")
	height, _ := strconv.ParseInt(hstr, 10, 64)
	width, _ := strconv.ParseInt(wstr, 10, 64)

	rows := int64(0)

	if len(os.Args) == 2 && os.Args[1] == "noraw" {
		util.ConnectToStdIn(Renderer{false, &m, &cols, height, width, &rows})
	} else {
		util.ConnectToStdIn(Renderer{true, &m, &cols, height, width, &rows})
	}
}
Пример #6
0
func main() {
	relevantArgs := os.Args[1:]

	if len(relevantArgs) == 1 {
		ticker := time.NewTicker(1 * time.Second)
		avg := makeSum(relevantArgs[0])
		go flush(avg, ticker)
		util.ConnectToStdIn(avg)
		avg.Flush()
	} else if len(relevantArgs) > 1 {
		key := relevantArgs[0]
		//_ := relevantArgs[1]
		keyFields := relevantArgs[2:]
		agg := grouper.NewAggregate(aggregateSum, keyFields, key)
		util.ConnectToStdIn(agg)
		agg.Flush()
	} else {
		fmt.Println("Need a argument to average (`sum field`)")
	}

}
Пример #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()})
}
Пример #8
0
func connectAggOperator(selector string, args []string) bool {
	aggBuilder, aggOk := aggOperators[selector]
	if !aggOk {
		return false
	}

	aggOperator, err := aggBuilder(args)
	if err != nil {
		fmt.Println(err)
	} else {
		ticker := time.NewTicker(100 * time.Millisecond)
		go flush(aggOperator, ticker)
		util.ConnectToStdIn(aggOperator)
		// Flush when the stream completes to ensure all data is accounted for
		aggOperator.Flush()
	}
	return true
}