table

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 16 Imported by: 1 module, 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

Overview

Package table reads delimited tables (CSV, TSV) for the desktop app's table viewer and workspace search (spec_files_029, spec_search_035): their delimiter and encoding (Latin-1 is decoded), a profile of their columns, and pages of rows matched by a search across columns, filters on columns and a sort, streamed so a file of hundreds of megabytes isn't loaded whole.

Index

Constants

View Source
const (
	KindNumber = "number"
	KindDate   = "date"
	KindText   = "text"
	KindEmpty  = "empty"
)

The kinds of column a profile tells apart.

Variables

View Source
var ErrBadFilter = errors.New("bad filter")

ErrBadFilter wraps a filter that can't be read.

View Source
var SortLimit = 200_000

SortLimit is the most matching rows a page sorts: past it, the rows come in file order (filter first).

Functions

func Decode

func Decode(head []byte, f Format) string

Decode is head as text: Latin-1 decoded when f says so.

func Describe

func Describe(cols []Column, rows int) string

Describe writes a profile as text, a line per column, for a model to read (search.enrich).

func IsTable

func IsTable(p string) bool

IsTable reports whether a file is read as a table, by its name.

func Reader

func Reader(r io.Reader, f Format) *csv.Reader

Reader reads r's records as f says, decoding Latin-1; quotes are lenient and rows may have any number of fields.

Types

type Column

type Column struct {
	Name     string
	Kind     string
	Empty    int
	Min, Max float64
	Samples  []string
}

Column is a column's name and what its values look like in the rows profiled: its kind, how many were empty, the range of a number column, and a few distinct values.

func Profile

func Profile(r *csv.Reader, rows int) ([]Column, int, error)

Profile reads the header and up to rows records of r and describes each column, and how many records it read.

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter is a test on one column's cell: a comparison with a number (">5", ">=5", "<5", "<=5", "=5", "!=5", a range "10..20"), equality with text ("=north", "!=north"), "empty" or "!empty", else that the cell contains the text, ignoring case.

func ParseFilter

func ParseFilter(expr string) (Filter, error)

ParseFilter reads a column filter.

func (Filter) Match

func (f Filter) Match(cell string) bool

Match reports whether a cell passes the filter.

type Format

type Format struct {
	Delimiter rune
	Latin1    bool
}

Format is how a table's bytes are read: its delimiter, and whether it's Latin-1 (Windows-1252) rather than UTF-8.

func Sniff

func Sniff(name string, head []byte) (Format, error)

Sniff decides a table's format from its name and first bytes: TSV by name, else the delimiter its header line has most of (comma, semicolon, tab, bar); Latin-1 when the bytes aren't UTF-8. A NUL means it's no text.

type Page

type Page struct {
	Columns []string
	Rows    []Row
	Matched int
	Total   int
	Sorted  bool
}

Page is a page of a table: its columns, the rows asked for, how many rows matched and how many there are in all. Sorted is false when there were too many matches to sort (more than SortLimit).

func Read

func Read(ctx context.Context, r *csv.Reader, q Query) (Page, error)

Read reads r to the end for q's page; ctx stops it between rows.

type Query

type Query struct {
	Search  string
	Filters map[int]string
	Sort    int
	Desc    bool
	Offset  int
	Limit   int
}

Query asks for a page of a table's rows: those with Search in a cell (ignoring case) and passing every Filter (by column), sorted by a column (-1: in file order), from Offset, up to Limit.

type Row

type Row struct {
	Number int
	Cells  []string
}

Row is a row of a table: its number (1-based, the header not counted) and its cells.

Jump to

Keyboard shortcuts

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