godata

package module
v0.0.0-...-7fe8aff Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2015 License: Apache-2.0 Imports: 5 Imported by: 0

README

WARNING: This package is *very* unstable. Treat as a proof of concept only; the
APIs are likely to completely change.

Documentation is available at:
  https://godoc.org/github.com/google/godata

Documentation

Overview

Package godata implements a Frame object for analyzing structured data in memory. The package is currently unstable and not ready for adoption.

Example (Joined)
f1 := NewFrame(row.NewColumnIndexer("index"))
f2 := NewFrame(row.NewColumnIndexer("index"))

// f1 and f2 share an index, so the values will be joined together.
f1.Put(row.Of("index", 0, "value", "foo"))
f2.Put(row.Of("index", 0, "value", "bar"))

// f1 and f2 have values at different indices, so index 1 will only contain a
// value from f1, and index 2 will only contain a value from f2.
f1.Put(row.Of("index", 1, "value", "something"))
f2.Put(row.Of("index", 2, "value", "else"))

joined, err := f1.Joined(f2)
if err != nil {
	log.Fatalf("Joined: %v", err)
}
common, err := joined.Get(row.Of("index", 0))
if err != nil {
	log.Fatalf("Get: %v", err)
}
fmt.Println("index:", common["index"], "value:", common["value"])

leftOnly, err := joined.Get(row.Of("index", 1))
if err != nil {
	log.Fatalf("Get: %v", err)
}
fmt.Println("index:", leftOnly["index"], "value:", leftOnly["value"])

rightOnly, err := joined.Get(row.Of("index", 2))
if err != nil {
	log.Fatalf("Get: %v", err)
}
fmt.Println("index:", rightOnly["index"], "value:", rightOnly["value"])
Output:

index: JoinResult{Left: 0, Right: 0} value: JoinResult{Left: foo, Right: bar}
index: JoinResult{Left: 1} value: JoinResult{Left: something}
index: JoinResult{Right: 2} value: JoinResult{Right: else}
Example (PutAndGet)
frame := NewFrame(row.NewColumnIndexer("index1", "index2"))
frame.Put(row.Of("index1", 123, "index2", "foo", "data1", "hello", "data2", "world"))
frame.Put(row.Of("index1", 456, "index2", "bar", "data3", "something"))

row, err := frame.Get(row.Of("index1", 123, "index2", "foo"))
if err != nil {
	log.Fatalf("Get: %v", err)
}
fmt.Print(row["data1"])
Output:

hello

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GreaterOrEqual

func GreaterOrEqual(val row.Data) rangeArg

GreaterOrEqual returns a range option that filters on rows greater than or equal to the given value.

func LessThan

func LessThan(val row.Data) rangeArg

LessThan returns a range option that filters on rows less than or equal to the given value.

Types

type Frame

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

Frame represents multiple rows and multiple columns of data.

func NewFrame

func NewFrame(indexer row.Indexer) *Frame

NewFrame returns a Frame for the given indexer.

func (*Frame) Get

func (f *Frame) Get(key row.Data) (row.Data, error)

Get returns the data for the given key. Returns error if the given key is invalid. Returns nil if there is no data for the given key.

func (*Frame) GetRange

func (f *Frame) GetRange(args ...rangeArg) ([]row.Data, error)

GetRange returns a list of all values in the given range. See GreaterOrEqual and LessThan. If no range is given, then this function returns all rows. If only a begin range is given, then this function returns all rows beginning with the given value. If only an end range is given, then this function returns all rows up to the given value.

func (*Frame) GroupBy

func (f *Frame) GroupBy(indexer row.Indexer) (*Frame, error)

GroupBy returns a new Frame object containing rows grouped by the given indexer. Each index corresponds to a row containing a single column group.Column, which is a slice of rows with that index.

func (*Frame) Joined

func (f *Frame) Joined(frame *Frame) (*Frame, error)

Joined returns a new Frame object that contains the joined contents of the two frames. The indices of the frames must be compatible. The resulting Frame contains one row for each key in the union of keys for the left and right frames. The Data contains a JoinResult for each column of data, where Left is populated with the left side contents, and Right is populated with the right side contents. Left and Right are nil if they don't exist in the left and right sides.

func (*Frame) Pop

func (f *Frame) Pop(key row.Data) (row.Data, error)

Pop returns the data for the given key and deletes it from the Frame. Returns error if the given key is invalid. Returns nil if there is no data for the given key.

func (*Frame) PopRange

func (f *Frame) PopRange(args ...rangeArg) ([]row.Data, error)

PopRange returns a list of all values in the given range and deletes them from the Frame. See GetRange for details on the arguments.

func (*Frame) Put

func (f *Frame) Put(data row.Data) (row.Data, error)

Put inserts the data into the frame, replacing and returning the existing data if an entry already exists. Returns error if the data cannot be indexed.

func (*Frame) String

func (f *Frame) String() string

String returns the string representation of the Frame.

TODO: The output is ugly and potentially very long. Refactor the forRange to take a limit, and then print out a partial representation of the Frame if there are too many rows.

func (*Frame) WithIndexer

func (f *Frame) WithIndexer(indexer row.Indexer) (*Frame, error)

WithIndexer returns a new Frame object with the same underlying data indexed by a new indexer. Returns error if the data cannot be indexed by the new indexer. Note that mutating rows in the returned Frame will also mutate the rows in the existing Frame. However, adding to or deleting rows from the returned Frame will not add to and delete from the existing Frame. WithIndexer assumes that the given Indexer gives each existing row a unique Index. If rows share an index, then one of the rows will be dropped. The dropped row is not defined by the API, and is subject to change.

type JoinResult

type JoinResult struct {
	// Left contains the contents in the left side of the join, or nil if the
	// left frame did not contain a row for the key. Left must contain the same
	// index as Right.
	Left interface{}

	// Right contains the contents in the right side of the join, or nil if the
	// right frame did not contain a row for the key. Left must contain the same
	// index as Right.
	Right interface{}
}

JoinResult represents the result of a join operation.

func (JoinResult) String

func (j JoinResult) String() string

String returns the string representation of this JoinResult.

type JoinResultIndexer

type JoinResultIndexer struct {
	// RowIndexer is the indexer to use for the RowData in either Left or Right.
	RowIndexer row.Indexer
}

JoinResultIndexer indexes a JoinResult by delegating to the given RowIndexer.

func (JoinResultIndexer) Index

func (j JoinResultIndexer) Index(data row.Data) (row.Index, error)

Index returns the index of the contents of a JoinResult. At least one of Left and Right must be non-nil. If both Left and Right are non-nil, then they must have the same index value.

type RowAction

type RowAction func(row.Data) (interface{}, error)

RowAction performs an operation on the given row and optionally returns a value. RowAction must not mutate the Data.

Directories

Path Synopsis
Package group defines utilities for aggregating and slicing Frames.
Package group defines utilities for aggregating and slicing Frames.
Package row defines row primitives that are used to construct a Frame.
Package row defines row primitives that are used to construct a Frame.

Jump to

Keyboard shortcuts

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