typex

package
v2.26.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package typex contains full type representation for PCollections and DoFns, and utilities for type checking.

Index

Constants

This section is empty.

Variables

View Source
var (
	TType = reflect.TypeOf((*T)(nil)).Elem()
	UType = reflect.TypeOf((*U)(nil)).Elem()
	VType = reflect.TypeOf((*V)(nil)).Elem()
	WType = reflect.TypeOf((*W)(nil)).Elem()
	XType = reflect.TypeOf((*X)(nil)).Elem()
	YType = reflect.TypeOf((*Y)(nil)).Elem()
	ZType = reflect.TypeOf((*Z)(nil)).Elem()

	EventTimeType = reflect.TypeOf((*EventTime)(nil)).Elem()
	WindowType    = reflect.TypeOf((*Window)(nil)).Elem()

	KVType            = reflect.TypeOf((*KV)(nil)).Elem()
	CoGBKType         = reflect.TypeOf((*CoGBK)(nil)).Elem()
	WindowedValueType = reflect.TypeOf((*WindowedValue)(nil)).Elem()
)

Functions

func Bind

func Bind(types, models []FullType) (map[string]reflect.Type, error)

Bind returns a substitution from universals to types in the given models, such as {"T" -> X, "X" -> int}. Each model must be assignable to the corresponding type. For example, Bind(KV<T,int>, KV<string, int>) would produce {"T" -> string}.

func IsBound

func IsBound(t FullType) bool

IsBound returns true iff the type has no universal type components. Nodes and coders need bound types.

func IsCoGBK

func IsCoGBK(t FullType) bool

IsCoGBK returns true iff the type is a CoGBK.

func IsComposite

func IsComposite(t reflect.Type) bool

IsComposite returns true iff the given type is one of the predefined Composite marker types: KV, CoGBK or WindowedValue.

func IsConcrete

func IsConcrete(t reflect.Type) bool

IsConcrete returns true iff the given type is a valid "concrete" data type. Such data must be fully serializable. Functions and channels are examples of invalid types. Aggregate types with no universals are considered concrete here.

func IsContainer

func IsContainer(t reflect.Type) bool

IsContainer returns true iff the given type is an container data type, such as []int or []T.

func IsEqual

func IsEqual(from, to FullType) bool

IsEqual returns true iff the types are equal.

func IsEqualList

func IsEqualList(from, to []FullType) bool

IsEqualList returns true iff the lists of types are equal.

func IsKV

func IsKV(t FullType) bool

IsKV returns true iff the type is a KV.

func IsList

func IsList(t reflect.Type) bool

IsList returns true iff the given type is a slice.

func IsStructurallyAssignable

func IsStructurallyAssignable(from, to FullType) bool

IsStructurallyAssignable returns true iff a from value is structurally assignable to the to value of the given types. Types that are "structurally assignable" (SA) are assignable if type variables are disregarded. In other words, depending on the bindings of universal type variables, types may or may not be assignable. However, types that are not SA are not assignable under any bindings.

For example:

SA:  KV<int,int>    := KV<int,int>
SA:  KV<int,X>      := KV<int,string>  // X bound to string by assignment
SA:  KV<int,string> := KV<int,X>       // Assignable only if X is already bound to string
SA:  KV<int,string> := KV<X,X>         // Not assignable under any binding

Not SA:  KV<int,string> := KV<string,X>
Not SA:  X              := KV<int,string>
Not SA:  GBK(X,Y)       := KV<int,string>

func IsUniversal

func IsUniversal(t reflect.Type) bool

IsUniversal returns true iff the given type is one of the predefined universal types: T, U, V, W, X, Y or Z.

func IsW

func IsW(t FullType) bool

IsW returns true iff the type is a WindowedValue.

Types

type Class

type Class int

Class is the type "class" of data as distinguished by the runtime. The class determines what kind of coding and/or conversion to be inserted. Special types such EventTime, error and reflect.Type are Invalid in this context.

const (
	// Invalid type, such as Function, which is not valid as data.
	Invalid Class = iota
	// Concrete type, such as int, string, struct { .. }.
	Concrete
	// Universal type: T, U, V, W, X, Y, Z. They act as type variables
	// for type checking purposes, but -- unlike type variables -- are
	// not instantiated at runtime.
	Universal
	// Container type: []. A Go-generic container type that both can be
	// represented as a reflect.Type and may incur runtime conversions.
	// The component cannot be a Composite.
	Container
	// Composite type: KV, CoGBk, WindowedValue. Beam-generic types
	// that cannot be represented as a single reflect.Type.
	Composite
)

func ClassOf

func ClassOf(t reflect.Type) Class

ClassOf returns the class of a given type. The class is Invalid, if the type is not suitable as data.

func (Class) String

func (c Class) String() string

type CoGBK

type CoGBK struct{}

type EventTime

type EventTime = mtime.Time

EventTime is a timestamp that Beam understands as attached to an element.

type FullType

type FullType interface {
	// Class returns the class of the FullType. It is never Illegal.
	Class() Class
	// Type returns the Go type at the root of the tree, such as KV, X
	// or int.
	Type() reflect.Type
	// Components returns the real components of the root type, if Composite.
	Components() []FullType
}

FullType represents the tree structure of data types processed by the graph. It allows representation of composite types, such as KV<int, string> or W<CoGBK<int, int>>, as well as "generic" such types, KV<int,T> or CoGBK<X,Y>, where the free "type variables" are the fixed universal types: T, X, etc.

func New

func New(t reflect.Type, components ...FullType) FullType

New constructs a new full type with the given elements. It panics if not valid.

func NewCoGBK

func NewCoGBK(components ...FullType) FullType

NewCoGBK constructs a new CoGBK of the given component types.

func NewKV

func NewKV(components ...FullType) FullType

NewKV constructs a new KV of the given key and value types.

func NewW

func NewW(t FullType) FullType

NewW constructs a new WindowedValue of the given type.

func SkipK

func SkipK(t FullType) FullType

SkipK skips the key in a KV layer, if present. If no, returns the input.

func SkipW

func SkipW(t FullType) FullType

SkipW skips a WindowedValue layer, if present. If no, returns the input.

func Substitute

func Substitute(list []FullType, m map[string]reflect.Type) ([]FullType, error)

Substitute returns types identical to the given types, but with all universals substituted. All free type variables must be present in the substitution.

type KV

type KV struct{}

type T

type T interface{}

type U

type U interface{}

type V

type V interface{}

type W

type W interface{}

type Window

type Window interface {
	// MaxTimestamp returns the the inclusive upper bound of timestamps for values in this window.
	MaxTimestamp() EventTime

	// Equals returns true iff the windows are identical.
	Equals(o Window) bool
}

Window represents a concrete Window.

type WindowedValue

type WindowedValue struct{}

type X

type X interface{}

type Y

type Y interface{}

type Z

type Z interface{}

Jump to

Keyboard shortcuts

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