expr

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2023 License: Apache-2.0 Imports: 11 Imported by: 6

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuncArgFromProto

func FuncArgFromProto(e *proto.FunctionArgument, baseSchema types.Type, reg ExtensionRegistry) (types.FuncArg, error)

func FuncArgsEqual

func FuncArgsEqual(a, b types.FuncArg) bool

Types

type AggregateFunction

type AggregateFunction struct {
	Sorts []SortField
	// contains filtered or unexported fields
}

func NewAggregateFunctionFromProto

func NewAggregateFunctionFromProto(agg *proto.AggregateFunction, baseSchema types.Type, reg ExtensionRegistry) (*AggregateFunction, error)

func (*AggregateFunction) Arg

func (a *AggregateFunction) Arg(i int) types.FuncArg

func (*AggregateFunction) CompoundName added in v0.4.2

func (a *AggregateFunction) CompoundName() string

func (*AggregateFunction) Decomposable

func (a *AggregateFunction) Decomposable() extensions.DecomposeType

func (*AggregateFunction) Deterministic

func (a *AggregateFunction) Deterministic() bool

func (*AggregateFunction) GetOption

func (a *AggregateFunction) GetOption(name string) []string

func (*AggregateFunction) GetType

func (a *AggregateFunction) GetType() types.Type

func (*AggregateFunction) ID

func (*AggregateFunction) IntermediateType

func (a *AggregateFunction) IntermediateType() (types.Type, error)

func (*AggregateFunction) Invocation

func (*AggregateFunction) MaxSet

func (a *AggregateFunction) MaxSet() int

func (*AggregateFunction) NArgs

func (a *AggregateFunction) NArgs() int

func (*AggregateFunction) Name

func (a *AggregateFunction) Name() string

func (*AggregateFunction) Ordered

func (a *AggregateFunction) Ordered() bool

func (*AggregateFunction) Phase

func (*AggregateFunction) SessionDependant

func (a *AggregateFunction) SessionDependant() bool

func (*AggregateFunction) String

func (a *AggregateFunction) String() string

func (*AggregateFunction) ToProto

func (*AggregateFunction) Variadic

type Bound

type Bound interface {
	ToProto() *proto.Expression_WindowFunction_Bound
}

type Builder added in v0.3.0

type Builder interface {
	BuildExpr() (Expression, error)
}

Builder is a basic interface for any type which can construct an expression. The `Build` method will be reserved for producing a concrete type while `BuildExpr` will exist for compatibility with this interface for ease of use. Typically it will be implemented as a simply a call to Build anyways.

type ByteSliceLiteral

type ByteSliceLiteral[T ~[]byte] struct {
	Value T
	Type  types.Type
}

ByteSliceLiteral is any literal that is represnted as a byte slice. As opposed to a string literal which can be compared with ==, a byte slice needs to use something like bytes.Equal

func NewByteSliceLiteral

func NewByteSliceLiteral[T []byte | types.UUID](val T, nullable bool) *ByteSliceLiteral[T]

func NewFixedBinaryLiteral

func NewFixedBinaryLiteral(val types.FixedBinary, nullable bool) *ByteSliceLiteral[types.FixedBinary]

func (*ByteSliceLiteral[T]) Equals

func (t *ByteSliceLiteral[T]) Equals(rhs Expression) bool

func (*ByteSliceLiteral[T]) GetType

func (t *ByteSliceLiteral[T]) GetType() types.Type

func (*ByteSliceLiteral[T]) IsScalar

func (*ByteSliceLiteral[T]) IsScalar() bool

func (*ByteSliceLiteral[T]) String

func (t *ByteSliceLiteral[T]) String() string

func (*ByteSliceLiteral[T]) ToProto

func (t *ByteSliceLiteral[T]) ToProto() *proto.Expression

func (*ByteSliceLiteral[T]) ToProtoFuncArg

func (t *ByteSliceLiteral[T]) ToProtoFuncArg() *proto.FunctionArgument

func (*ByteSliceLiteral[T]) ToProtoLiteral

func (t *ByteSliceLiteral[T]) ToProtoLiteral() *proto.Expression_Literal

func (*ByteSliceLiteral[T]) Visit

func (t *ByteSliceLiteral[T]) Visit(VisitFunc) Expression

type Cast

type Cast struct {
	Type            types.Type
	Input           Expression
	FailureBehavior types.CastFailBehavior
}

func (*Cast) Equals

func (ex *Cast) Equals(other Expression) bool

func (*Cast) GetType

func (ex *Cast) GetType() types.Type

func (*Cast) IsScalar

func (ex *Cast) IsScalar() bool

func (*Cast) String

func (ex *Cast) String() string

func (*Cast) ToProto

func (ex *Cast) ToProto() *proto.Expression

func (*Cast) ToProtoFuncArg

func (ex *Cast) ToProtoFuncArg() *proto.FunctionArgument

func (*Cast) Visit

func (ex *Cast) Visit(visit VisitFunc) Expression

type CurrentRow

type CurrentRow struct{}

func (CurrentRow) ToProto

type ExprBuilder added in v0.3.0

type ExprBuilder struct {
	Reg        ExtensionRegistry
	BaseSchema *types.StructType
}

ExprBuilder is the parent context for all the expression builders. It maintains a pointer to an extension registry and, optionally, a pointer to a base input schema. This allows less verbose expression building as it isn't necessary to pass these to every `New*` function to construct the expressions.

This is intended to be used like:

    b := expr.ExprBuilder{
	       Reg: ...,
        BaseSchema: ...,
    }
    e, err := b.ScalarFunc(fnID, options...).Args(
        b.RootRef(expr.NewStructFieldRef(1)),
        b.ScalarFunc(fn2ID, options2...).Args(
            b.Wrap(expr.NewLiteral(int32(5), false /* nullable type */)),
            b.RootRef(expr.NewStructFieldRef(2))))

See the unit tests for additional examples / constructs.

func (*ExprBuilder) AggFunc added in v0.3.0

func (e *ExprBuilder) AggFunc(id extensions.ID, opts ...*types.FunctionOption) *aggregateFuncBuilder

AggFunc returns a builder for the aggregate function represented by the passed in ID and options. Other properties such as Arguments, aggregation phase, invocation, sort fields, etc. can be then added via individual methods on the returned builder. Validity of the ID, argument types and number of arguments will be checked at the point that the Build method is called to construct the final expression and will return an error if invalid.

The extension registry inside of ExprBuilder will be used to resolve the ID, but only at the point at which Build is called. Therefore this can be called before actually loading the extensions as long as the extension identified by the ID is loaded into the registry *before* `Build` is called.

func (*ExprBuilder) Cast added in v0.3.0

func (e *ExprBuilder) Cast(from Builder, to types.Type) *castBuilder

Cast returns a builder for constructing a Cast expression. The failure behavior can be specified by calling FailBehavior before calling Build.

func (*ExprBuilder) Enum added in v0.3.0

func (e *ExprBuilder) Enum(val string) enumWrapper

Enum wraps a string representing an Enum argument to a function being built.

func (*ExprBuilder) Literal added in v0.3.0

func (e *ExprBuilder) Literal(l Literal) literalWrapper

Literal returns a wrapped literal that can be passed as an argument to any of the other expression builders such as ScalarFunc.Args.

func (*ExprBuilder) Ref added in v0.3.0

func (e *ExprBuilder) Ref(root RootRefType, ref Reference) *fieldRefBuilder

Ref constructs a field reference with the provided root and reference type. When `Build` is called on the returned builder, the `BaseSchema` in ExprBuilder will be used to resolve the type of the expression if relevant (such as a StructFieldRef/ListRef/MapKeyRef).

func (*ExprBuilder) RootRef added in v0.3.0

func (e *ExprBuilder) RootRef(ref Reference) *fieldRefBuilder

RootRef is a convenience method equivalent to calling ExprBuilder.Ref with `expr.RootReference` as the first argument.

func (*ExprBuilder) ScalarFunc added in v0.3.0

func (e *ExprBuilder) ScalarFunc(id extensions.ID, opts ...*types.FunctionOption) *scalarFuncBuilder

ScalarFunc returns a builder for the scalar function represented by the passed in ID and options. Use the Args method to add arguments to this builder. Validity of the ID, argument types and number of arguments will be checked at the point that the Build method is called to construct the final expression and will return an error if invalid.

The extension registry inside of ExprBuilder will be used to resolve the ID, but only at the point at which Build is called. Therefore this can be called before actually loading the extensions as long as the extension identified by the ID is loaded into the registry *before* `Build` is called.

func (*ExprBuilder) WindowFunc added in v0.3.0

func (e *ExprBuilder) WindowFunc(id extensions.ID, opts ...*types.FunctionOption) *windowFuncBuilder

WindowFunc returns a builder for the window function represented by the passed in ID and options. Other properties such as Arguments, aggregation phase, invocation, sort fields, etc. can be then added via individual methods on the returned builder. Validity of the ID, argument types and number of arguments will be checked at the point that the Build method is called to construct the final expression and will return an error if invalid.

The extension registry inside of ExprBuilder will be used to resolve the ID, but only at the point at which Build is called. Therefore this can be called before actually loading the extensions as long as the extension identified by the ID is loaded into the registry *before* `Build` is called.

func (*ExprBuilder) Wrap added in v0.3.0

func (e *ExprBuilder) Wrap(l Literal, err error) literalWrapper

Wrap is like Literal but allows propagating an error (such as when calling expr.NewLiteral) that will bubble up when attempting to build an expression so it doesn't get swallowed or force a panic.

type Expression

type Expression interface {
	// an Expression can also be a function argument
	types.FuncArg
	// an expression can also be the root of a reference
	RootRefType

	IsScalar() bool
	// GetType returns the output type of this expression
	GetType() types.Type
	// ToProto converts this Expression and its arguments
	// to the equivalent Protobuf objects.
	ToProto() *proto.Expression
	// Equals returns true if this expression and all of its
	// arguments and their children etc. are equal to the passed
	// in Expression.
	Equals(Expression) bool
	// Visit invokes the passed visit function for each child of the
	// expression. The visit function can return its input expression
	// as-is with no changes, or it can construct and return a
	// replacement expression. If any children have been replaced, Visit
	// will construct and return a new instance of this expression using
	// the new children. Callers can use the Visit method to traverse
	// and potentially rewrite the expression tree, in either pre or post
	// order. Here is a pre-order example:
	//
	//   func preOrderVisit(e Expression) Expression {
	//     // Replace some scalar function, leave everything else
	//     // as-is. This check is before the call to Visit, so
	//     // it's a pre-order traversal
	//     if f, ok := e.(*ScalarFunction); ok {
	//       return &ScalarFunction{
	//         ID: ExtID{URI: "some other uri", Name: "some other func"},
	//         Args: f.Args,
	//         Options: f.Options,
	//         OutputType: f.OutputType,
	//       }
	//     }
	//     return e.Visit(preOrderVisit)
	//   }
	//   newExpr := preOrderVisit(oldExpr)
	Visit(VisitFunc) Expression
}

Expression can be one of many different things as a generalized expression. It could be:

  • A literal
  • A Field Reference Selection
  • A Scalar Function expression
  • A Window Function expression
  • An If-Then statement
  • A Switch Expression
  • A Singular Or List
  • A Multiple Or List
  • A Cast expression
  • A Subquery
  • A Nested expression
Example (ScalarFunction)
package main

import (
	"fmt"
	"strings"

	"github.com/substrait-io/substrait-go/expr"

	ext "github.com/substrait-io/substrait-go/extensions"
	"github.com/substrait-io/substrait-go/proto"
	"github.com/substrait-io/substrait-go/types"
	"google.golang.org/protobuf/encoding/protojson"

	pb "google.golang.org/protobuf/proto"
)

const sampleYAML = `---
scalar_functions:
  -
    name: "add"
    description: "Add two values."
    impls:
      - args:
          - name: x
            value: i8
          - name: y
            value: i8
        options:
          overflow:
            values: [ SILENT, SATURATE, ERROR ]
        return: i8
`

var collection ext.Collection

func init() {
	collection.Load("https://github.com/substrait-io/substrait/blob/main/extensions/functions_arithmetic.yaml", strings.NewReader(sampleYAML))
}

func main() {
	// define extensions with no plan for now
	const planExt = `{
		"extensionUris": [
			{
				"extensionUriAnchor": 1,
				"uri": "https://github.com/substrait-io/substrait/blob/main/extensions/functions_arithmetic.yaml"
			}
		],
		"extensions": [
			{
				"extensionFunction": {
					"extensionUriReference": 1,
					"functionAnchor": 2,
					"name": "add:i32_i32"
				}
			}
		],
		"relations": []
	}`

	var plan proto.Plan
	if err := protojson.Unmarshal([]byte(planExt), &plan); err != nil {
		panic(err)
	}

	// get the extension set
	extSet := ext.GetExtensionSet(&plan)

	// json proto to represent of add(field_ref(0), float64(10))
	const scalarFunction = `{
		"scalarFunction": {
		  "functionReference": 2,
		  "outputType": {"i32": {}},
		  "arguments": [
			{"value": {"selection": {
				"rootReference": {},
				"directReference": {"structField": {"field": 0}}}}},
			{"value": {"literal": {"fp64": 10}}}
		  ]
		}
	  }`

	var exprProto proto.Expression
	if err := protojson.Unmarshal([]byte(scalarFunction), &exprProto); err != nil {
		panic(err)
	}

	reg := expr.NewExtensionRegistry(extSet, &collection)
	// convert from protobuf to Expression!
	fromProto, err := expr.ExprFromProto(&exprProto, nil, reg)
	if err != nil {
		panic(err)
	}

	// manually define the entire expression instead of going through
	// having to construct the protobuf
	const substraitext = `https://github.com/substrait-io/substrait/blob/main/extensions/functions_arithmetic.yaml`

	var addVariant = ext.NewScalarFuncVariant(ext.ID{URI: substraitext, Name: "add:i32_i32"})

	var ex expr.Expression
	refArg, _ := expr.NewRootFieldRef(expr.NewStructFieldRef(0), &types.StructType{Types: []types.Type{&types.Int32Type{}}})
	ex, _ = expr.NewCustomScalarFunc(reg, addVariant, &types.Int32Type{}, nil,
		refArg, expr.NewPrimitiveLiteral(float64(10), false))

	// call ToProto to convert our manual expression to proto.Expression
	toProto := ex.ToProto()

	// output some info!

	// print string represention of the expression
	fmt.Println(fromProto)
	// print the string representation of our
	// manually constructed expression
	fmt.Println(ex)

	// verify that the Equals methods work recursively
	fmt.Println(ex.Equals(fromProto))
	// confirm our manually constructed expression is the same
	// as the one we got from protojson
	fmt.Println(pb.Equal(&exprProto, toProto))

}
Output:

add(.field(0), fp64(10)) => i32
add(.field(0) => i32, fp64(10)) => i32
true
true

func ExprFromProto

func ExprFromProto(e *proto.Expression, baseSchema types.Type, reg ExtensionRegistry) (Expression, error)

func MustExpr

func MustExpr(e Expression, err error) Expression

MustExpr is a helper function to avoid having it get written and re-written by everyone. It takes an expression and an error and will panic if the error is non-nil, otherwise returning the expression.

This is intended for situations where it's okay to panic, like testing, to make it more convenient when building expressions to use the `New...` functions that return some expression and potentially an error. For instance:

NewScalarFunc(reg, id, nil, MustExpr(NewRootFieldRef(...)),
    MustExpr(NewScalarFunc(...)))

type ExpressionReference

type ExpressionReference struct {
	OutputNames []string
	// contains filtered or unexported fields
}

func NewExpressionReference

func NewExpressionReference(names []string, ex Expression) ExpressionReference

func NewMeasureReference

func NewMeasureReference(names []string, measure *AggregateFunction) ExpressionReference

func (*ExpressionReference) GetExpr

func (er *ExpressionReference) GetExpr() Expression

func (*ExpressionReference) GetMeasure

func (er *ExpressionReference) GetMeasure() *AggregateFunction

func (*ExpressionReference) SetExpr

func (er *ExpressionReference) SetExpr(ex Expression)

func (*ExpressionReference) SetMeasure

func (er *ExpressionReference) SetMeasure(m *AggregateFunction)

func (*ExpressionReference) ToProto

type Extended

type Extended struct {
	Version          *types.Version
	Extensions       extensions.Set
	ReferredExpr     []ExpressionReference
	BaseSchema       types.NamedStruct
	AdvancedExts     *extensions.AdvancedExtension
	ExpectedTypeURLs []string
}

func ExtendedFromProto

func ExtendedFromProto(ex *proto.ExtendedExpression, c *extensions.Collection) (*Extended, error)

func (*Extended) ToProto

func (ex *Extended) ToProto() *proto.ExtendedExpression

type ExtensionRegistry

type ExtensionRegistry struct {
	extensions.Set
	// contains filtered or unexported fields
}

func NewEmptyExtensionRegistry

func NewEmptyExtensionRegistry(c *extensions.Collection) ExtensionRegistry

func NewExtensionRegistry

func NewExtensionRegistry(extSet extensions.Set, c *extensions.Collection) ExtensionRegistry

func (*ExtensionRegistry) LookupAggregateFunction

func (e *ExtensionRegistry) LookupAggregateFunction(anchor uint32) (*extensions.AggregateFunctionVariant, bool)

func (*ExtensionRegistry) LookupScalarFunction

func (e *ExtensionRegistry) LookupScalarFunction(anchor uint32) (*extensions.ScalarFunctionVariant, bool)

func (*ExtensionRegistry) LookupType

func (e *ExtensionRegistry) LookupType(anchor uint32) (extensions.Type, bool)

func (*ExtensionRegistry) LookupTypeVariation

func (e *ExtensionRegistry) LookupTypeVariation(anchor uint32) (extensions.TypeVariation, bool)

func (*ExtensionRegistry) LookupWindowFunction

func (e *ExtensionRegistry) LookupWindowFunction(anchor uint32) (*extensions.WindowFunctionVariant, bool)

type FieldReference

type FieldReference struct {
	Reference Reference
	Root      RootRefType
	// contains filtered or unexported fields
}

func FieldReferenceFromProto

func FieldReferenceFromProto(p *proto.Expression_FieldReference, baseSchema types.Type, reg ExtensionRegistry) (*FieldReference, error)

func NewFieldRef

func NewFieldRef(root RootRefType, ref Reference, baseSchema *types.StructType) (*FieldReference, error)

func NewRootFieldRef

func NewRootFieldRef(ref Reference, baseSchema *types.StructType) (*FieldReference, error)

func (*FieldReference) Equals

func (f *FieldReference) Equals(rhs Expression) bool

func (*FieldReference) GetType

func (f *FieldReference) GetType() types.Type

func (*FieldReference) IsScalar

func (*FieldReference) IsScalar() bool

func (*FieldReference) String

func (f *FieldReference) String() string

func (*FieldReference) ToProto

func (f *FieldReference) ToProto() *proto.Expression

func (*FieldReference) ToProtoFieldRef

func (f *FieldReference) ToProtoFieldRef() *proto.Expression_FieldReference

func (*FieldReference) ToProtoFuncArg

func (f *FieldReference) ToProtoFuncArg() *proto.FunctionArgument

func (*FieldReference) Visit

func (f *FieldReference) Visit(v VisitFunc) Expression

type FollowingBound

type FollowingBound int64

func (FollowingBound) ToProto

type FuncArgBuilder added in v0.3.0

type FuncArgBuilder interface {
	BuildFuncArg() (types.FuncArg, error)
}

type IfThen

type IfThen struct {
	// contains filtered or unexported fields
}

func NewIfThen

func NewIfThen(firstIf IfThenPair, elseClause Expression, elsifs ...IfThenPair) (*IfThen, error)

NewIfThen constructs a new IfThen expression, verifying it is valid.

elseClause should not be nil as there is a required default via the else. The constructed expression would be interpreted as this pseudocode:

if <firstIf.If> then <firstIf.Then>
foreach e in elsifs:
 if <e.If> then <e.Then>
endforeach
else <elseClause>

If elseClause is nil or all of the result expressions do not have the same result type, an error will be returned.

func (*IfThen) Else

func (ex *IfThen) Else() Expression

func (*IfThen) Equals

func (ex *IfThen) Equals(other Expression) bool

func (*IfThen) GetType

func (ex *IfThen) GetType() types.Type

func (*IfThen) IfPair

func (ex *IfThen) IfPair(i int) IfThenPair

IfPair returns the IfThenPair for the given index. It is not bounds-checked

func (*IfThen) IsScalar

func (ex *IfThen) IsScalar() bool

func (*IfThen) NIfs

func (ex *IfThen) NIfs() int

NIfs returns the number of If/then pairs are in this expression before the else clause. It should always be at least 1

func (*IfThen) String

func (ex *IfThen) String() string

func (*IfThen) ToProto

func (ex *IfThen) ToProto() *proto.Expression

func (*IfThen) ToProtoFuncArg

func (ex *IfThen) ToProtoFuncArg() *proto.FunctionArgument

func (*IfThen) Visit

func (ex *IfThen) Visit(visit VisitFunc) Expression

type IfThenPair

type IfThenPair struct {
	If   Expression
	Then Expression
}

type ListElementRef

type ListElementRef struct {
	Offset int32
	Child  ReferenceSegment
}

func NewListElemRef

func NewListElemRef(offset int32) *ListElementRef

func (*ListElementRef) Equals

func (r *ListElementRef) Equals(rhs ReferenceSegment) bool

func (*ListElementRef) GetChild

func (r *ListElementRef) GetChild() ReferenceSegment

func (*ListElementRef) GetType

func (r *ListElementRef) GetType(parentType types.Type) (types.Type, error)

func (*ListElementRef) String

func (r *ListElementRef) String() string

func (*ListElementRef) ToProto

type ListExpr

type ListExpr struct {
	Nullable         bool
	TypeVariationRef uint32
	Values           []Expression
}

func NewListExpr

func NewListExpr(nullable bool, vals ...Expression) *ListExpr

func (*ListExpr) Equals

func (ex *ListExpr) Equals(other Expression) bool

func (*ListExpr) GetType

func (ex *ListExpr) GetType() types.Type

func (*ListExpr) IsNullable

func (ex *ListExpr) IsNullable() bool

func (*ListExpr) IsScalar

func (ex *ListExpr) IsScalar() bool

func (*ListExpr) String

func (ex *ListExpr) String() string

func (*ListExpr) ToProto

func (ex *ListExpr) ToProto() *proto.Expression

func (*ListExpr) ToProtoFuncArg

func (ex *ListExpr) ToProtoFuncArg() *proto.FunctionArgument

func (*ListExpr) TypeVariation

func (ex *ListExpr) TypeVariation() uint32

func (*ListExpr) Visit

func (ex *ListExpr) Visit(visit VisitFunc) Expression

type ListLiteral

type ListLiteral = NestedLiteral[ListLiteralValue]

Convenience names so that there is StructLiteral, ListLiteral and MapLiteral

func NewEmptyListLiteral

func NewEmptyListLiteral(t types.Type, nullable bool) *ListLiteral

NewEmptyListLiteral creates an empty list literal of the type and marks the type as nullable or not.

type ListLiteralValue

type ListLiteralValue []Literal

ListLiteralValue is a slice of other literals

type Literal

type Literal interface {
	// Literals are also Function arguments
	types.FuncArg
	RootRefType
	fmt.Stringer

	IsScalar() bool
	// GetType returns the full Type of the literal value
	GetType() types.Type
	// Equals only returns true if the rhs is a literal of the exact
	// same type and value.
	Equals(Expression) bool
	ToProto() *proto.Expression
	ToProtoLiteral() *proto.Expression_Literal
	Visit(VisitFunc) Expression
}

Literal represents a specific literal of some type which could also be a typed null or a nested type like a struct/map/list.

An empty map/empty list will have len(value) == 0

func LiteralFromProto

func LiteralFromProto(l *proto.Expression_Literal) Literal

LiteralFromProto constructs the appropriate Literal struct from a protobuf message.

func NewLiteral

func NewLiteral[T allLiteralTypes](val T, nullable bool) (Literal, error)

func NewNestedLiteral

func NewNestedLiteral[T StructLiteralValue | MapLiteralValue | ListLiteralValue](val T, nullable bool) Literal

NewNestedLiteral constructs a new literal value and marks whether the type should be considered nullable. This assumes that the passed in value is not empty, so len(v) MUST be > 0.

For an Empty Map literal or an empty List literal, you need to use the corresponding NewEmptyMapLiteral and NewEmptyListLiteral functions which take the Type of the empty literal as an argument.

func NewPrimitiveLiteral

func NewPrimitiveLiteral[T newPrimitiveLiteralTypes](val T, nullable bool) Literal

type MapExpr

type MapExpr struct {
	Nullable         bool
	TypeVariationRef uint32
	KeyValues        []struct{ Key, Value Expression }
}

func (*MapExpr) Equals

func (ex *MapExpr) Equals(other Expression) bool

func (*MapExpr) GetType

func (ex *MapExpr) GetType() types.Type

func (*MapExpr) IsNullable

func (ex *MapExpr) IsNullable() bool

func (*MapExpr) IsScalar

func (ex *MapExpr) IsScalar() bool

func (*MapExpr) String

func (ex *MapExpr) String() string

func (*MapExpr) ToProto

func (ex *MapExpr) ToProto() *proto.Expression

func (*MapExpr) ToProtoFuncArg

func (ex *MapExpr) ToProtoFuncArg() *proto.FunctionArgument

func (*MapExpr) TypeVariation

func (ex *MapExpr) TypeVariation() uint32

func (*MapExpr) Visit

func (ex *MapExpr) Visit(visit VisitFunc) Expression

type MapKeyRef

type MapKeyRef struct {
	MapKey Literal
	Child  ReferenceSegment
}

func NewMapKeyRef

func NewMapKeyRef(key Literal) *MapKeyRef

func (*MapKeyRef) Equals

func (r *MapKeyRef) Equals(rhs ReferenceSegment) bool

func (*MapKeyRef) GetChild

func (r *MapKeyRef) GetChild() ReferenceSegment

func (*MapKeyRef) GetType

func (r *MapKeyRef) GetType(parentType types.Type) (types.Type, error)

func (*MapKeyRef) String

func (r *MapKeyRef) String() string

func (*MapKeyRef) ToProto

type MapLiteral

type MapLiteral struct {
	Value MapLiteralValue
	Type  types.Type
}

MapLiteral is represented as a slice of Key/Value structs consisting of other literals.

func NewEmptyMapLiteral

func NewEmptyMapLiteral(key, val types.Type, nullable bool) *MapLiteral

NewEmptyMapLiteral creates an empty map literal of the provided key/value types and marks the type as nullable or not.

func (*MapLiteral) Equals

func (t *MapLiteral) Equals(rhs Expression) bool

func (*MapLiteral) GetType

func (t *MapLiteral) GetType() types.Type

func (*MapLiteral) IsScalar

func (*MapLiteral) IsScalar() bool

func (*MapLiteral) String

func (t *MapLiteral) String() string

func (*MapLiteral) ToProto

func (t *MapLiteral) ToProto() *proto.Expression

func (*MapLiteral) ToProtoFuncArg

func (t *MapLiteral) ToProtoFuncArg() *proto.FunctionArgument

func (*MapLiteral) ToProtoLiteral

func (t *MapLiteral) ToProtoLiteral() *proto.Expression_Literal

func (*MapLiteral) Visit

func (t *MapLiteral) Visit(VisitFunc) Expression

type MapLiteralValue

type MapLiteralValue []struct {
	Key   Literal
	Value Literal
}

Easy type aliases for multi-value types that also saves us having to create new types / new objects at runtime when getting them from protobuf.

type MapSelectKind added in v0.4.0

type MapSelectKind int8
const (
	MapSelectKey MapSelectKind = iota
	MapSelectExpr
)

type MaskExpression

type MaskExpression struct {
	// contains filtered or unexported fields
}

MaskExpression is a reference that takes an existing subtype and selectively removes fields from it. For example, one might initially have an inner struct with 100 fields, but a particular operation only needs to interact with 2 of those 100 fields. In this situation, one would use a mask expression to eliminate the 98 fields that are not relevant to the rest of the operations pipeline.

Note that this does not fundamentally alter the structure of data beyond the elimination of unnecessary elements.

func MaskExpressionFromProto added in v0.4.0

func MaskExpressionFromProto(p *proto.Expression_MaskExpression) *MaskExpression

func (*MaskExpression) MaintainSingularStruct added in v0.4.0

func (e *MaskExpression) MaintainSingularStruct() bool

func (*MaskExpression) Select added in v0.4.0

func (e *MaskExpression) Select() MaskStructSelect

func (*MaskExpression) ToProto added in v0.4.0

type MaskListElement added in v0.4.0

func (*MaskListElement) GetField added in v0.4.0

func (m *MaskListElement) GetField() int32

func (*MaskListElement) ToProto added in v0.4.0

type MaskListSelect added in v0.4.0

type MaskListSelect struct {
	// contains filtered or unexported fields
}

func (*MaskListSelect) Child added in v0.4.0

func (m *MaskListSelect) Child() MaskSelect

func (*MaskListSelect) Selection added in v0.4.0

func (m *MaskListSelect) Selection() []MaskListSelectItem

func (*MaskListSelect) ToProto added in v0.4.0

type MaskListSelectItem added in v0.4.0

type MaskListSelectItem interface {
	ToProto() *proto.Expression_MaskExpression_ListSelect_ListSelectItem
}

type MaskListSlice added in v0.4.0

func (*MaskListSlice) GetBounds added in v0.4.0

func (m *MaskListSlice) GetBounds() (start, end int32)

func (*MaskListSlice) ToProto added in v0.4.0

type MaskMapSelect added in v0.4.0

type MaskMapSelect struct {
	// contains filtered or unexported fields
}

func (*MaskMapSelect) Child added in v0.4.0

func (m *MaskMapSelect) Child() MaskSelect

func (*MaskMapSelect) Key added in v0.4.0

func (m *MaskMapSelect) Key() string

func (*MaskMapSelect) KeyKind added in v0.4.0

func (m *MaskMapSelect) KeyKind() MapSelectKind

func (*MaskMapSelect) ToProto added in v0.4.0

type MaskSelect added in v0.4.0

type MaskSelect interface {
	ToProto() *proto.Expression_MaskExpression_Select
}

type MaskStructItem added in v0.4.0

type MaskStructItem struct {
	// contains filtered or unexported fields
}

func (*MaskStructItem) Child added in v0.4.0

func (m *MaskStructItem) Child() MaskSelect

func (*MaskStructItem) Field added in v0.4.0

func (m *MaskStructItem) Field() int32

func (*MaskStructItem) ToProto added in v0.4.0

type MaskStructSelect added in v0.4.0

type MaskStructSelect []MaskStructItem

func (MaskStructSelect) ToProto added in v0.4.0

type MultiOrList

type MultiOrList struct {
	Value   []Expression
	Options [][]Expression
}

func (*MultiOrList) Equals

func (ex *MultiOrList) Equals(other Expression) bool

func (*MultiOrList) GetType

func (ex *MultiOrList) GetType() types.Type

func (*MultiOrList) IsScalar

func (ex *MultiOrList) IsScalar() bool

func (*MultiOrList) String

func (ex *MultiOrList) String() string

func (*MultiOrList) ToProto

func (ex *MultiOrList) ToProto() *proto.Expression

func (*MultiOrList) ToProtoFuncArg

func (ex *MultiOrList) ToProtoFuncArg() *proto.FunctionArgument

func (*MultiOrList) Visit

func (ex *MultiOrList) Visit(visit VisitFunc) Expression

type NestedExpr

type NestedExpr interface {
	Expression

	IsNullable() bool
	TypeVariation() uint32
}

type NestedLiteral

type NestedLiteral[T nestedLiteral] struct {
	Value T
	Type  types.Type
}

NestedLiteral is either a Struct or List literal, both of which are represented as a slice of other literals.

func (*NestedLiteral[T]) Equals

func (t *NestedLiteral[T]) Equals(rhs Expression) bool

func (*NestedLiteral[T]) GetType

func (t *NestedLiteral[T]) GetType() types.Type

func (*NestedLiteral[T]) IsScalar

func (*NestedLiteral[T]) IsScalar() bool

func (*NestedLiteral[T]) String

func (t *NestedLiteral[T]) String() string

func (*NestedLiteral[T]) ToProto

func (t *NestedLiteral[T]) ToProto() *proto.Expression

func (*NestedLiteral[T]) ToProtoFuncArg

func (t *NestedLiteral[T]) ToProtoFuncArg() *proto.FunctionArgument

func (*NestedLiteral[T]) ToProtoLiteral

func (t *NestedLiteral[T]) ToProtoLiteral() *proto.Expression_Literal

func (*NestedLiteral[T]) Visit

func (t *NestedLiteral[T]) Visit(VisitFunc) Expression

type Null

type Null types.Type

Null is a typed null value so it can be just a Type itself

type NullLiteral

type NullLiteral struct {
	Type types.Type
}

A NullLiteral is a typed null, so it just contains its type

func (*NullLiteral) Equals

func (n *NullLiteral) Equals(rhs Expression) bool

func (*NullLiteral) GetType

func (n *NullLiteral) GetType() types.Type

func (*NullLiteral) IsScalar

func (*NullLiteral) IsScalar() bool

func (*NullLiteral) String

func (n *NullLiteral) String() string

func (*NullLiteral) ToProto

func (n *NullLiteral) ToProto() *proto.Expression

func (*NullLiteral) ToProtoFuncArg

func (n *NullLiteral) ToProtoFuncArg() *proto.FunctionArgument

func (*NullLiteral) ToProtoLiteral

func (n *NullLiteral) ToProtoLiteral() *proto.Expression_Literal

func (*NullLiteral) Visit

func (n *NullLiteral) Visit(VisitFunc) Expression

type OuterReference

type OuterReference uint32

type PrecedingBound

type PrecedingBound int64

func (PrecedingBound) ToProto

type PrimitiveLiteral

type PrimitiveLiteral[T PrimitiveLiteralValue] struct {
	Value T
	Type  types.Type
}

PrimitiveLiteral represents a non-nested, non-null literal value which can be compared easily using ==

func NewFixedCharLiteral

func NewFixedCharLiteral(val types.FixedChar, nullable bool) *PrimitiveLiteral[types.FixedChar]

func (*PrimitiveLiteral[T]) Equals

func (t *PrimitiveLiteral[T]) Equals(rhs Expression) bool

func (*PrimitiveLiteral[T]) GetType

func (t *PrimitiveLiteral[T]) GetType() types.Type

func (*PrimitiveLiteral[T]) IsScalar

func (*PrimitiveLiteral[T]) IsScalar() bool

func (*PrimitiveLiteral[T]) String

func (t *PrimitiveLiteral[T]) String() string

func (*PrimitiveLiteral[T]) ToProto

func (t *PrimitiveLiteral[T]) ToProto() *proto.Expression

func (*PrimitiveLiteral[T]) ToProtoFuncArg

func (t *PrimitiveLiteral[T]) ToProtoFuncArg() *proto.FunctionArgument

func (*PrimitiveLiteral[T]) ToProtoLiteral

func (t *PrimitiveLiteral[T]) ToProtoLiteral() *proto.Expression_Literal

func (*PrimitiveLiteral[T]) Visit

func (t *PrimitiveLiteral[T]) Visit(VisitFunc) Expression

type PrimitiveLiteralValue

type PrimitiveLiteralValue interface {
	bool | int8 | int16 | ~int32 | ~int64 |
		float32 | float64 | ~string
}

PrimitiveLiteralValue is a type constraint that represents any of the non-nested literal types which are also easily comparable via ==

type ProtoLiteral

type ProtoLiteral struct {
	Value any
	Type  types.Type
}

ProtoLiteral is a literal that is represented using its protobuf message type such as a Decimal or UserDefinedType.

func (*ProtoLiteral) Equals

func (t *ProtoLiteral) Equals(rhs Expression) bool

func (*ProtoLiteral) GetType

func (t *ProtoLiteral) GetType() types.Type

func (*ProtoLiteral) IsScalar

func (*ProtoLiteral) IsScalar() bool

func (*ProtoLiteral) String

func (t *ProtoLiteral) String() string

func (*ProtoLiteral) ToProto

func (t *ProtoLiteral) ToProto() *proto.Expression

func (*ProtoLiteral) ToProtoFuncArg

func (t *ProtoLiteral) ToProtoFuncArg() *proto.FunctionArgument

func (*ProtoLiteral) ToProtoLiteral

func (t *ProtoLiteral) ToProtoLiteral() *proto.Expression_Literal

func (*ProtoLiteral) Visit

func (t *ProtoLiteral) Visit(VisitFunc) Expression

type Reference

type Reference interface {
	// contains filtered or unexported methods
}

type ReferenceSegment

type ReferenceSegment interface {
	Reference
	fmt.Stringer
	GetChild() ReferenceSegment
	GetType(types.Type) (types.Type, error)
	ToProto() *proto.Expression_ReferenceSegment
	Equals(ReferenceSegment) bool
}

func FlattenRefSegments

func FlattenRefSegments(refs ...ReferenceSegment) ReferenceSegment

type RootRefType

type RootRefType interface {
	// contains filtered or unexported methods
}
var RootReference RootRefType

type ScalarFunction

type ScalarFunction struct {
	// contains filtered or unexported fields
}

func NewCustomScalarFunc

func NewCustomScalarFunc(reg ExtensionRegistry, v *extensions.ScalarFunctionVariant, outputType types.Type, opts []*types.FunctionOption, args ...types.FuncArg) (*ScalarFunction, error)

NewCustomScalarFunc doesn't validate that the ID can be found already in the registry with LookupScalarFunction and will construct the function as provided as long as the outputType is non-nil. In this case, the registry is only used to provide an anchor / function reference that can be used when serializing this expression to Protobuf. Guaranteeing that you have a valid expression returned.

Currently an error is only returned if outputType == nil

func NewScalarFunc

func NewScalarFunc(reg ExtensionRegistry, id extensions.ID, opts []*types.FunctionOption, args ...types.FuncArg) (*ScalarFunction, error)

NewScalarFunc validates that the specified ID can be found in the registry via LookupScalarFunction and retrieves a function anchor to use.

If the name in the ID is not currently a compound signature and cannot be found in the registry, we'll attempt to construct the compound signature based on the types of the provided arguments and look it up that way. If both attempts fail to lookup the function, a substraitgo.ErrNotFound will be returned.

Currently the options are not validated against the function declaration but the number of arguments and their types will be validated in order to resolve the output type.

func (*ScalarFunction) Arg

func (s *ScalarFunction) Arg(i int) types.FuncArg

func (*ScalarFunction) CompoundName added in v0.4.2

func (s *ScalarFunction) CompoundName() string

func (*ScalarFunction) Deterministic

func (s *ScalarFunction) Deterministic() bool

func (*ScalarFunction) Equals

func (s *ScalarFunction) Equals(rhs Expression) bool

func (*ScalarFunction) FuncRef added in v0.2.0

func (s *ScalarFunction) FuncRef() uint32

func (*ScalarFunction) GetOption

func (s *ScalarFunction) GetOption(name string) []string

func (*ScalarFunction) GetType

func (s *ScalarFunction) GetType() types.Type

func (*ScalarFunction) ID

func (s *ScalarFunction) ID() extensions.ID

func (*ScalarFunction) IsScalar

func (s *ScalarFunction) IsScalar() bool

func (*ScalarFunction) NArgs

func (s *ScalarFunction) NArgs() int

func (*ScalarFunction) Name

func (s *ScalarFunction) Name() string

func (*ScalarFunction) SessionDependant

func (s *ScalarFunction) SessionDependant() bool

func (*ScalarFunction) String

func (s *ScalarFunction) String() string

func (*ScalarFunction) ToProto

func (s *ScalarFunction) ToProto() *proto.Expression

func (*ScalarFunction) ToProtoFuncArg

func (s *ScalarFunction) ToProtoFuncArg() *proto.FunctionArgument

func (*ScalarFunction) Variadic

func (*ScalarFunction) Visit

func (s *ScalarFunction) Visit(visit VisitFunc) Expression

type SingularOrList

type SingularOrList struct {
	Value   Expression
	Options []Expression
}

func (*SingularOrList) Equals

func (ex *SingularOrList) Equals(other Expression) bool

func (*SingularOrList) GetType

func (ex *SingularOrList) GetType() types.Type

func (*SingularOrList) IsScalar

func (ex *SingularOrList) IsScalar() bool

func (*SingularOrList) String

func (ex *SingularOrList) String() string

func (*SingularOrList) ToProto

func (ex *SingularOrList) ToProto() *proto.Expression

func (*SingularOrList) ToProtoFuncArg

func (ex *SingularOrList) ToProtoFuncArg() *proto.FunctionArgument

func (*SingularOrList) Visit

func (ex *SingularOrList) Visit(visit VisitFunc) Expression

type SortField

type SortField struct {
	Expr Expression
	Kind types.SortKind
}

func SortFieldFromProto

func SortFieldFromProto(f *proto.SortField, baseSchema types.Type, reg ExtensionRegistry) (sf SortField, err error)

func (*SortField) ToProto

func (s *SortField) ToProto() *proto.SortField

type StructExpr

type StructExpr struct {
	Nullable         bool
	TypeVariationRef uint32
	Fields           []Expression
}

func (*StructExpr) Equals

func (ex *StructExpr) Equals(other Expression) bool

func (*StructExpr) GetType

func (ex *StructExpr) GetType() types.Type

func (*StructExpr) IsNullable

func (ex *StructExpr) IsNullable() bool

func (*StructExpr) IsScalar

func (ex *StructExpr) IsScalar() bool

func (*StructExpr) String

func (ex *StructExpr) String() string

func (*StructExpr) ToProto

func (ex *StructExpr) ToProto() *proto.Expression

func (*StructExpr) ToProtoFuncArg

func (ex *StructExpr) ToProtoFuncArg() *proto.FunctionArgument

func (*StructExpr) TypeVariation

func (ex *StructExpr) TypeVariation() uint32

func (*StructExpr) Visit

func (ex *StructExpr) Visit(visit VisitFunc) Expression

type StructFieldRef

type StructFieldRef struct {
	Field int32
	Child ReferenceSegment
}

func NewStructFieldRef

func NewStructFieldRef(field int32) *StructFieldRef

func (*StructFieldRef) Equals

func (r *StructFieldRef) Equals(rhs ReferenceSegment) bool

func (*StructFieldRef) GetChild

func (r *StructFieldRef) GetChild() ReferenceSegment

func (*StructFieldRef) GetType

func (r *StructFieldRef) GetType(parentType types.Type) (types.Type, error)

func (*StructFieldRef) String

func (r *StructFieldRef) String() string

func (*StructFieldRef) ToProto

type StructLiteral

type StructLiteral = NestedLiteral[StructLiteralValue]

Convenience names so that there is StructLiteral, ListLiteral and MapLiteral

type StructLiteralValue

type StructLiteralValue []Literal

StructLiteralValue is a slice of other literals where each element in the slice is a different field in the struct

func StructLiteralFromProto added in v0.4.0

func StructLiteralFromProto(s *proto.Expression_Literal_Struct) StructLiteralValue

func (StructLiteralValue) ToProto added in v0.4.0

type SwitchExpr

type SwitchExpr struct {
	// contains filtered or unexported fields
}

func NewSwitch

func NewSwitch(match Expression, elseClause Expression, switchCases ...struct {
	If   Literal
	Then Expression
}) (*SwitchExpr, error)

NewSwitch constructs a switch statement. Will return an error in the following cases:

  • match is nil
  • len(switchCases) < 1
  • the type of the If literal in each switchCase != match.GetType()
  • the GetType for each "Then" of switch cases aren't the same
  • elseClause.GetType() != switchCases.Then.GetType() if elseClause != nil

elseClause is allowed to be nil if there is no default case.

func (*SwitchExpr) Case

func (ex *SwitchExpr) Case(i int) struct {
	If   Literal
	Then Expression
}

Case returns the pair of Literal and result Expression for the given index. It is not bounds checked.

func (*SwitchExpr) Else

func (ex *SwitchExpr) Else() Expression

func (*SwitchExpr) Equals

func (ex *SwitchExpr) Equals(other Expression) bool

func (*SwitchExpr) GetType

func (ex *SwitchExpr) GetType() types.Type

func (*SwitchExpr) IsScalar

func (ex *SwitchExpr) IsScalar() bool

func (*SwitchExpr) MatchExpr

func (ex *SwitchExpr) MatchExpr() Expression

func (*SwitchExpr) NCases

func (ex *SwitchExpr) NCases() int

NCases returns the number of case statements in this switch, not including the existences of a default else clause

func (*SwitchExpr) String

func (ex *SwitchExpr) String() string

func (*SwitchExpr) ToProto

func (ex *SwitchExpr) ToProto() *proto.Expression

func (*SwitchExpr) ToProtoFuncArg

func (ex *SwitchExpr) ToProtoFuncArg() *proto.FunctionArgument

func (*SwitchExpr) Visit

func (ex *SwitchExpr) Visit(visit VisitFunc) Expression

type Unbounded

type Unbounded struct{}

func (Unbounded) ToProto

type VisitFunc

type VisitFunc func(Expression) Expression

type WindowFunction

type WindowFunction struct {
	Sorts []SortField

	Partitions []Expression

	LowerBound, UpperBound Bound
	// contains filtered or unexported fields
}

func (*WindowFunction) Arg

func (w *WindowFunction) Arg(i int) types.FuncArg

func (*WindowFunction) CompoundName added in v0.4.2

func (w *WindowFunction) CompoundName() string

func (*WindowFunction) Decomposable

func (w *WindowFunction) Decomposable() extensions.DecomposeType

func (*WindowFunction) Deterministic

func (w *WindowFunction) Deterministic() bool

func (*WindowFunction) Equals

func (w *WindowFunction) Equals(other Expression) bool

func (*WindowFunction) GetType

func (w *WindowFunction) GetType() types.Type

func (*WindowFunction) ID

func (w *WindowFunction) ID() extensions.ID

func (*WindowFunction) IntermediateType

func (w *WindowFunction) IntermediateType() (types.Type, error)

func (*WindowFunction) Invocation

func (w *WindowFunction) Invocation() types.AggregationInvocation

func (*WindowFunction) IsScalar

func (*WindowFunction) IsScalar() bool

func (*WindowFunction) MaxSet

func (w *WindowFunction) MaxSet() int

func (*WindowFunction) NArgs

func (w *WindowFunction) NArgs() int

func (*WindowFunction) Name

func (w *WindowFunction) Name() string

func (*WindowFunction) Ordered

func (w *WindowFunction) Ordered() bool

func (*WindowFunction) Phase

func (*WindowFunction) SessionDependant

func (w *WindowFunction) SessionDependant() bool

func (*WindowFunction) String

func (w *WindowFunction) String() string

func (*WindowFunction) ToProto

func (w *WindowFunction) ToProto() *proto.Expression

func (*WindowFunction) ToProtoFuncArg

func (w *WindowFunction) ToProtoFuncArg() *proto.FunctionArgument

func (*WindowFunction) Variadic

func (*WindowFunction) Visit

func (w *WindowFunction) Visit(visit VisitFunc) Expression

func (*WindowFunction) WindowType

func (w *WindowFunction) WindowType() extensions.WindowType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL