A go package for Redshift Lambda UDF Multiplexer
go get -u github.com/mashiike/gravita
most simple case:
func main() {
mux := gravita.NewMux()
mux.HandleFunc("*", func(ctx context.Context, args [][]interface{}) ([]interface{}, error) {
ret := make([]interface{}, 0, len(args))
// anything do
return ret, nil
})
lambda.Start(mux.HandleLambdaEvent)
}
If each row is independent, can also do the following:
func main() {
mux := gravita.NewMux()
mux.HandleRowFunc("*", func(_ context.Context, args []interface{}) (interface{}, error) {
return fmt.Sprint(args...), nil
})
lambda.Start(mux.HandleLambdaEvent)
}
If you want to do batch processing, you can do the following:
func main() {
mux := gravita.NewMux()
handler := gravita.NewBatchProcessHandler(
100, //batchSize
gravita.LambdaUDFHandlerFunc(func(ctx context.Context, args [][]interface{}) ([]interface{}, error) {
//Called in small batches, len(args) == batchSize
ret := make([]interface{}, 0, len(args))
// anything do
return ret, nil
}),
)
mux.Handle("*", handler)
lambda.Start(mux.HandleLambdaEvent)
}
MIT License
Copyright (c) 2022 IKEDA Masashi