sdata

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(w TupleWriter, r TupleReader, row Tuple) (n int, _ error)

Copy copies a tuple from r to w. Row is used to indicate the correct shape of read data.

Types

type CSVParser

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

A CSVParser reads rows from a CSV-formatted io.Reader into tuples.

func NewCSVParser

func NewCSVParser(r io.Reader) *CSVParser

NewCSVParser returns a new CSV parser which reads from r.

func (*CSVParser) Next

func (p *CSVParser) Next(row Tuple) error

Next reads one data row from the underlying io.Reader into the Tuple. If a header is expected, it will read the header row, then the first data row.

func (*CSVParser) WithHeaderFields

func (p *CSVParser) WithHeaderFields(fields []string) *CSVParser

WithHeaderFields updates the CSV parser to expect a header with the indicated fields. It must called prior to any call to Next. As a special case, if no fields are passed then the parser will expect no header.

type CSVWriter

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

CSVWriter writes Tuples in CSV format.

func NewCSVWriter

func NewCSVWriter(w io.Writer, headers []string) *CSVWriter

NewCSVWriter returns a CSVWriter writing to w. If len(headers) == 0, then no headers will be written

func (*CSVWriter) Flush

func (m *CSVWriter) Flush() error

func (*CSVWriter) WriteTuple

func (m *CSVWriter) WriteTuple(row Tuple) error

type ErrCannotConvert

type ErrCannotConvert struct {
	Value interface{}
	Dest  interface{}
}

ErrCannotConvert is returned when a value cannot be converted to a value of a different type.

func (ErrCannotConvert) Error

func (e ErrCannotConvert) Error() string

type ErrTupleFields

type ErrTupleFields struct {
	Writer TupleWriter
	Tuple  Tuple
	Fields []string
}

ErrTupleFields is returned by writers to indicate that a tuple is not the right shape to be written to them.

func (ErrTupleFields) Error

func (e ErrTupleFields) Error() string

type JSONParser

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

func (*JSONParser) Next

func (p *JSONParser) Next(row Tuple) error

type JSONWriter

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

JSONWriter writes tuples as newline separated json objects.

func NewJSONWriter

func NewJSONWriter(w io.Writer, fieldNames []string) *JSONWriter

TODO: figure out some way to specify a projection so that we can write nested structures.

func (*JSONWriter) Flush

func (m *JSONWriter) Flush() error

func (*JSONWriter) WriteTuple

func (m *JSONWriter) WriteTuple(row Tuple) error

type MaterializationResult

type MaterializationResult struct {
	ColumnNames []string
	RowCount    uint64
}

MaterializationResult is returned by MaterializeSQL

func MaterializeSQL

func MaterializeSQL(tw TupleWriter, rows *sql.Rows) (*MaterializationResult, error)

MaterializeSQL reads all the rows from a *sql.Rows, and writes them to tw. It flushes tw and returns a MaterializationResult

type SQLTupleWriter

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

SQLTupleWriter writes tuples to a SQL database.

func NewSQLTupleWriter

func NewSQLTupleWriter(tx *pachsql.Tx, tableInfo *pachsql.TableInfo) *SQLTupleWriter

func (*SQLTupleWriter) Flush

func (m *SQLTupleWriter) Flush() error

func (*SQLTupleWriter) GeneratePreparedStatement

func (m *SQLTupleWriter) GeneratePreparedStatement() (*pachsql.Stmt, error)

GeneratePreparedStatement generates a prepared statement based the amount of data in the buffer. This can be used to execute a batched INSERT.

func (*SQLTupleWriter) WriteTuple

func (m *SQLTupleWriter) WriteTuple(t Tuple) error

type Tuple

type Tuple = []interface{}

Tuple is an alias for []interface{}. It is used for passing around rows of data. The elements of a tuple will always be pointers so the Tuple can be passed to sql.Rows.Scan

func CloneTuple

func CloneTuple(t Tuple) Tuple

CloneTuple uses Go reflection to make a copy of a Tuple.

func NewTupleFromColumnTypes

func NewTupleFromColumnTypes(cTypes []*sql.ColumnType) (Tuple, error)

func NewTupleFromTableInfo

func NewTupleFromTableInfo(info *pachsql.TableInfo) (Tuple, error)

type TupleReader

type TupleReader interface {
	// Next attempts to read one Tuple into x.
	// If the next data is the wrong shape for x then an error is returned.
	Next(x Tuple) error
}

TupleReader is a stream of Tuples

func NewJSONParser

func NewJSONParser(r io.Reader, fieldNames []string) TupleReader

type TupleWriter

type TupleWriter interface {
	WriteTuple(row Tuple) error
	Flush() error
}

TupleWriter is the type of Writers for structured data.

Directories

Path Synopsis
Package csv reads and writes comma-separated values (CSV) files.
Package csv reads and writes comma-separated values (CSV) files.

Jump to

Keyboard shortcuts

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