framework

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Catalog = map[string][]FunctionInterface{}

Catalog contains all of the PostgreSQL functions.

Functions

func AddExplicitTypeCast added in v0.6.0

func AddExplicitTypeCast(cast TypeCast) error

AddExplicitTypeCast registers the given explicit type cast.

func AddImplicitTypeCast added in v0.6.0

func AddImplicitTypeCast(cast TypeCast) error

AddImplicitTypeCast registers the given implicit type cast.

func GetPotentialExplicitCasts added in v0.6.0

func GetPotentialExplicitCasts(fromType pgtypes.DoltgresTypeBaseID) []pgtypes.DoltgresType

GetPotentialExplicitCasts returns all registered explicit type casts from the given type.

func GetPotentialImplicitCasts added in v0.6.0

func GetPotentialImplicitCasts(fromType pgtypes.DoltgresTypeBaseID) []pgtypes.DoltgresType

GetPotentialImplicitCasts returns all registered implicit type casts from the given type.

func Initialize

func Initialize()

Initialize handles the initialization of the catalog by overwriting the built-in GMS functions, since they do not apply to PostgreSQL (and functions of the same name often have different behavior).

func MustAddExplicitTypeCast added in v0.6.0

func MustAddExplicitTypeCast(cast TypeCast)

MustAddExplicitTypeCast registers the given explicit type cast. Panics if an error occurs.

func MustAddImplicitTypeCast added in v0.6.0

func MustAddImplicitTypeCast(cast TypeCast)

MustAddImplicitTypeCast registers the given implicit type cast. Panics if an error occurs.

func RegisterBinaryFunction

func RegisterBinaryFunction(operator Operator, f Function2)

RegisterBinaryFunction registers the given function, so that it will be usable from a running server. This should only be used for binary functions, which are the underlying functions for binary operators such as addition, subtraction, etc. This should be called from within an init().

func RegisterFunction

func RegisterFunction(f FunctionInterface)

RegisterFunction registers the given function, so that it will be usable from a running server. This should be called from within an init().

func RegisterUnaryFunction

func RegisterUnaryFunction(operator Operator, f Function1)

RegisterUnaryFunction registers the given function, so that it will be usable from a running server. This should only be used for unary functions, which are the underlying functions for unary operators such as negation, etc. This should be called from within an init().

Types

type CompiledFunction

type CompiledFunction struct {
	Name       string
	Parameters []sql.Expression
	Functions  *OverloadDeduction
}

CompiledFunction is an expression that represents a fully-analyzed PostgreSQL function.

func (*CompiledFunction) Children

func (c *CompiledFunction) Children() []sql.Expression

Children implements the interface sql.Expression.

func (*CompiledFunction) Description

func (c *CompiledFunction) Description() string

Description implements the interface sql.Expression.

func (*CompiledFunction) Eval

func (c *CompiledFunction) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)

Eval implements the interface sql.Expression.

func (*CompiledFunction) FunctionName

func (c *CompiledFunction) FunctionName() string

FunctionName implements the interface sql.Expression.

func (*CompiledFunction) IsNullable

func (c *CompiledFunction) IsNullable() bool

IsNullable implements the interface sql.Expression.

func (*CompiledFunction) OverloadString

func (c *CompiledFunction) OverloadString(types []pgtypes.DoltgresType) string

OverloadString returns the name of the function represented by the given overload.

func (*CompiledFunction) Resolved

func (c *CompiledFunction) Resolved() bool

Resolved implements the interface sql.Expression.

func (*CompiledFunction) String

func (c *CompiledFunction) String() string

String implements the interface sql.Expression.

func (*CompiledFunction) Type

func (c *CompiledFunction) Type() sql.Type

Type implements the interface sql.Expression.

func (*CompiledFunction) WithChildren

func (c *CompiledFunction) WithChildren(children ...sql.Expression) (sql.Expression, error)

WithChildren implements the interface sql.Expression.

type Context

type Context struct {
	*sql.Context
}

Context is a context that PostgreSQL functions will use.

type Function

type Function struct {
	Name      string
	Overloads []any
}

Function is a name, along with a collection of functions, that represent a single PostgreSQL function with all of its overloads.

type Function0

type Function0 struct {
	Name       string
	Return     pgtypes.DoltgresType
	Parameters []pgtypes.DoltgresType
	Callable   func(ctx Context) (any, error)
}

Function0 is a function that does not take any parameters.

func (Function0) GetExpectedParameterCount

func (f Function0) GetExpectedParameterCount() int

GetExpectedParameterCount implements the FunctionInterface interface.

func (Function0) GetName

func (f Function0) GetName() string

GetName implements the FunctionInterface interface.

func (Function0) GetParameters

func (f Function0) GetParameters() []pgtypes.DoltgresType

GetParameters implements the FunctionInterface interface.

func (Function0) GetReturn

func (f Function0) GetReturn() pgtypes.DoltgresType

GetReturn implements the FunctionInterface interface.

type Function1

type Function1 struct {
	Name       string
	Return     pgtypes.DoltgresType
	Parameters []pgtypes.DoltgresType
	Callable   func(ctx Context, val1 any) (any, error)
}

Function1 is a function that takes one parameter.

func (Function1) GetExpectedParameterCount

func (f Function1) GetExpectedParameterCount() int

GetExpectedParameterCount implements the FunctionInterface interface.

func (Function1) GetName

func (f Function1) GetName() string

GetName implements the FunctionInterface interface.

func (Function1) GetParameters

func (f Function1) GetParameters() []pgtypes.DoltgresType

GetParameters implements the FunctionInterface interface.

func (Function1) GetReturn

func (f Function1) GetReturn() pgtypes.DoltgresType

GetReturn implements the FunctionInterface interface.

type Function2

type Function2 struct {
	Name       string
	Return     pgtypes.DoltgresType
	Parameters []pgtypes.DoltgresType
	Callable   func(ctx Context, val1 any, val2 any) (any, error)
}

Function2 is a function that takes two parameters.

func (Function2) GetExpectedParameterCount

func (f Function2) GetExpectedParameterCount() int

GetExpectedParameterCount implements the FunctionInterface interface.

func (Function2) GetName

func (f Function2) GetName() string

GetName implements the FunctionInterface interface.

func (Function2) GetParameters

func (f Function2) GetParameters() []pgtypes.DoltgresType

GetParameters implements the FunctionInterface interface.

func (Function2) GetReturn

func (f Function2) GetReturn() pgtypes.DoltgresType

GetReturn implements the FunctionInterface interface.

type Function3

type Function3 struct {
	Name       string
	Return     pgtypes.DoltgresType
	Parameters []pgtypes.DoltgresType
	Callable   func(ctx Context, val1 any, val2 any, val3 any) (any, error)
}

Function3 is a function that takes three parameters.

func (Function3) GetExpectedParameterCount

func (f Function3) GetExpectedParameterCount() int

GetExpectedParameterCount implements the FunctionInterface interface.

func (Function3) GetName

func (f Function3) GetName() string

GetName implements the FunctionInterface interface.

func (Function3) GetParameters

func (f Function3) GetParameters() []pgtypes.DoltgresType

GetParameters implements the FunctionInterface interface.

func (Function3) GetReturn

func (f Function3) GetReturn() pgtypes.DoltgresType

GetReturn implements the FunctionInterface interface.

type Function4

type Function4 struct {
	Name       string
	Return     pgtypes.DoltgresType
	Parameters []pgtypes.DoltgresType
	Callable   func(ctx Context, val1 any, val2 any, val3 any, val4 any) (any, error)
}

Function4 is a function that takes four parameters.

func (Function4) GetExpectedParameterCount

func (f Function4) GetExpectedParameterCount() int

GetExpectedParameterCount implements the FunctionInterface interface.

func (Function4) GetName

func (f Function4) GetName() string

GetName implements the FunctionInterface interface.

func (Function4) GetParameters

func (f Function4) GetParameters() []pgtypes.DoltgresType

GetParameters implements the FunctionInterface interface.

func (Function4) GetReturn

func (f Function4) GetReturn() pgtypes.DoltgresType

GetReturn implements the FunctionInterface interface.

type FunctionInterface

type FunctionInterface interface {
	// GetName returns the name of the function. The name is case-insensitive, so the casing does not matter.
	GetName() string
	// GetReturn returns the return type.
	GetReturn() pgtypes.DoltgresType
	// GetParameters returns the parameter types for the function.
	GetParameters() []pgtypes.DoltgresType
	// GetExpectedParameterCount returns the number of paramters that are valid for this function.
	GetExpectedParameterCount() int
	// contains filtered or unexported methods
}

FunctionInterface is an interface for PostgreSQL functions.

type IntermediateFunction

type IntermediateFunction struct {
	Functions *OverloadDeduction
}

IntermediateFunction is an expression that represents an incomplete PostgreSQL function.

func GetBinaryFunction

func GetBinaryFunction(operator Operator) IntermediateFunction

GetBinaryFunction returns the binary function that matches the given operator.

func GetUnaryFunction

func GetUnaryFunction(operator Operator) IntermediateFunction

GetUnaryFunction returns the unary function that matches the given operator.

func (IntermediateFunction) Compile

func (f IntermediateFunction) Compile(name string, parameters ...sql.Expression) *CompiledFunction

Compile returns a CompiledFunction created from the calling IntermediateFunction. Returns a nil function if it could not be compiled.

type LiteralInterface

type LiteralInterface interface {
	sql.Expression
	GetDoltgresType() pgtypes.DoltgresType
	ConformsToLiteralInterface()
}

LiteralInterface is used to prevent import cycles, since we can't reference pgexprs.Literal from this package.

type Operator

type Operator byte

Operator is a unary or binary operator.

const (
	Operator_BinaryPlus Operator = iota
	Operator_BinaryMinus
	Operator_BinaryMultiply
	Operator_BinaryDivide
	Operator_BinaryMod
	Operator_BinaryShiftLeft
	Operator_BinaryShiftRight
	Operator_BinaryBitAnd
	Operator_BinaryBitOr
	Operator_BinaryBitXor
	Operator_UnaryPlus
	Operator_UnaryMinus
)

func (Operator) IsBinary

func (o Operator) IsBinary() bool

IsBinary returns whether the operator is a binary operator.

func (Operator) IsUnary

func (o Operator) IsUnary() bool

IsUnary returns whether the operator is a unary operator.

func (Operator) String

func (o Operator) String() string

String returns the string form of the operator.

type OverloadDeduction

type OverloadDeduction struct {
	Function  FunctionInterface
	Parameter map[pgtypes.DoltgresTypeBaseID]*OverloadDeduction
}

OverloadDeduction handles resolving which function to call by iterating over the parameter expressions. This also handles casting between types if an exact function match is not found.

func (*OverloadDeduction) Resolve

func (overload *OverloadDeduction) Resolve(parameters []pgtypes.DoltgresType, sources []Source) (*OverloadDeduction, []TypeCastFunction, error)

Resolve returns an overload that either matches the given parameters exactly, or is a viable match after casting. Returns a nil OverloadDeduction if a viable match is not found.

type Source

type Source uint8

Source defines what kind of expression generated the given value, as some functions are context-dependent, and we need to approximate the context.

const (
	Source_Expression Source = iota // The source is some expression. This may change as more sources are added.
	Source_Constant                 // The source is a constant value
	Source_Column                   // The source is a column
)

type TypeCast

type TypeCast struct {
	FromType pgtypes.DoltgresType
	ToType   pgtypes.DoltgresType
	Function TypeCastFunction
}

TypeCast is used to cast from one type to another.

type TypeCastFunction

type TypeCastFunction func(ctx Context, val any, targetType pgtypes.DoltgresType) (any, error)

TypeCastFunction is a function that takes a value of a particular kind of type, and returns it as another kind of type. The targetType given should match the "To" type used to obtain the cast.

func GetExplicitCast added in v0.6.0

func GetExplicitCast(fromType pgtypes.DoltgresTypeBaseID, toType pgtypes.DoltgresTypeBaseID) TypeCastFunction

GetExplicitCast returns the explicit type cast function that will cast the "from" type to the "to" type. Returns nil if such a cast is not valid.

func GetImplicitCast added in v0.6.0

func GetImplicitCast(fromType pgtypes.DoltgresTypeBaseID, toType pgtypes.DoltgresTypeBaseID) TypeCastFunction

GetImplicitCast returns the implicit type cast function that will cast the "from" type to the "to" type. Returns nil if such a cast is not valid.

Jump to

Keyboard shortcuts

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