ntup

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2018 License: BSD-3-Clause, BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package ntup provides a way to create, open and iterate over n-tuple data.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotExist is returned when an n-tuple could not be located in a sql.DB
	ErrNotExist = errors.New("hbook/ntup: ntuple does not exist")

	// ErrMissingColDef is returned when some information is missing wrt
	// an n-tuple column definition
	ErrMissingColDef = errors.New("hbook/ntup: expected at least one column definition")
)

Functions

This section is empty.

Types

type Descriptor

type Descriptor interface {
	Name() string       // the column name
	Type() reflect.Type // the column type
}

Descriptor describes a column

type Ntuple

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

Ntuple provides read/write access to row-wise n-tuple data.

func Create

func Create(db *sql.DB, name string, cols ...interface{}) (*Ntuple, error)

Create creates a new ntuple with the given name inside the given database handle. The n-tuple schema is inferred from the cols argument. cols can be:

  • a single struct value (columns are inferred from the names+types of the exported fields)
  • a list of builtin values (the columns names are varX where X=[1-len(cols)])
  • a list of ntup.Descriptors

e.g.:

nt, err := ntup.Create(db, "nt", struct{X float64 `hbook:"x"`}{})
nt, err := ntup.Create(db, "nt", int64(0), float64(0))

func Open

func Open(db *sql.DB, name string) (*Ntuple, error)

Open inspects the given database handle and tries to return an Ntuple connected to a table with the given name. Open returns ErrNotExist if no such table exists. If name is "", Open will connect to the one-and-only table in the db.

e.g.:

db, err := sql.Open("csv", "file.csv")
nt, err := ntup.Open(db, "ntup")

func (*Ntuple) Cols

func (nt *Ntuple) Cols() []Descriptor

Cols returns the columns' descriptors of this n-tuple. Modifying it directly leads to undefined behaviour.

func (*Ntuple) DB

func (nt *Ntuple) DB() *sql.DB

DB returns the underlying db this n-tuple is connected to.

func (*Ntuple) Name

func (nt *Ntuple) Name() string

Name returns the name of this n-tuple.

func (*Ntuple) Scan

func (nt *Ntuple) Scan(query string, f interface{}) error

Scan executes a query against the ntuple and runs the function f against that context.

e.g.

err = nt.Scan("x,y where z>10", func(x,y float64) error {
  h1.Fill(x, 1)
  h2.Fill(y, 1)
  return nil
})

func (*Ntuple) ScanH1D

func (nt *Ntuple) ScanH1D(query string, h *hbook.H1D) (*hbook.H1D, error)

ScanH1D executes a query against the ntuple and fills the histogram with the results of the query. If h is nil, a (100-bins, xmin, xmax+ULP) histogram is created, where xmin and xmax are inferred from the content of the underlying database.

func (*Ntuple) ScanH2D

func (nt *Ntuple) ScanH2D(query string, h *hbook.H2D) (*hbook.H2D, error)

ScanH2D executes a query against the ntuple and fills the histogram with the results of the query. If h is nil, a (100-bins, xmin, xmax+ULP) (100-bins, ymin, ymax+ULP) 2d-histogram is created, where xmin, xmax and ymin,ymax are inferred from the content of the underlying database.

Directories

Path Synopsis
Package ntcsv provides a convenient access to CSV files as n-tuple data.
Package ntcsv provides a convenient access to CSV files as n-tuple data.

Jump to

Keyboard shortcuts

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