table

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2017 License: Apache-2.0 Imports: 11 Imported by: 11

Documentation

Overview

Package table export the table that contains the results of a BQL query.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CellString added in v0.3.0

func CellString(s string) *string

CellString create a pointer for the provided string.

Types

type Accumulator

type Accumulator interface {
	// Accumulate takes the given value and accumulates it to the current state.
	Accumulate(interface{}) (interface{}, error)

	// Resets the current state back to the original one.
	Reset()
}

Accumulator type represents a generic accumulator for independent values expressed as the element of the array slice. Returns the values after being accumulated. If the wrong type is passed in, it will crash casting the interface.

func NewCountAccumulator

func NewCountAccumulator() Accumulator

NewCountAccumulator accumulates the int64 types of a literal.

func NewCountDistinctAccumulator

func NewCountDistinctAccumulator() Accumulator

NewCountDistinctAccumulator counts calls by incrementing the internal state only if the value has not been seen before.

func NewSumFloat64LiteralAccumulator

func NewSumFloat64LiteralAccumulator(s float64) Accumulator

NewSumFloat64LiteralAccumulator accumulates the int64 types of a literal.

func NewSumInt64LiteralAccumulator

func NewSumInt64LiteralAccumulator(s int64) Accumulator

NewSumInt64LiteralAccumulator accumulates the int64 types of a literal.

type AliasAccPair

type AliasAccPair struct {
	InAlias  string
	OutAlias string
	Acc      Accumulator
}

AliasAccPair contains the in, out alias, and the optional accumulator to use.

type Cell

type Cell struct {
	S *string              `json:"s,omitempty"`
	N *node.Node           `json:"node,omitempty"`
	P *predicate.Predicate `json:"pred,omitempty"`
	L *literal.Literal     `json:"lit,omitempty"`
	T *time.Time           `json:"time,omitempty"`
}

Cell contains one of the possible values that form rows.

func (*Cell) String

func (c *Cell) String() string

String returns a readable representation of a cell.

type Row

type Row map[string]*Cell

Row represents a collection of cells.

func MergeRows

func MergeRows(ms []Row) Row

MergeRows takes a list of rows and returns a new map containing both.

func (Row) ToTextLine

func (r Row) ToTextLine(res *bytes.Buffer, bs []string, sep string) error

ToTextLine converts a row into line of text. To do so, it requires the list of bindings of the table, and the separator you want to use. If the separator is empty tabs will be used.

type SortConfig

type SortConfig []struct {
	Binding string
	Desc    bool
}

SortConfig contains the sorting information. Contains the binding order to use while sorting as well as the direction for each of them to use.

func (SortConfig) String added in v0.7.0

func (s SortConfig) String() string

type Table

type Table struct {
	// AvailableBindings in order contained on the table
	AvailableBindings []string `json:"bindings,omitempty"`
	// Data that form the table.
	Data []Row `json:"rows,omitempty"`
	// contains filtered or unexported fields
}

Table contains the results of a BQL query. This table implementation is not safe for concurrency. You should take appropriate precautions if you want to access it concurrently and wrap to properly control concurrent operations.

func New

func New(bs []string) (*Table, error)

New returns a new table that can hold data for the the given bindings. The, table creation will fail if there are repeated bindings.

func (*Table) AddBindings

func (t *Table) AddBindings(bs []string)

AddBindings add the new bindings provided to the table.

func (*Table) AddRow

func (t *Table) AddRow(r Row)

AddRow adds a row to the end of a table. For performance reasons, it does not check that all bindings are set, nor that they are declared on table creation. BQL builds valid tables, if you plan to create tables on your own you should be careful to provide valid rows.

func (*Table) AppendTable

func (t *Table) AppendTable(t2 *Table) error

AppendTable appends the content of the provided table. It will fail it the target table is not empty and the bindings do not match.

func (*Table) Bindings

func (t *Table) Bindings() []string

Bindings returns the bindings contained on the tables.

func (*Table) DeleteRow

func (t *Table) DeleteRow(i int) error

DeleteRow removes the row at position i from the table. This should be used carefully. If you are planning to delete a large volume of rows consider creating a new table and just copy the rows you need. This operation relies on slices and it *will* *not* release the underlying deleted row. Please, see https://blog.golang.org/go-slices-usage-and-internals for a detailed explanation.

func (*Table) DotProduct

func (t *Table) DotProduct(t2 *Table) error

DotProduct does the dot product with the provided table

func (*Table) Filter

func (t *Table) Filter(f func(Row) bool)

Filter removes all the rows where the provided function returns true.

func (*Table) HasBinding

func (t *Table) HasBinding(b string) bool

HasBinding returns true if the binding currently exist on the table.

func (*Table) Limit

func (t *Table) Limit(i int64)

Limit keeps the initial ith rows.

func (*Table) NumRows

func (t *Table) NumRows() int

NumRows returns the number of rows currently available on the table.

func (*Table) ProjectBindings

func (t *Table) ProjectBindings(bs []string) error

ProjectBindings replaces the current bindings with the projected one. The provided bindings needs to be a subset of the original bindings. If the provided bindings are not a subset of the original ones, the projection will fail, leave the table unmodified, and return an error. The projection only modify the bindings, but does not drop non projected data.

func (*Table) Reduce

func (t *Table) Reduce(cfg SortConfig, aaps []AliasAccPair) error

Reduce alters the table by sorting and then range grouping the table data. In order to group reduce the table, we sort the table and then apply the accumulator functions to each group. Finally, the table metadata gets updated to reflect the reduce operation.

func (*Table) Row

func (t *Table) Row(i int) (Row, bool)

Row returns the requested row. Rows start at 0. Also, if you request a row beyond it will return nil, and the ok boolean will be false.

func (*Table) Rows

func (t *Table) Rows() []Row

Rows returns all the available rows.

func (*Table) Sort

func (t *Table) Sort(cfg SortConfig)

Sort sorts the table given a sort configuration.

func (*Table) String

func (t *Table) String() string

String attempts to force serialize the table into a string.

func (*Table) ToJSON added in v0.8.0

func (t *Table) ToJSON(w io.Writer)

ToJSON convert the table intotext versions. It requires the separator to be used between cells JSON.

func (*Table) ToText

func (t *Table) ToText(sep string) (*bytes.Buffer, error)

ToText convert the table into a readable text versions. It requires the separator to be used between cells.

func (*Table) Truncate

func (t *Table) Truncate()

Truncate flushes all the data away. It still retains all set bindings.

Jump to

Keyboard shortcuts

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