csvparser

package
v0.0.0-debug-20260702 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BufferSizeScale       = int64(5)
	ReadBlockSize   int64 = 64 * 1024
)

Functions

func IndexAnyByte

func IndexAnyByte(s []byte, as *byteSet) int

IndexAnyByte returns the byte index of the first occurrence in s of any in the byte points in chars. It returns -1 if there is no code point in common.

Types

type CSVConfig

type CSVConfig struct {
	// they can only be used by LOAD DATA
	// https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-field-line-handling
	LinesStartingBy   string
	LinesTerminatedBy string

	FieldsTerminatedBy string
	FieldsEnclosedBy   string
	FieldsEscapedBy    string

	Null              []string
	Header            bool
	HeaderSchemaMatch bool
	TrimLastSep       bool
	NotNull           bool

	AllowEmptyLine bool
	// For non-empty FieldsEnclosedBy (for example quotes), null elements inside quotes are not considered as null except for
	// `\N` (when escape-by is `\`). That is to say, `\N` is special for null because it always means null.
	QuotedNullIsText bool
	// ref https://dev.mysql.com/doc/refman/8.0/en/load-data.html
	// > If the field begins with the ENCLOSED BY character, instances of that character are recognized as terminating a
	// > field value only if followed by the field or line TERMINATED BY sequence.
	// This means we will meet unescaped quote in a quoted field
	// > The "BIG" boss      -> The "BIG" boss
	// This means we will meet unescaped quote in an unquoted field
	UnescapedQuote bool

	// Comment is the comment marker: a line whose RAW prefix (before unquoting)
	// equals it is skipped. The empty string (the default) means no comment
	// marker, so every line is data — an enclosed value like "#x" is always
	// data regardless, since its raw prefix is the enclosure char.
	Comment string
}

type CSVParser

type CSVParser struct {
	LastRow []Field
	// contains filtered or unexported fields
}

CSVParser is basically a copy of encoding/csv, but special-cased for MySQL-like input.

func NewCSVParser

func NewCSVParser(
	cfg *CSVConfig,
	reader io.Reader,
	blockBufSize int64,
	shouldParseHeader bool,
) (*CSVParser, error)

NewCSVParser creates a CSV parser.

func (*CSVParser) Columns

func (parser *CSVParser) Columns() []string

func (*CSVParser) Pos

func (parser *CSVParser) Pos() int64

func (*CSVParser) Read

func (parser *CSVParser) Read(lastRow []Field) (row []Field, err error)

func (*CSVParser) SetColumns

func (parser *CSVParser) SetColumns(columns []string)

type Field

type Field struct {
	Val            string
	IsNull         bool
	HasStringQuote bool
}

Jump to

Keyboard shortcuts

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