skizze

package
v0.0.0-...-1e7855a Latest Latest
Warning

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

Go to latest
Published: May 6, 2016 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package skizze is a client for the Skizze database.

The Skizze repository (https://github.com/skizzehq/skizze) provides more information about Skizze and how to use it.

Example:

 package main

 import (
   "fmt"

   "github.com/skizzehq/goskizze/skizze"
 )

 func main() {
   client, err := skizze.Dial("127.0.0.1:3596", skizze.Options{Insecure: true})
   if err != nil {
     fmt.Printf("Error connecting to Skizze: %s\n", err)
     return
   }

   // A domain is an easy way to use the same data set for multiple statistics
   name := "testdomain"
   client.CreateDomain(name)

  // Adding values to a domain will trigger statistics generation for each of
  // the supported Sketches in the domain
  client.AddToDomain(name, "alvin", "simon", "theodore")

  // The Membership sketch will test if a value resides in a data set, returning
  // true or false
  membs, _ := client.GetMembership(name, "alvin", "simon", "theodore", "gary")
  for _, m := range membs {
    fmt.Printf("MEMB: %s is in %s: %v\n", m.Value, name, m.IsMember)
  }

  // The Frequency sketch will return how many times a value occurs in a sketch
  freqs, _ := client.GetFrequency(name, "alvin", "simon", "theodore", "gary")
  for _, f := range freqs {
    fmt.Printf("FREQ: %s appears in %s %v times\n", f.Value, name, f.Count)
  }

  // The Rankings sketch will always keep the top N (configurable) rankings and
  // their occurrance counts
  ranks, _ := client.GetRankings(name)
  for i, r := range ranks {
    fmt.Printf("RANK: #%v = %s (count=%v)\n", i, r.Value, r.Count)
  }

  // Finally, the Cardinality sketch will keep a count of how many unique items
  // have been added to the data set
  card, _ := client.GetCardinality(name)
  fmt.Printf("CARD: There are %v items in the %s domain\n\n", card, name)

  client.DeleteDomain(name)
}

Output:

MEMB: alvin is in testdomain: true
MEMB: simon is in testdomain: true
MEMB: theodore is in testdomain: true
MEMB: gary is in testdomain: false

FREQ: alvin appears in testdomain 1 times
FREQ: simon appears in testdomain 1 times
FREQ: theodore appears in testdomain 1 times
FREQ: gary appears in testdomain 0 times

RANK: #0 = alvin (count=1)
RANK: #1 = simon (count=1)
RANK: #2 = theodore (count=1)

CARD: There are 3 items in the testdomain domain

For a full guide, visit https://github.com/skizzehq/goskizze.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents a a thread-safe connection to Skizze

func Dial

func Dial(address string, opts Options) (*Client, error)

Dial initalizes a connection to Skizze and returns a client

func (*Client) AddToDomain

func (c *Client) AddToDomain(name string, values ...string) error

AddToDomain will add the supplied values to the domain's data set.

func (*Client) AddToSketch

func (c *Client) AddToSketch(name string, t SketchType, values ...string) error

AddToSketch will add the supplied values to the sketch's data set.

func (*Client) Close

func (c *Client) Close()

Close shuts down the client connection to Skizze.

func (*Client) CreateDomain

func (c *Client) CreateDomain(name string) (*Domain, error)

CreateDomain creates a new domain with default properties per Sketch.

func (*Client) CreateDomainWithProperties

func (c *Client) CreateDomainWithProperties(name string, props *DomainProperties) (*Domain, error)

CreateDomainWithProperties creates a domain with customized properties.

func (*Client) CreateSketch

func (c *Client) CreateSketch(name string, t SketchType, p *Properties) (*Sketch, error)

CreateSketch creates a new sketch.

func (*Client) DeleteDomain

func (c *Client) DeleteDomain(name string) error

DeleteDomain deletes a domain

func (*Client) DeleteSketch

func (c *Client) DeleteSketch(name string, t SketchType) error

DeleteSketch deletes a sketch

func (*Client) GetCardinality

func (c *Client) GetCardinality(name string) (int64, error)

GetCardinality queries the sketch for the cardinality of items.

func (*Client) GetDomain

func (c *Client) GetDomain(name string) (*Domain, error)

GetDomain gets the details of a domain.

func (*Client) GetFrequency

func (c *Client) GetFrequency(name string, values ...string) (ret []*FrequencyResult, err error)

GetFrequency queries the sketch for frequency for the provided values.

func (*Client) GetMembership

func (c *Client) GetMembership(name string, values ...string) (ret []*MembershipResult, err error)

GetMembership queries the sketch for membership (true/false) for the provided values.

func (*Client) GetMultiCardinality

func (c *Client) GetMultiCardinality(names []string) (ret []int64, err error)

GetMultiCardinality queries multiple sketches for the cardinality of items.

func (*Client) GetMultiFrequency

func (c *Client) GetMultiFrequency(names []string, values ...string) (ret [][]*FrequencyResult, err error)

GetMultiFrequency queries multiple sketches for the frequency of the provided values.

func (*Client) GetMultiMembership

func (c *Client) GetMultiMembership(names []string, values ...string) (ret [][]*MembershipResult, err error)

GetMultiMembership queries multiple sketches for membership of the provided values.

func (*Client) GetMultiRankings

func (c *Client) GetMultiRankings(names []string) (ret [][]*RankingsResult, err error)

GetMultiRankings queries multiple sketches for the top rankings.

func (*Client) GetRankings

func (c *Client) GetRankings(name string) (ret []*RankingsResult, err error)

GetRankings queries the sketch for the top rankings.

func (*Client) GetSketch

func (c *Client) GetSketch(name string, t SketchType) (*Sketch, error)

GetSketch gets the details of a sketch.

func (*Client) ListAll

func (c *Client) ListAll() (ret []*Sketch, err error)

ListAll gets all the available Sketches.

func (*Client) ListDomains

func (c *Client) ListDomains() (ret []string, err error)

ListDomains gets all the available domains

func (*Client) ListSketches

func (c *Client) ListSketches(t SketchType) (ret []*Sketch, err error)

ListSketches gets all the sketches of the specified type.

type Domain

type Domain struct {
	Name     string
	Sketches []*Sketch
}

Domain describes details of a Skizze domain

type DomainProperties

type DomainProperties struct {
	MembershipProperties Properties
	FrequencyProperties  Properties
	RankingsProperties   Properties
}

DomainProperties details configuration for Sketches in a domain

type FrequencyResult

type FrequencyResult struct {
	Value string
	Count int64
}

FrequencyResult indicates the result of a frequency query for a value.

type MembershipResult

type MembershipResult struct {
	Value    string
	IsMember bool
}

MembershipResult indicates the result of a membership query for a value.

type Options

type Options struct {
	// Insecure disables transport security for the Client connection.
	Insecure bool
}

Options contains connection options

type Properties

type Properties struct {
	MaxUniqueItems int64
	ErrorRate      float32

	// Size is used by Rankings sketches to determine the number of rankings this
	// Sketch should track e.g. top 10, top 100, top 1000
	Size int64
}

Properties are configuration settings for a Sketch.

type RankingsResult

type RankingsResult struct {
	Value string
	Count int64
}

RankingsResult indicates the result of a ranking query for a value.

type Sketch

type Sketch struct {
	Name       string
	Type       SketchType
	Properties *Properties
}

Sketch describes the details of a sketch

type SketchType

type SketchType int

SketchType is the kind of sketch

const (
	// Membership sketches can evaluate if a data set contains an element.
	Membership SketchType = iota
	// Frequency sketches can evaluate the frequency of an element in a data set.
	Frequency
	// Ranking sketches return the top ranked elements of the data set.
	Ranking
	// Cardinality sketches evaluate how many distinct elements are in the data set.
	Cardinality
)

type Snapshot

type Snapshot struct {
	Status  SnapshotState
	Message string
}

Snapshot represents details of the a snapshot

type SnapshotState

type SnapshotState int

SnapshotState indicates the state of the current or previous snapshot.

const (
	// Pending indicates a snapshot is waiting to be taken.
	Pending SnapshotState = iota
	// InProgress indicates a snapshot is currently being taken.
	InProgress
	// Successful indicates the last snapshot was successful.
	Successful
	// Failed indicates the last snapshot had an error.
	Failed
)

Jump to

Keyboard shortcuts

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