olap

package module
v0.0.0-...-f684b15 Latest Latest
Warning

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

Go to latest
Published: May 28, 2018 License: MIT Imports: 2 Imported by: 2

README

olap

OLAP cube for in memory data processing

GoDoc Go Report Card

Install

go get github.com/xdbsoft/olap

Use

package main

import (
    "fmt"
    "github.com/xdbsoft/olap"
)
	
func main() {
    cube := olap.Cube{
        Dimensions : []string{"year", "month", "product"},
        Fields: []string{"revenue"},
    }

    cube.AddRows([]string{"year", "month", "product", "revenue"}, [][]interface{}{
        {2017, "Jan", "apple", 100},
        {2017, "Jan", "orange", 80},
        {2018, "Jan", "apple", 120},
        {2018, "Jan", "orange", 40},
        {2018, "Feb", "apple", 75},
        {2018, "Feb", "orange", 75},
    })

    cube = cube.Slice("year", 2018)
    cube = cube.Rollup([]string{"product"}, cube.Fields, sum ,[]interface{}{0})

    fmt.Print(cube.Rows())
    /* The following lines will be printed:
     * apple, 195
     * orange, 115
     */
}

func sum(aggregate, value []interface{}) []interface{} {
    s := aggregate[0].(int)
    s += value[0].(int)
    return []interface{}{s}
}

Tests

go test is used for testing.

License

This code is licensed under the MIT license. See LICENSE.

This code is inspired by https://github.com/fibo/OLAP-cube/ (javascript implementation of an OALP cube)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregator

type Aggregator func(aggregate, value []interface{}) []interface{}

Aggregator is a summarization method to be used by RollUp operator

type Cube

type Cube struct {
	Dimensions []string        `json:"dimensions,omitempty"`
	Points     [][]interface{} `json:"points,omitempty"`
	Fields     []string        `json:"fields,omitempty"`
	Data       [][]interface{} `json:"data,omitempty"`
}

Cube is an OLAP cube

func (*Cube) AddRows

func (c *Cube) AddRows(header []string, rows [][]interface{}) error

AddRows add a set of rows to the cube.

func (Cube) Dice

func (c Cube) Dice(selector func(c Cube, idx int) bool) Cube

Dice operator picks a subcube by choosing a specific values of multiple dimensions.

func (Cube) Headers

func (c Cube) Headers() []string

Headers return the name of the columns for the Rows method.

func (Cube) IsValid

func (c Cube) IsValid() error

IsValid verify that a Cube is properly instentiated

func (Cube) RollUp

func (c Cube) RollUp(dimensions []string, fields []string, aggregator Aggregator, initialValue []interface{}) Cube

RollUp operator summarize the data along multiple dimensions. Ex: rollup(['year','month'], ['flights'], (sum, value) => [sum[0]+value[0]], [0])

func (Cube) Rows

func (c Cube) Rows() [][]interface{}

Rows return the Cube content as list of rows. Headers are available via Headers method.

func (Cube) Slice

func (c Cube) Slice(dimension string, value interface{}) Cube

Slice operator picks a rectangular subset of a cube by choosing a single value of its dimensions.

Jump to

Keyboard shortcuts

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