inputs

package
Version: v0.0.0-...-fca00ec Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSVInput

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

CSVInput represents a record producing input from a CSV formatted file or pipe.

func NewCSVInput

func NewCSVInput(opts *CSVInputOptions) (*CSVInput, error)

NewCSVInput sets up a new CSVInput, the first row is read when this is run. If there is a problem with reading the first row, the error is returned. Otherwise, the returned csvInput can be reliably consumed with ReadRecord() until ReadRecord() returns nil.

func (*CSVInput) Header

func (csvInput *CSVInput) Header() []string

Header returns the header of the csvInput. Either the first row if a header set in the options, or c#, where # is the column number, starting with 0.

func (*CSVInput) Name

func (csvInput *CSVInput) Name() string

Name returns the name of the CSV being read. By default, either the base filename or 'pipe' if it is a unix pipe

func (*CSVInput) ReadRecord

func (csvInput *CSVInput) ReadRecord() []string

ReadRecord reads a single record from the CSV. Always returns successfully. If the record is empty, an empty []string is returned. Record expand to match the current row size, adding blank fields as needed. Records never return less then the number of fields in the first row. Returns nil on EOF In the event of a parse error due to an invalid record, it is logged, and an empty []string is returned with the number of fields in the first row, as if the record were empty.

In general, this is a very tolerant of problems CSV reader.

func (*CSVInput) SetName

func (csvInput *CSVInput) SetName(name string)

SetName overrides the name of the CSV

type CSVInputOptions

type CSVInputOptions struct {
	// HasHeader when true, will treat the first row as a header row.
	HasHeader bool
	// Separator is the rune that fields are delimited by.
	Separator rune
	// ReadFrom is where the data will be read from.
	ReadFrom io.Reader
}

CSVInputOptions options are passed to the underlying encoding/csv reader.

type Input

type Input interface {
	// ReadRecord should return nil on the end of data, or a single record.
	// Recoverable errors should represent themselves as empty sets.
	// Unrecoverable errors should return nil.
	ReadRecord() []string
	// Header should return metadata naming the columns in the table.
	Header() []string
	// Name should return a reasonable name for the data set, prehaps the file name.
	Name() string
	// SetName allows users of the dataset to supply their own name if needed.
	SetName(string)
}

Input is how TextQL reads from data sources. To be an input, an implementor must return tabular data. How data is manipulated into the tabular structure is left to the implementor. Inputs are expected to return in a row by row fashion.

Source Files

Jump to

Keyboard shortcuts

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