Back to godoc.org
github.com/grailbio/bigslice/slicefunc

package slicefunc

v0.0.0 (8e22b3d)
Latest Go to latest
Published: May 28, 2020 | License: Apache-2.0 | Module: github.com/grailbio/bigslice

Overview

Package slicefunc provides types and code to call user-defined functions with Bigslice.

Index

type Func

type Func struct {
	// In and Out represent the slicetype of the function's input and output,
	// respectively.
	In, Out slicetype.Type
	// contains filtered or unexported fields
}

Func represents a user-defined function within Bigslice. Currently it's a simple shim that's used to determine whether a context should be supplied to the callee.

TODO(marius): Evolve this abstraction over time to avoid the use of reflection. For example, we can generate (via a template) code for invocations on common types. Having this abstraction in place makes this possible to do without changing any of the callers.

TODO(marius): Another possibility is to exploit the fact that we have already typechecked the data pipeline within Bigslice, and thus can avoid the per-call typechecking overhead that is incurred by reflection. For example, we could allow Funcs to mint a new re-usable call frame that we can write values directly into. This might get us most of the former but with more generality and arguably less complexity. We could even pre-generate call frames for each row in a frame, since that is re-used also.

TODO(marius): consider using this package to allow user-defined funcs to return an error in the last argument.

var Nil Func

Nil is a nil Func.

func Of

func Of(fn interface{}) Func

Of creates a Func from the provided function. Of panics if fn is not a func.

func (Func) Call

func (f Func) Call(ctx context.Context, args []reflect.Value) []reflect.Value

Call invokes the function with the provided arguments, and returns the reflected return values.

TODO(marius): using reflect.Value here is not ideal for performance, but there may be more holistic approaches (see above) since we're (almost) always invoking functions from frames.

func (Func) IsNil

func (f Func) IsNil() bool

IsNil returns whether the Func f is nil.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier