chore(pkg/csv2lp): rename CsvToProtocolLines to CsvToLineProtocol
parent
010f23f82f
commit
d12d6deae9
|
@ -5,7 +5,7 @@ csv2lp library converts CSV (comma separated values) to InfluxDB Line Protocol.
|
|||
2. it allows the processing of existing CSV files
|
||||
|
||||
## Usage
|
||||
The entry point is the ``CsvToProtocolLines`` function that accepts a (utf8) reader with CSV data and returns a reader with line protocol data.
|
||||
The entry point is the ``CsvToLineProtocol`` function that accepts a (utf8) reader with CSV data and returns a reader with line protocol data.
|
||||
|
||||
## Examples
|
||||
#### Example 1 - Flux Query Result
|
||||
|
|
|
@ -123,8 +123,8 @@ func (state *CsvToLineReader) Read(p []byte) (n int, err error) {
|
|||
return state.Read(p)
|
||||
}
|
||||
|
||||
// CsvToProtocolLines transforms csv data into line protocol data
|
||||
func CsvToProtocolLines(reader io.Reader) *CsvToLineReader {
|
||||
// CsvToLineProtocol transforms csv data into line protocol data
|
||||
func CsvToLineProtocol(reader io.Reader) *CsvToLineReader {
|
||||
csv := csv.NewReader(reader)
|
||||
csv.ReuseRecord = true
|
||||
return &CsvToLineReader{
|
||||
|
|
|
@ -14,8 +14,8 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// Test_CsvToProtocolLines tests conversion of annotated CSV data to line protocol data
|
||||
func Test_CsvToProtocolLines(t *testing.T) {
|
||||
// Test_CsvToLineProtocol tests conversion of annotated CSV data to line protocol data
|
||||
func Test_CsvToLineProtocol(t *testing.T) {
|
||||
var tests = []struct {
|
||||
name string
|
||||
csv string
|
||||
|
@ -86,7 +86,7 @@ func Test_CsvToProtocolLines(t *testing.T) {
|
|||
for _, test := range tests {
|
||||
for _, bufferSize := range bufferSizes {
|
||||
t.Run(test.name+"_"+strconv.Itoa(bufferSize), func(t *testing.T) {
|
||||
reader := CsvToProtocolLines(strings.NewReader(test.csv))
|
||||
reader := CsvToLineProtocol(strings.NewReader(test.csv))
|
||||
buffer := make([]byte, bufferSize)
|
||||
lines := make([]byte, 0, 100)
|
||||
for {
|
||||
|
@ -117,8 +117,8 @@ func Test_CsvToProtocolLines(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// Test_CsvToProtocolLines_LogTableColumns checks correct logging of table columns
|
||||
func Test_CsvToProtocolLines_LogTableColumns(t *testing.T) {
|
||||
// Test_CsvToLineProtocol_LogTableColumns checks correct logging of table columns
|
||||
func Test_CsvToLineProtocol_LogTableColumns(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
log.SetOutput(&buf)
|
||||
oldFlags := log.Flags()
|
||||
|
@ -134,7 +134,7 @@ func Test_CsvToProtocolLines_LogTableColumns(t *testing.T) {
|
|||
|
||||
csv := "_measurement,a,b\ncpu,1,1\ncpu,b2\n"
|
||||
|
||||
reader := CsvToProtocolLines(strings.NewReader(csv)).LogTableColumns(true)
|
||||
reader := CsvToLineProtocol(strings.NewReader(csv)).LogTableColumns(true)
|
||||
require.False(t, reader.skipRowOnError)
|
||||
require.True(t, reader.logTableDataColumns)
|
||||
// read all the data
|
||||
|
@ -146,8 +146,8 @@ func Test_CsvToProtocolLines_LogTableColumns(t *testing.T) {
|
|||
require.Equal(t, messages, 1)
|
||||
}
|
||||
|
||||
// Test_CsvToProtocolLines_LogTimeZoneWarning checks correct logging of timezone warning
|
||||
func Test_CsvToProtocolLines_LogTimeZoneWarning(t *testing.T) {
|
||||
// Test_CsvToLineProtocol_LogTimeZoneWarning checks correct logging of timezone warning
|
||||
func Test_CsvToLineProtocol_LogTimeZoneWarning(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
log.SetOutput(&buf)
|
||||
oldFlags := log.Flags()
|
||||
|
@ -165,7 +165,7 @@ func Test_CsvToProtocolLines_LogTimeZoneWarning(t *testing.T) {
|
|||
"#constant,dateTime:2006-01-02,1970-01-01\n" +
|
||||
"_measurement,a,b\ncpu,1,1"
|
||||
|
||||
reader := CsvToProtocolLines(strings.NewReader(csv))
|
||||
reader := CsvToLineProtocol(strings.NewReader(csv))
|
||||
bytes, _ := ioutil.ReadAll(reader)
|
||||
|
||||
out := buf.String()
|
||||
|
@ -175,8 +175,8 @@ func Test_CsvToProtocolLines_LogTimeZoneWarning(t *testing.T) {
|
|||
require.Equal(t, string(bytes), "cpu a=1,b=1 0\n")
|
||||
}
|
||||
|
||||
// Test_CsvToProtocolLines_SkipRowOnError tests that error rows are skipped
|
||||
func Test_CsvToProtocolLines_SkipRowOnError(t *testing.T) {
|
||||
// Test_CsvToLineProtocol_SkipRowOnError tests that error rows are skipped
|
||||
func Test_CsvToLineProtocol_SkipRowOnError(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
log.SetOutput(&buf)
|
||||
oldFlags := log.Flags()
|
||||
|
@ -192,7 +192,7 @@ func Test_CsvToProtocolLines_SkipRowOnError(t *testing.T) {
|
|||
|
||||
csv := "_measurement,a,_time\n,1,1\ncpu,2,2\ncpu,3,3a\n"
|
||||
|
||||
reader := CsvToProtocolLines(strings.NewReader(csv)).SkipRowOnError(true)
|
||||
reader := CsvToLineProtocol(strings.NewReader(csv)).SkipRowOnError(true)
|
||||
require.Equal(t, reader.skipRowOnError, true)
|
||||
require.Equal(t, reader.logTableDataColumns, false)
|
||||
// read all the data
|
||||
|
|
|
@ -179,7 +179,7 @@ func Test_Examples(t *testing.T) {
|
|||
for _, example := range examples {
|
||||
example.normalize()
|
||||
t.Run(example.name, func(t *testing.T) {
|
||||
transformer := CsvToProtocolLines(strings.NewReader(example.csv))
|
||||
transformer := CsvToLineProtocol(strings.NewReader(example.csv))
|
||||
transformer.SkipRowOnError(true)
|
||||
result, err := ioutil.ReadAll(transformer)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue