Documentation ¶
Overview ¶
Package csv provides TableReadCloser and TableWriteCloser implementations for working with csvs.
Index ¶
- Variables
- func WriteCSVRow(wr *bufio.Writer, record []*string, delim string, useCRLF bool) error
- type CSVFileInfo
- type CSVReader
- func (csvr *CSVReader) Close(ctx context.Context) error
- func (csvr *CSVReader) GetSchema() schema.Schema
- func (csvr *CSVReader) ReadRow(ctx context.Context) (row.Row, error)
- func (csvr *CSVReader) ReadSqlRow(crx context.Context) (sql.Row, error)
- func (csvr *CSVReader) VerifySchema(outSch schema.Schema) (bool, error)
- type CSVWriter
Constants ¶
This section is empty.
Variables ¶
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 ¶
func WriteCSVRow ¶
WriteCSVRow is directly copied from csv.Writer.Write() with the addition of the `isNull []bool` parameter this method has been adapted for Dolt's special quoting logic, ie `10,,""` -> (10,NULL,"")
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) ReadRow ¶
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) ReadSqlRow ¶
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