Documentation ¶
Overview ¶
Package csv2lp transforms CSV data to InfluxDB line protocol
Index ¶
- Constants
- func CreateDecoder(encoding string) (func(io.Reader) io.Reader, error)
- func IsTypeSupported(dataType string) bool
- func MultiCloser(closers ...io.Closer) io.Closer
- func SkipHeaderLinesReader(skipLines int, reader io.Reader) io.Reader
- type CsvColumnError
- type CsvLineError
- type CsvTable
- func (t *CsvTable) AddRow(row []string) bool
- func (t *CsvTable) AppendLine(buffer []byte, row []string, lineNumber int) ([]byte, error)
- func (t *CsvTable) Column(label string) *CsvTableColumn
- func (t *CsvTable) ColumnLabels() []string
- func (t *CsvTable) Columns() []*CsvTableColumn
- func (t *CsvTable) CreateLine(row []string) (line string, err error)
- func (t *CsvTable) DataColumnsInfo() string
- func (t *CsvTable) FieldName() *CsvTableColumn
- func (t *CsvTable) FieldValue() *CsvTableColumn
- func (t *CsvTable) Fields() []*CsvTableColumn
- func (t *CsvTable) IgnoreDataTypeInColumnName(val bool)
- func (t *CsvTable) Measurement() *CsvTableColumn
- func (t *CsvTable) NextTable()
- func (t *CsvTable) Tags() []*CsvTableColumn
- func (t *CsvTable) Time() *CsvTableColumn
- type CsvTableColumn
- type CsvToLineReader
- type LineReader
Constants ¶
const ( RFC3339 = "RFC3339" RFC3339Nano = "RFC3339Nano" )
predefined dateTime formats
Variables ¶
This section is empty.
Functions ¶
func CreateDecoder ¶
CreateDecoder creates a decoding reader from the supplied encoding to UTF-8, or returns an error
func IsTypeSupported ¶
IsTypeSupported returns true if the data type is supported
func MultiCloser ¶
MultiCloser creates am io.Closer that silently closes supplied io.Closer instances
Types ¶
type CsvColumnError ¶
CsvColumnError indicates conversion error in a specific column
type CsvLineError ¶
CsvLineError is returned for csv conversion errors
func CreateRowColumnError ¶
func CreateRowColumnError(line int, columnLabel string, err error) CsvLineError
CreateRowColumnError wraps an existing error to add line and column coordinates
func (CsvLineError) Error ¶
func (e CsvLineError) Error() string
type CsvTable ¶
type CsvTable struct {
// contains filtered or unexported fields
}
CsvTable contains metadata about columns and a state of the CSV processing
func (*CsvTable) AddRow ¶
AddRow updates the state of the CSV table with a new header, annotation or data row. Returns true if the row is a data row.
func (*CsvTable) AppendLine ¶
AppendLine appends a protocol line to the supplied buffer using a CSV row and returns appended buffer or an error if any
func (*CsvTable) Column ¶
func (t *CsvTable) Column(label string) *CsvTableColumn
Column returns the first column of the supplied label or nil
func (*CsvTable) ColumnLabels ¶
ColumnLabels returns available columns labels
func (*CsvTable) Columns ¶
func (t *CsvTable) Columns() []*CsvTableColumn
Columns returns available columns
func (*CsvTable) CreateLine ¶
CreateLine produces a protocol line out of the supplied row or returns error
func (*CsvTable) DataColumnsInfo ¶
DataColumnsInfo returns a string representation of columns that are used to process CSV data
func (*CsvTable) FieldName ¶
func (t *CsvTable) FieldName() *CsvTableColumn
FieldName returns field name column or nil
func (*CsvTable) FieldValue ¶
func (t *CsvTable) FieldValue() *CsvTableColumn
FieldValue returns field value column or nil
func (*CsvTable) IgnoreDataTypeInColumnName ¶
IgnoreDataTypeInColumnName sets a flag that can ignore dataType parsing in column names. When true, column names can then contain '|'. By default, column name can also contain datatype and a default value when named `name|datatype` or `name|datatype|default`, for example `ready|boolean|true`
func (*CsvTable) Measurement ¶
func (t *CsvTable) Measurement() *CsvTableColumn
Measurement returns measurement column or nil
type CsvTableColumn ¶
type CsvTableColumn struct { // Label is a column label from the header row, such as "_start", "_stop", "_time" Label string // DataType such as "string", "long", "dateTime" ... DataType string // DataFormat is a format of DataType, such as "RFC3339", "2006-01-02" DataFormat string // LinePart is a line part of the column (0 means not determined yet), see linePart constants LinePart int // DefaultValue is used when column's value is an empty string. DefaultValue string // Index of this column when reading rows, -1 indicates a virtual column with DefaultValue data Index int // TimeZone of dateTime column, applied when parsing dateTime DataType TimeZone *time.Location // ParseF is an optional function used to convert column's string value to interface{} ParseF func(value string) (interface{}, error) // ComputeValue is an optional function used to compute column value out of row data ComputeValue func(row []string) string // contains filtered or unexported fields }
CsvTableColumn represents processing metadata about a csv column
func (*CsvTableColumn) LineLabel ¶
func (c *CsvTableColumn) LineLabel() string
LineLabel returns escaped name of the column so it can be then used as a tag name or field name in line protocol
func (*CsvTableColumn) Value ¶
func (c *CsvTableColumn) Value(row []string) string
Value returns the value of the column for the supplied row
type CsvToLineReader ¶
type CsvToLineReader struct { // Table collects information about used columns Table CsvTable // LineNumber represents line number of csv.Reader, 1 is the first LineNumber int // RowSkipped is called when a row is skipped because of data parsing error RowSkipped func(source *CsvToLineReader, lineError error, row []string) // contains filtered or unexported fields }
CsvToLineReader represents state of transformation from csv data to lien protocol reader
func CsvToLineProtocol ¶
func CsvToLineProtocol(reader io.Reader) *CsvToLineReader
CsvToLineProtocol transforms csv data into line protocol data
func (*CsvToLineReader) Comma ¶
func (state *CsvToLineReader) Comma() rune
Comma returns a field delimiter used in an input CSV file
func (*CsvToLineReader) LogTableColumns ¶
func (state *CsvToLineReader) LogTableColumns(val bool) *CsvToLineReader
LogTableColumns turns on/off logging of table data columns before reading data rows
func (*CsvToLineReader) Read ¶
func (state *CsvToLineReader) Read(p []byte) (n int, err error)
Read implements io.Reader that returns protocol lines
func (*CsvToLineReader) SkipRowOnError ¶
func (state *CsvToLineReader) SkipRowOnError(val bool) *CsvToLineReader
SkipRowOnError controls whether to fail on every CSV conversion error (false) or to log the error and continue (true)
type LineReader ¶
type LineReader struct { // LineNumber of the next read operation, 0 is the first line by default. // It can be set to 1 start counting from 1. LineNumber int // LastLineNumber is the number of the last read row. LastLineNumber int // contains filtered or unexported fields }
LineReader wraps an io.Reader to count lines that go though read function and returns at most one line during every invocation of read. It provides a workaround to golang's CSV reader that does not expose current line number at all (see https://github.com/golang/go/issues/26679)
At most one line is returned by every read in order to ensure that golang's CSV reader buffers at most one single line into its nested bufio.Reader.
func NewLineReader ¶
func NewLineReader(rd io.Reader) *LineReader
NewLineReader returns a new LineReader.
func NewLineReaderSize ¶
func NewLineReaderSize(rd io.Reader, size int) *LineReader
NewLineReaderSize returns a new Reader whose buffer has at least the specified size.