csv

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: 20 Imported by: 0

Documentation

Overview

Package csv provides TableReadCloser and TableWriteCloser implementations for working with csvs.

Index

Constants

This section is empty.

Variables

View Source
var ReadBufSize = 256 * 1024

ReadBufSize is the size of the buffer used when reading the csv file. It is set at the package level and all readers create their own buffer's using the value of this variable at the time they create their buffers.

Functions

This section is empty.

Types

type CSVFileInfo

type CSVFileInfo struct {
	// Delim says which character is used as a field delimiter
	Delim string
	// HasHeaderLine says if the csv has a header line which contains the names of the columns
	HasHeaderLine bool
	// Columns can be provided if you know the columns and their order in the csv
	Columns []string
	// EscapeQuotes says whether quotes should be escaped when parsing the csv
	EscapeQuotes bool
}

CSVFileInfo describes a csv file

func NewCSVInfo

func NewCSVInfo() *CSVFileInfo

NewCSVInfo creates a new CSVInfo struct with default values

func (*CSVFileInfo) SetColumns

func (info *CSVFileInfo) SetColumns(columns []string) *CSVFileInfo

SetColumns sets the Columns member and returns the CSVFileInfo

func (*CSVFileInfo) SetDelim

func (info *CSVFileInfo) SetDelim(delim string) *CSVFileInfo

SetDelim sets the Delim member and returns the CSVFileInfo

func (*CSVFileInfo) SetEscapeQuotes

func (info *CSVFileInfo) SetEscapeQuotes(escapeQuotes bool) *CSVFileInfo

SetEscapeQuotes sets the EscapeQuotes member and returns the CSVFileInfo

func (*CSVFileInfo) SetHasHeaderLine

func (info *CSVFileInfo) SetHasHeaderLine(hasHeaderLine bool) *CSVFileInfo

SetHasHeaderLine sets the HeaderLine member and returns the CSVFileInfo

type CSVReader

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

CSVReader implements TableReader. It reads csv files and returns rows.

func NewCSVReader

func NewCSVReader(nbf *types.NomsBinFormat, r io.ReadCloser, info *CSVFileInfo) (*CSVReader, error)

NewCSVReader creates a CSVReader from a given ReadCloser. The CSVFileInfo should describe the csv file being read.

func OpenCSVReader

func OpenCSVReader(nbf *types.NomsBinFormat, path string, fs filesys.ReadableFS, info *CSVFileInfo) (*CSVReader, error)

OpenCSVReader opens a reader at a given path within a given filesys. The CSVFileInfo should describe the csv file being opened.

func (*CSVReader) Close

func (csvr *CSVReader) Close(ctx context.Context) error

Close should release resources being held

func (*CSVReader) GetSchema

func (csvr *CSVReader) GetSchema() schema.Schema

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

func (*CSVReader) ReadRow

func (csvr *CSVReader) 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 (*CSVReader) VerifySchema

func (csvr *CSVReader) VerifySchema(outSch schema.Schema) (bool, error)

VerifySchema checks that the in schema matches the original schema

type CSVWriter

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

CSVWriter implements TableWriter. It writes rows as comma separated string values

func NewCSVWriter

func NewCSVWriter(wr io.WriteCloser, outSch schema.Schema, info *CSVFileInfo) (*CSVWriter, error)

NewCSVWriter writes rows to the given WriteCloser based on the Schema and CSVFileInfo provided

func OpenCSVWriter

func OpenCSVWriter(path string, fs filesys.WritableFS, outSch schema.Schema, info *CSVFileInfo) (*CSVWriter, error)

OpenCSVWriter creates a file at the given path in the given filesystem and writes out rows based on the Schema, and CSVFileInfo provided

func (*CSVWriter) Close

func (csvw *CSVWriter) Close(ctx context.Context) error

Close should flush all writes, release resources being held

func (*CSVWriter) GetSchema

func (csvw *CSVWriter) GetSchema() schema.Schema

GetSchema gets the schema of the rows that this writer writes

func (*CSVWriter) WriteRow

func (csvw *CSVWriter) WriteRow(ctx context.Context, r row.Row) error

WriteRow will write a row to a table

Jump to

Keyboard shortcuts

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