types

package
v0.0.0-...-87c9453 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	ASC sortOrder = iota
	DESC
)
View Source
const (
	// This order is important.
	// filter first,
	// then group,
	// then sort each group,
	// then apply whatever,
	// then select the field
	FILTER_ACTION actionType = iota
	GROUPBY_ACTION
	SORT_ACTION
	APPLY_ACTION
	SELECT_ACTION
)

Variables

View Source
var (
	MAX   aggregateFunc = getMax
	MIN   aggregateFunc = getMin
	SUM   aggregateFunc = getSum
	MEAN  aggregateFunc = getMean
	COUNT aggregateFunc = getCount
	RANGE aggregateFunc = getRange
)

Functions

func AND

func AND(filters ...filterType) filterType

Combines a list of filters to produce a combined AND logical filter

func NOT

func NOT(filter filterType) filterType

Inverts a given filter to produce a NOT logical filter

func OR

func OR(filters ...filterType) filterType

Combines a list of filters to produce a combined OR logical filter

Types

type Column

type Column struct {
	Name string

	Dtype Datatype
	// contains filtered or unexported fields
}

func (*Column) Agg

func (c *Column) Agg(aggFunc aggregateFunc) aggregation

Returns an aggregation function specific to this column to merge its values into a single value. It works when GroupBy is used

func (*Column) Equals

func (c *Column) Equals(operand interface{}) filterType

Returns an array of booleans corresponding in position to each item, true if item is equal to operand or else false The operand can reference a constant, or a Col

func (*Column) GreaterOrEquals

func (c *Column) GreaterOrEquals(operand float64) filterType

Returns an array of booleans corresponding in position to each item, true if item is greater than or equal to the operand or else false The operand can reference a constant, or a Col

func (*Column) GreaterThan

func (c *Column) GreaterThan(operand float64) filterType

Returns an array of booleans corresponding in position to each item, true if item is greater than operand or else false The operand can reference a constant, or a Col

func (*Column) IsLike

func (c *Column) IsLike(pattern *regexp.Regexp) filterType

Returns an array of booleans corresponding in position to each item, true if item is like the regex expression or else false

func (*Column) Items

func (c *Column) Items() []interface{}

Returns a list of Items

func (*Column) LessOrEquals

func (c *Column) LessOrEquals(operand float64) filterType

Returns an array of booleans corresponding in position to each item, true if item is less than or equal to the operand or else false The operand can reference a constant, or a Col

func (*Column) LessThan

func (c *Column) LessThan(operand float64) filterType

Returns an array of booleans corresponding in position to each item, true if item is less than operand or else false The operand can reference a constant, or a Col

func (*Column) Order

func (c *Column) Order(option sortOrder) sortOption

Returns a Sort Option that is attached to this column, for the given order

func (*Column) Tx

func (c *Column) Tx(op rowWiseFunc) transformation

Returns transformer method specific to this column to transform its values from one thing to another It is passed a function expecting a value any type

type Dataframe

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

func FromArray

func FromArray(records []map[string]interface{}, primaryFields []string) (*Dataframe, error)

Constructs a Dataframe from an array of maps and returns a pointer to it

func FromMap

func FromMap(records map[interface{}]map[string]interface{}, primaryFields []string) (*Dataframe, error)

Constructs a Dataframe from a map of maps and returns a pointer to it

func (*Dataframe) Clear

func (d *Dataframe) Clear()

Clears all the data held by the dataframe except the primary key fields

func (*Dataframe) Col

func (d *Dataframe) Col(name string) *Column

Gets the pointer to a given column, or creates it if it does not exist

func (*Dataframe) ColumnNames

func (d *Dataframe) ColumnNames() []string

access method to return all column names

func (*Dataframe) Copy

func (d *Dataframe) Copy() (*Dataframe, error)

Copies the dataframe and returns the new copy

func (*Dataframe) Count

func (d *Dataframe) Count() int

Returns the number of actual active items

func (*Dataframe) Delete

func (d *Dataframe) Delete(filter filterType) error

Deletes the items that fulfill the filters

func (*Dataframe) Insert

func (d *Dataframe) Insert(records []map[string]interface{}) error

Inserts items passed as a list of maps into the Dataframe, It will overwrite any record whose primary field values match with the new records

func (*Dataframe) Keys

func (d *Dataframe) Keys() []string

Access method to return the keys in order

func (*Dataframe) Merge

func (d *Dataframe) Merge(dfs ...*Dataframe) error

Merges the dataframes dfs to d

func (*Dataframe) PrettyPrintRecords

func (d *Dataframe) PrettyPrintRecords() error

Pretty prints the record in this dataframe

Example

The PrettyPrintRecords method prints out the records in a pretty format

df, err := FromArray(dataArray, primaryFields)
if err != nil {
	log.Fatalf("df error is: %s", err)
}

df.PrettyPrintRecords()
Output:

[
	{
		"age": 30,
		"first name": "John",
		"last name": "Doe",
		"location": "Kampala"
	},
	{
		"age": 50,
		"first name": "Jane",
		"last name": "Doe",
		"location": "Lusaka"
	},
	{
		"age": 19,
		"first name": "Paul",
		"last name": "Doe",
		"location": "Kampala"
	},
	{
		"age": 34,
		"first name": "Richard",
		"last name": "Roe",
		"location": "Nairobi"
	},
	{
		"age": 45,
		"first name": "Reyna",
		"last name": "Roe",
		"location": "Nairobi"
	},
	{
		"age": 60,
		"first name": "Ruth",
		"last name": "Roe",
		"location": "Kampala"
	}
]

func (*Dataframe) Select

func (d *Dataframe) Select(fields ...string) *query

Selects a given number of fields, and returns a query instance of the same

func (*Dataframe) ToArray

func (d *Dataframe) ToArray(selectedFields ...string) ([]map[string]interface{}, error)

Converts that dataframe into a slice of records (maps). If selectedFields is a non-empty slice the fields are limited only to the passed fields

func (*Dataframe) Update

func (d *Dataframe) Update(filter []bool, value map[string]interface{}) error

Updates the items that fulfill the given filters with the new value

type Datatype

type Datatype int
const (
	IntType Datatype = iota
	FloatType
	StringType
	ObjectType
	BooleanType
	ArrayType
)

Jump to

Keyboard shortcuts

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