table

package
v0.0.0-...-892de5e Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package table provides a framework for interacting with row based table data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBadRowRow

func GetBadRowRow(err error) row.Row

GetBadRow will retrieve the Row from the BadRow error

func IsBadRow

func IsBadRow(err error) bool

IsBadRow takes an error and returns whether it is a BadRow

func PipeRows

func PipeRows(ctx context.Context, rd TableReader, wr TableWriter, contOnBadRow bool) (int, int, error)

PipeRows will read a row from given TableReader and write it to the provided TableWriter. It will do this for every row until the TableReader's ReadRow method returns io.EOF or encounters an error in either reading or writing. The caller will need to handle closing the tables as necessary. If contOnBadRow is true, errors reading or writing will be ignored and the pipe operation will continue.

Returns a tuple: (number of rows written, number of errors ignored, error). In the case that err is non-nil, the row counter fields in the tuple will be set to -1.

func ReadAllRows

func ReadAllRows(ctx context.Context, rd TableReader, contOnBadRow bool) ([]row.Row, int, error)

ReadAllRows reads all rows from a TableReader and returns a slice containing those rows. Usually this is used for testing, or with very small data sets.

Types

type AsyncReadAheadTableReader

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

AsyncReadAheadTableReader is a TableReadCloser implementation that spins up a go routine to keep reading data into a buffered channel so that it is ready when the caller wants it.

func NewAsyncReadAheadTableReader

func NewAsyncReadAheadTableReader(tr TableReadCloser, bufferSize int) *AsyncReadAheadTableReader

NewAsyncReadAheadTableReader creates a new AsyncReadAheadTableReader

func (*AsyncReadAheadTableReader) Close

Close releases resources being held

func (*AsyncReadAheadTableReader) GetSchema

func (tr *AsyncReadAheadTableReader) GetSchema() schema.Schema

GetSchema gets the schema of the rows that this reader will return

func (*AsyncReadAheadTableReader) ReadRow

func (tr *AsyncReadAheadTableReader) ReadRow(ctx context.Context) (row.Row, error)

ReadRow reads a row from a table. If there is a bad row the returned error will be non nil, and calling IsBadRow(err) will be return true. This is a potentially non-fatal error and callers can decide if they want to continue on a bad row, or fail.

func (*AsyncReadAheadTableReader) Start

Start the worker routine reading rows to the channel

func (*AsyncReadAheadTableReader) VerifySchema

func (tr *AsyncReadAheadTableReader) VerifySchema(outSch schema.Schema) (bool, error)

VerifySchema checks that the incoming schema matches the schema from the existing table

type BadRow

type BadRow struct {
	Row     row.Row
	Details []string
}

BadRow is an error which contains the row and details about what is wrong with it.

func NewBadRow

func NewBadRow(r row.Row, details ...string) *BadRow

NewBadRow creates a BadRow instance with a given row and error details

func (*BadRow) Error

func (br *BadRow) Error() string

Error returns a string with error details.

type CompositeTableReader

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

CompositeTableReader is a TableReader implementation which will concatenate the results of multiple TableReader instances into a single set of results.

func NewCompositeTableReader

func NewCompositeTableReader(readers []TableReadCloser) (*CompositeTableReader, error)

NewCompositeTableReader creates a new CompositeTableReader instance from a slice of TableReadClosers.

func (*CompositeTableReader) Close

func (rd *CompositeTableReader) Close(ctx context.Context) error

Close should release resources being held

func (*CompositeTableReader) GetSchema

func (rd *CompositeTableReader) GetSchema() schema.Schema

GetSchema gets the schema of the rows that this reader will return

func (*CompositeTableReader) ReadRow

func (rd *CompositeTableReader) ReadRow(ctx context.Context) (row.Row, error)

ReadRow reads a row from a table. If there is a bad row the returned error will be non nil, and calling IsBadRow(err) will be return true. This is a potentially non-fatal error and callers can decide if they want to continue on a bad row, or fail.

func (*CompositeTableReader) VerifySchema

func (rd *CompositeTableReader) VerifySchema(outSch schema.Schema) (bool, error)

VerifySchema checks that the incoming schema matches the schema from the existing table

type InMemTable

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

InMemTable holds a simple list of rows that can be retrieved, or appended to. It is meant primarily for testing.

func NewInMemTable

func NewInMemTable(sch schema.Schema) *InMemTable

NewInMemTable creates an empty Table with the expectation that any rows added will have the given Schema

func NewInMemTableWithData

func NewInMemTableWithData(sch schema.Schema, rows []row.Row) *InMemTable

NewInMemTableWithData creates a Table with the riven rows

func NewInMemTableWithDataAndValidationType

func NewInMemTableWithDataAndValidationType(sch schema.Schema, rows []row.Row) *InMemTable

func (*InMemTable) AppendRow

func (imt *InMemTable) AppendRow(r row.Row) error

AppendRow appends a row. Appended rows must be valid for the table's schema. Sorts rows as they are inserted.

func (*InMemTable) GetRow

func (imt *InMemTable) GetRow(index int) (row.Row, error)

GetRow gets a row by index

func (*InMemTable) GetSchema

func (imt *InMemTable) GetSchema() schema.Schema

GetSchema gets the table's schema

func (*InMemTable) NumRows

func (imt *InMemTable) NumRows() int

NumRows returns the number of rows in the table

type InMemTableReader

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

InMemTableReader is an implementation of a TableReader for an InMemTable

func NewInMemTableReader

func NewInMemTableReader(imt *InMemTable) *InMemTableReader

NewInMemTableReader creates an instance of a TableReader from an InMemTable

func (*InMemTableReader) Close

func (rd *InMemTableReader) Close(ctx context.Context) error

Close should release resources being held

func (*InMemTableReader) GetSchema

func (rd *InMemTableReader) GetSchema() schema.Schema

GetSchema gets the schema of the rows that this reader will return

func (*InMemTableReader) ReadRow

func (rd *InMemTableReader) ReadRow(ctx context.Context) (row.Row, error)

ReadRow reads a row from a table. If there is a bad row the returned error will be non nil, and callin IsBadRow(err) will be return true. This is a potentially non-fatal error and callers can decide if they want to continue on a bad row, or fail.

func (*InMemTableReader) VerifySchema

func (rd *InMemTableReader) VerifySchema(outSch schema.Schema) (bool, error)

VerifySchema checks that the incoming schema matches the schema from the existing table

type InMemTableWriter

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

InMemTableWriter is an implementation of a TableWriter for an InMemTable

func NewInMemTableWriter

func NewInMemTableWriter(imt *InMemTable) *InMemTableWriter

NewInMemTableWriter creates an instance of a TableWriter from an InMemTable

func (*InMemTableWriter) Close

func (w *InMemTableWriter) Close(ctx context.Context) error

Close should flush all writes, release resources being held

func (*InMemTableWriter) GetSchema

func (w *InMemTableWriter) GetSchema() schema.Schema

GetSchema gets the schema of the rows that this writer writes

func (*InMemTableWriter) WriteRow

func (w *InMemTableWriter) WriteRow(ctx context.Context, r row.Row) error

WriteRow will write a row to a table

type TableCloser

type TableCloser interface {
	// Close should release resources being held
	Close(ctx context.Context) error
}

TableCloser is an interface for a table stream that can be closed to release resources

type TableReadCloser

type TableReadCloser interface {
	TableReader
	TableCloser
}

TableReadCloser is an interface for reading rows from a table, that can be closed.

type TableReader

type TableReader interface {
	// GetSchema gets the schema of the rows that this reader will return
	GetSchema() schema.Schema

	// ReadRow reads a row from a table.  If there is a bad row the returned error will be non nil, and calling
	// IsBadRow(err) will be return true. This is a potentially non-fatal error and callers can decide if they want to
	// continue on a bad row, or fail.
	ReadRow(ctx context.Context) (row.Row, error)

	// VerifySchema checks that the incoming schema matches the schema from the existing table
	VerifySchema(outSch schema.Schema) (bool, error)
}

TableReader is an interface for reading rows from a table

type TableWriteCloser

type TableWriteCloser interface {
	TableWriter
	TableCloser
}

TableWriteCloser is an interface for writing rows to a table, that can be closed

type TableWriter

type TableWriter interface {
	// GetSchema gets the schema of the rows that this writer writes
	GetSchema() schema.Schema

	// WriteRow will write a row to a table
	WriteRow(ctx context.Context, r row.Row) error
}

TableWriteCloser is an interface for writing rows to a table

Directories

Path Synopsis
Package typed provides helper functions and utility classes for working with typed table data.
Package typed provides helper functions and utility classes for working with typed table data.
noms
Package nbf provides TableReadCloser and TableWriteCloser implementations for working with dolt tables in noms.
Package nbf provides TableReadCloser and TableWriteCloser implementations for working with dolt tables in noms.
Package untyped provides helper functions for working with untyped table data.
Package untyped provides helper functions for working with untyped table data.
csv
Package csv provides TableReadCloser and TableWriteCloser implementations for working with csvs.
Package csv provides TableReadCloser and TableWriteCloser implementations for working with csvs.
fwt
tabular
Package tabular provides writer implementations for working with tabular output for display
Package tabular provides writer implementations for working with tabular output for display

Jump to

Keyboard shortcuts

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