package
0.0.0-20210827224422-e5fa29d95e8b
Repository: https://github.com/attic-labs/noms.git
Documentation: pkg.go.dev
# README
CSV Importer
Imports a CSV file as List<T>
where T
is a struct with fields corresponding to the CSV's column headers. The struct spec can also be set manually with the -header
flag.
Usage
$ cd csv-import
$ go build
$ ./csv-import <PATH> http://localhost:8000::foo
Some places for CSV files
- https://data.cityofnewyork.us/api/views/kku6-nxdu/rows.csv?accessType=DOWNLOAD
- http://www.opendatacache.com/
CSV Exporter
Export a dataset in CSV format to stdout with column headers.
Usage
$ cd csv-export
$ go build
$ ./csv-export http://localhost:8000:foo
# Functions
EscapeStructFieldFromCSV removes special characters and replaces spaces with camelCasing (camel case turns to camelCase).
FindPrimaryKeys reads numSamples from r, using the first numFields and returns slices of []int indices that are primary keys for those samples.
GetListElemDesc ensures that l is a types.List of structs, pulls the types.StructDesc that describes the elements of l out of vr, and returns the StructDesc.
GetMapElemDesc ensures that m is a types.Map of structs, pulls the types.StructDesc that describes the elements of m out of vr, and returns the StructDesc.
KindsToStrings looks up each element of kinds in the types.KindToString map and returns a slice of answers.
MakeStructTemplateFromHeaders creates a struct type from the headers using |kinds| as the type of each field.
NewCSVReader returns a new csv.Reader that splits on comma.
ReadToColumnar takes a CSV reader and reads data from each column into a separate list.
ReadToList takes a CSV reader and reads data into a typed List of structs.
ReadToMap takes a CSV reader and reads data into a typed Map of structs.
StringsToKinds looks up each element of strs in the StringToKind map and returns a slice of answers.
StringToRune returns the rune contained in delimiter or an error.
StringToValue takes a piece of data as a string and attempts to convert it to a types.Value of the appropriate types.NomsKind.
WriteList takes a types.List l of structs (described by sd) and writes it to output as comma-delineated values.
WriteMap takes a types.Map m of structs (described by sd) and writes it to output as comma-delineated values.
# Variables
StringToKind maps names of valid NomsKinds (e.g.
# Type aliases
KindSlice is an alias for []types.NomsKind.