sample

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package sample reads small, bounded samples of rows. Every query is a plain SELECT with a LIMIT, ordered by the primary key where there is one, so the server reads only a few index pages per query.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInteger

func IsInteger(c *model.Column) bool

IsInteger reports whether a column holds whole numbers.

func QuoteIdent

func QuoteIdent(s string) string

QuoteIdent quotes a table or column name for MySQL.

func Sampleable

func Sampleable(c *model.Column) bool

Sampleable reports whether the scanner reads a column's values. Binary, spatial and vector columns are skipped.

func ValueExpr

func ValueExpr(c *model.Column, n int) string

ValueExpr is the select expression for a column: text is cut to n characters on the server so huge values never cross the network.

Types

type Querier

type Querier interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

Querier is the part of *sql.DB the package needs.

type Sample

type Sample struct {
	Columns []*model.Column
	Rows    [][]sql.NullString
	Method  string
}

Sample is the set of rows read from one table.

func (*Sample) Index

func (s *Sample) Index(column string) int

Index returns the position of a column in the sample, or -1.

func (*Sample) Values

func (s *Sample) Values(i int) []string

Values returns the non-NULL values of one sampled column.

type Sampler

type Sampler struct {
	DB          Querier
	MaxValueLen int           // longer text values are cut on the server
	Timeout     time.Duration // client-side limit per query
}

Sampler reads samples from one database.

func (*Sampler) KeyValues

func (sm *Sampler) KeyValues(ctx context.Context, t *model.Table, keyCol, valueCol *model.Column, key string, limit int) ([]string, error)

KeyValues reads up to limit values of valueCol from rows where keyCol equals key. It is used to look at a known meta key directly when the window sample happened to miss it.

func (*Sampler) Table

func (sm *Sampler) Table(ctx context.Context, t *model.Table, limit int) (*Sample, error)

Table samples up to limit rows. With a single integer primary key the rows come from three windows: the oldest, the middle and the newest rows, since old and new data often differ in shape. Otherwise the first rows the server returns are used.

Jump to

Keyboard shortcuts

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