static

package
v0.170.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package static provides utilities for easily constructing static tables that are meant for tests.

The primary type is Table which will be a mapping of columns to their data. The data is defined in a columnar format instead of a row-based one.

The implementations in this package are not performant and are not meant to be used in production code. They are good enough for small datasets that are present in tests to ensure code correctness.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column interface {
	// Label returns the label associated with this column.
	Label() string

	// Type returns the column type for this column.
	Type() flux.ColType

	// Make will construct an array with the given length
	// if it is possible.
	Make(n int, mem memory.Allocator) array.Array

	// Len will return the length of this column.
	// If no length is known, this will return -1.
	Len() int

	// IsKey will return true if this is part of the group key.
	IsKey() bool

	// KeyValue will return the key value if this column is part
	// of the group key.
	KeyValue() values.Value

	// TableBuilder allows this column to add itself to a template.
	TableBuilder
}

Column is the definition for how to construct a column for the table.

func Booleans

func Booleans(k string, v ...interface{}) Column

Booleans will construct an array of booleans. Each value can be a bool or nil.

func Floats

func Floats(k string, v ...interface{}) Column

Floats will construct an array of floats. Each value can be a float64, int, int64, or nil.

func Ints

func Ints(k string, v ...interface{}) Column

Ints will construct an array of integers. Each value can be an int, int64, or nil.

func Strings

func Strings(k string, v ...interface{}) Column

Strings will construct an array of strings. Each value can be a string or nil.

func Times

func Times(k string, v ...interface{}) Column

Times will construct an array of times with the given time using either a string or an integer. If an integer is used, then it is in seconds.

If strings and integers are mixed, the integers will be treates as offsets from the last string time that was used.

func Uints

func Uints(k string, v ...interface{}) Column

Uints will construct an array of unsigned integers. Each value can be a uint, uint64, int, int64, or nil.

type KeyColumn

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

func BooleanKey

func BooleanKey(k string, v interface{}) KeyColumn

BooleanKey will construct a group key with the boolean type. The value can be a bool or nil.

func FloatKey

func FloatKey(k string, v interface{}) KeyColumn

FloatKey will construct a group key with the float type. The value can be a float64, int, int64, or nil.

func IntKey

func IntKey(k string, v interface{}) KeyColumn

IntKey will construct a group key with the integer type. The value can be an int, int64, or nil.

func StringKey

func StringKey(k string, v interface{}) KeyColumn

StringKey will construct a group key with the string type. The value can be a string or nil.

func TimeKey

func TimeKey(k string, v interface{}) KeyColumn

TimeKey will construct a group key with the given time using either a string or an integer. If an integer is used, then it is in seconds.

func UintKey

func UintKey(k string, v interface{}) KeyColumn

UintKey will construct a group key with the unsigned type. The value can be a uint, uint64, int, int64, or nil.

func (KeyColumn) Build

func (s KeyColumn) Build(template *[]Column, mem memory.Allocator) []flux.Table

func (KeyColumn) IsKey

func (s KeyColumn) IsKey() bool

func (KeyColumn) KeyValue

func (s KeyColumn) KeyValue() values.Value

func (KeyColumn) Label

func (s KeyColumn) Label() string

func (KeyColumn) Len

func (s KeyColumn) Len() int

func (KeyColumn) Make

func (s KeyColumn) Make(n int, mem memory.Allocator) array.Array

func (KeyColumn) Type

func (s KeyColumn) Type() flux.ColType

type Table

type Table []Column

Table is a statically constructed table. It is a mapping between column names and the column.

This is not a performant section of code and it is primarily meant to make writing unit tests easily. Do not use in production code.

The Table struct implements the TableIterator interface and not the Table interface. To retrieve a flux.Table compatible implementation, the Table() method can be used.

func (Table) Build

func (s Table) Build(template *[]Column, mem memory.Allocator) []flux.Table

func (Table) Do

func (s Table) Do(f func(flux.Table) error) error

Do will produce the Table and then invoke the function on that flux.Table.

If the produced Table is invalid, then this method will panic.

func (Table) Table

func (s Table) Table(mem memory.Allocator) flux.Table

Table will produce a flux.Table using the Column values that are part of this Table.

If the Table produces an invalid buffer, then this method will panic.

type TableBuilder

type TableBuilder interface {
	// Build will construct a set of tables using the
	// template as input.
	//
	// The template is a pointer as a builder is allowed
	// to modify the template. For implementors, the
	// template pointer must be non-nil.
	Build(template *[]Column, mem memory.Allocator) []flux.Table
}

TableBuilder is used to construct a set of Tables.

type TableGroup

type TableGroup []TableBuilder

TableGroup will construct a group of Tables that have common values. It includes any TableBuilder values.

func (TableGroup) Build

func (t TableGroup) Build(template *[]Column, mem memory.Allocator) []flux.Table

Build will construct Tables using the given template.

func (TableGroup) Do

func (t TableGroup) Do(f func(flux.Table) error) error

type TableList

type TableList []TableBuilder

TableList will produce a Table using the template and each of the table builders.

Changes to the template are not shared between each of the entries. If the TableBuilder does not produce tables, this will force a single Table to be created.

func StringKeys

func StringKeys(k string, v ...interface{}) TableList

StringKeys creates a TableList with the given key values.

func (TableList) Build

func (t TableList) Build(template *[]Column, mem memory.Allocator) []flux.Table

type TableMatrix

type TableMatrix []TableList

TableMatrix will produce a set of Tables by producing the cross product of each of the TableBuilders with each other.

func (TableMatrix) Build

func (t TableMatrix) Build(template *[]Column, mem memory.Allocator) []flux.Table

Jump to

Keyboard shortcuts

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