table

package
v0.0.0-...-65fd79d Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToString

func ToString(tbl Table) (string, error)

ToString converts the given table to a string. To do this, it calls Table.Rows exactly once and drains the obtained RowIterator. The resulting string representation is a formatted table, where the column headers contain the type name of the column, and aliases are used over plain column names, if present.

col1 (Integer)   col2 (String)
1                foobar
2                snafu

Types

type Col

type Col struct {
	QualifiedName string
	Alias         string
	Type          types.Type
}

Col is a header for a single column in a table, containing the qualified name of the col, a possible alias and the col data type.

func FindColumnForNameOrAlias

func FindColumnForNameOrAlias(tbl Table, nameOrAlias string) (foundColumn Col, found bool)

FindColumnForNameOrAlias checks the given table for a column that has the given nameOrAlias as name or as an alias. Every column is first checked for its name, then for its alias. A nameOrAlias "*" will NOT yield a column.

func (Col) String

func (c Col) String() string

type Error

type Error string

Error is a sentinel error.

const (
	// ErrEOT indicates, that a table iterator is fully drained and will not yield
	// any more results.
	ErrEOT Error = "end of table"
)

func (Error) Error

func (e Error) Error() string

type Row

type Row struct {
	Values []types.Value
}

Row is a collection of values with no column information. To have column information available for the values, see table.RowWithColInfo.

type RowIterator

type RowIterator interface {
	Next() (Row, error)
	Reset() error
	io.Closer
}

RowIterator is an iterator that can be reset, which results in Next obtaining the rows in the beginning again. It must be closed after use.

type RowWithColInfo

type RowWithColInfo struct {
	Cols []Col
	Row
}

RowWithColInfo is a row with col information available.

func NewRowWithImplicitColData

func NewRowWithImplicitColData(values []types.Value) RowWithColInfo

NewRowWithImplicitColData creates a new RowWithColInfo and implies the column information from the given values. That is, type information is extracted from the values, and column qualified names are of the form column<colIndex>, where colIndex is one-based. This results in generated column names such as column1, column5, column26 etc.

func (RowWithColInfo) ValueForColName

func (r RowWithColInfo) ValueForColName(colName string) (types.Value, bool)

ValueForColName checks if this row has a value for the given col name. It has such a value, if any cols QualifiedName or Alias matches the given argument. If no such value is present, false is returned.

type Table

type Table interface {
	// Cols returns all column information of this table.
	Cols() ([]Col, error)
	// Rows returns a resettable row iterator, which can be used to iterate over all
	// rows in this table. Multiple calls to this method result in different row iterator
	// objects.
	Rows() (RowIterator, error)
}

Table describes a collection of rows, where each row consists of multiple columns. A column has a type, and that information is carried separately in the table. A table has a row iterator, which can be used to obtain all rows of the table in sequence. Multiple calls to RowIterator must result in different iterators.

var (
	// Empty is an empty table with no cols and no rows.
	Empty Table = inMemoryTable{
		// contains filtered or unexported fields
	}
)

func NewFilteredCol

func NewFilteredCol(underlying Table, keep func(int, Col) bool) Table

NewFilteredCol returns a new table that will filter columns from the given underlying table.

tbl := getSevenColTable()
len(tbl.Cols()) == 7
newTbl = table.NewFilteredCol(tbl, func(i int, c Col) bool { return i > 0 })
len(newTbl.Cols()) == 6 // first column is not present anymore

func NewFilteredRow

func NewFilteredRow(underlying Table, keep func(RowWithColInfo) (bool, error)) Table

NewFilteredRow returns a new table that can filter rows from the given underlying table.

func NewInMemory

func NewInMemory(cols []Col, rows []Row) Table

NewInMemory returns a new in-memory table, consisting of the given cols and rows.

Jump to

Keyboard shortcuts

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