Version: v0.1.1 Latest Latest

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

Go to latest
Published: Aug 30, 2017 License: MIT


Build Status Coverage Status Go Report Card Gitter chat GoDoc


A Go library for working with Table Schema.

Main Features

  • table package defines Table and Iterator interfaces, which are used to manipulate and/or explore tabular data;
  • csv package contains implementation of Table and Iterator interfaces to deal with CSV format;
  • schema package contains classes and funcions for working with table schemas:

Getting started


This package uses semantic versioning 2.0.0.

Using dep
$ dep init
$ dep ensure -add
Using govendor
$ govendor init
$ govendor fetch


Code examples in this readme requires Go 1.8+. You can find more examples in the examples directory.

import (
// struct representing each row of the table.
type person struct {
    Name string
    Age uint16
func main() {
    t, _ := csv.New(csv.FileSource("data.csv"), csv.LoadHeaders())  // load table
    t.Infer()  // infer the table schema
    t.Schema.SaveToFile("schema.json")  // save inferred schema to file
    data := []person
    t.CastAll(&data)  // casts the table data into the data slice.



A table is a core concept in a tabular data world. It represents a data with a metadata (Table Schema). Let's see how we could use it in practice.

Consider we have some local CSV file, data.csv:


To read its contents we use csv.New to create a table and use the File Source.

    table, _ := csv.New(csv.FromFile("data.csv"), csv.LoadHeaders())
    table.Headers // ["city", "location"]
    table.All() // [[london 51.50,-0.11], [paris 48.85,2.30], [rome N/A]]

As we could see our locations are just a strings. But it should be geopoints. Also Rome's location is not available but it's also just a N/A string instead of go's zero value. First we have to infer Table Schema:

	// "fields": [
	//     {"name": "city", "type": "string", "format": "default"},
	//     {"name": "location", "type": "geopoint", "format": "default"},
	// ],
	// "missingValues": []
    // ...

Then we could create a struct and automatically cast the table data to schema types. It is like json.Unmarshal, but for table rows. First thing we need is to create the struct which will represent each row.

type Location struct {
    City string
    Location schema.GeoPoint

Then we are ready to cast the table.

var locations []Location
// Fails with cast error: "Invalid geopoint:\"N/A\""

The problem is that the library does not know that N/A is not an empty value. For those cases, there is a missingValues property in Table Schema specification. As a first try we set missingValues to N/A in table.Schema.

table.Schema.MissingValues = []string{"N/A"}
var locations []Location
// [{london {51.5 -0.11}} {paris {48.85 2.3}} {rome {0 0}}]

And because there are no errors on data reading we could be sure that our data is valid againt our schema. Let's save it:



Path Synopsis

Jump to

Keyboard shortcuts

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