Skip to content

mashiike/gravita

Repository files navigation

gravita

A go package for Redshift Lambda UDF Multiplexer

GoDoc Github Actions test Go Report Card License

Install

go get -u github.com/mashiike/gravita

Examples

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)
}

LICENSE

MIT License

Copyright (c) 2022 IKEDA Masashi

About

A go handler package for Redshift Lambda UDF

Topics

Resources

License

Stars

Watchers

Forks

Languages