skyd

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2013 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FactorDataType  = "factor"
	StringDataType  = "string"
	IntegerDataType = "integer"
	FloatDataType   = "float"
	BooleanDataType = "boolean"
)
View Source
const (
	QueryConditionUnitSteps    = "steps"
	QueryConditionUnitSessions = "sessions"
	QueryConditionUnitSeconds  = "seconds"
)
View Source
const (
	QueryStepTypeCondition = "condition"
	QueryStepTypeSelection = "selection"
)
View Source
const LuaHeader = `` /* 3011-byte string literal not displayed */
View Source
const (
	Version = "0.3.0"
)

Variables

This section is empty.

Functions

func CondenseUint64Even

func CondenseUint64Even(value uint64) uint32

Condenses the even bits of a 64-bit integer into 32 bits.

func CondenseUint64Odd

func CondenseUint64Odd(value uint64) uint32

Condenses the odd bits of a 64-bit integer into 32 bits.

func ConvertToStringKeys

func ConvertToStringKeys(value interface{}) interface{}

Converts untyped map to a map[string]interface{} if passed a map.

func NewFactorNotFound

func NewFactorNotFound(text string) error

func ShiftTime

func ShiftTime(value time.Time) int64

Shifts a Go time into Sky timestamp format.

func TablePrefix

func TablePrefix(tableName string) ([]byte, error)

Generates a prefix key used for iterating over the table's data.

func UnshiftTime

func UnshiftTime(value int64) time.Time

Shifts a Sky timestamp format into a Go time.

Types

type Event

type Event struct {
	Timestamp time.Time
	Data      map[int64]interface{}
}

An Event is a state change that occurs at a particular point in time.

func NewEvent

func NewEvent(timestamp string, data map[int64]interface{}) *Event

NewEvent returns a new Event.

func (*Event) DecodeRaw

func (e *Event) DecodeRaw(reader io.Reader) error

Decodes an event from MsgPack format.

func (*Event) Dedupe

func (e *Event) Dedupe(a *Event)

Removes data in the event that is present in another event.

func (*Event) EncodeRaw

func (e *Event) EncodeRaw(writer io.Writer) error

Encodes an event to MsgPack format.

func (*Event) Equal

func (e *Event) Equal(x *Event) bool

Compares two events for equality.

func (*Event) MarshalRaw

func (e *Event) MarshalRaw() ([]byte, error)

Encodes an event to MsgPack format and returns the byte array.

func (*Event) Merge

func (e *Event) Merge(a *Event)

Merges the data of another event into this event.

func (*Event) MergePermanent

func (e *Event) MergePermanent(a *Event)

Merges the persistent data of another event into this event.

func (*Event) UnmarshalRaw

func (e *Event) UnmarshalRaw(data []byte) error

type EventList

type EventList []*Event

func (EventList) Len

func (s EventList) Len() int

Determines the length of an event slice.

func (EventList) Less

func (s EventList) Less(i, j int) bool

Compares two events in an event slice.

func (EventList) Swap

func (s EventList) Swap(i, j int)

Swaps two events in an event slice.

type ExecutionEngine

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

An ExecutionEngine is used to iterate over a series of objects.

func NewExecutionEngine

func NewExecutionEngine(table *Table, source string) (*ExecutionEngine, error)

func (*ExecutionEngine) Aggregate

func (e *ExecutionEngine) Aggregate() (interface{}, error)

Executes an aggregation over the iterator.

func (*ExecutionEngine) Destroy

func (e *ExecutionEngine) Destroy()

Closes the lua context.

func (*ExecutionEngine) FullAnnotatedSource

func (e *ExecutionEngine) FullAnnotatedSource() string

Retrieves the full annotated source with line numbers.

func (*ExecutionEngine) FullSource

func (e *ExecutionEngine) FullSource() string

Retrieves the full source sent to the Lua compiler.

func (*ExecutionEngine) Header

func (e *ExecutionEngine) Header() string

Retrieves the generated header for the engine.

func (*ExecutionEngine) Merge

func (e *ExecutionEngine) Merge(results interface{}, data interface{}) (interface{}, error)

Executes an merge over the iterator.

func (*ExecutionEngine) SetIterator

func (e *ExecutionEngine) SetIterator(iterator *levigo.Iterator) error

Sets the iterator to use.

func (*ExecutionEngine) Source

func (e *ExecutionEngine) Source() string

Retrieves the source for the engine.

type FactorNotFound

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

func (*FactorNotFound) Error

func (e *FactorNotFound) Error() string

type Factors

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

A Factors object manages the factorization and defactorization of values.

func NewFactors

func NewFactors(path string) *Factors

NewFactors returns a new Factors object.

func (*Factors) Close

func (f *Factors) Close()

Closes the factors database.

func (*Factors) Defactorize

func (f *Factors) Defactorize(namespace string, id string, value uint64) (string, error)

Converts the factorized value for a given id in a given namespace to its internal representation.

func (*Factors) Factorize

func (f *Factors) Factorize(namespace string, id string, value string, createIfMissing bool) (uint64, error)

Converts the defactorized value for a given id in a given namespace to its internal representation.

func (*Factors) IsOpen

func (f *Factors) IsOpen() bool

Returns whether the factors database is open.

func (*Factors) Open

func (f *Factors) Open() error

Opens the factors databse.

func (*Factors) Path

func (f *Factors) Path() string

The path to the database on disk.

type Property

type Property struct {
	Id        int64  `json:"id"`
	Name      string `json:"name"`
	Transient bool   `json:"transient"`
	DataType  string `json:"dataType"`
}

A Property is a loose schema column on a Table.

func NewProperty

func NewProperty(id int64, name string, transient bool, dataType string) (*Property, error)

NewProperty returns a new Property.

type PropertyFile

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

A PropertyFile manages the serialization of Property objects for a table.

func NewPropertyFile

func NewPropertyFile(path string) *PropertyFile

NewProperty returns a new PropertyFile.

func (*PropertyFile) Close

func (p *PropertyFile) Close()

Closes the property file.

func (*PropertyFile) CreateProperty

func (p *PropertyFile) CreateProperty(name string, transient bool, dataType string) (*Property, error)

Adds a new property to the property file and generate an identifier for it.

func (*PropertyFile) DbPath

func (p *PropertyFile) DbPath() string

The path to the factors database.

func (*PropertyFile) Decode

func (p *PropertyFile) Decode(reader io.Reader) error

Decodes a property file.

func (*PropertyFile) DeleteProperty

func (p *PropertyFile) DeleteProperty(property *Property)

Deletes a property.

func (*PropertyFile) DenormalizeMap

func (p *PropertyFile) DenormalizeMap(m map[int64]interface{}) (map[string]interface{}, error)

Converts a map with property identifier keys to use string keys.

func (*PropertyFile) Encode

func (p *PropertyFile) Encode(writer io.Writer) error

Encodes a property file.

func (*PropertyFile) Factorize

func (p *PropertyFile) Factorize(property *Property, value interface{}) (interface{}, error)

Converts the value for a given property to its internal representation. This only changes the value for 'factor' data types.

func (*PropertyFile) GetAllProperties

func (p *PropertyFile) GetAllProperties() []*Property

Retrieves a list of all properties sorted by id.

func (*PropertyFile) GetProperties

func (p *PropertyFile) GetProperties() []*Property

Retrieves a list of undeleted properties sorted by id.

func (*PropertyFile) GetProperty

func (p *PropertyFile) GetProperty(id int64) *Property

Retrieves a single property by id.

func (*PropertyFile) GetPropertyByName

func (p *PropertyFile) GetPropertyByName(name string) *Property

Retrieves a single property by name.

func (*PropertyFile) IsOpen

func (p *PropertyFile) IsOpen() bool

Returns whether the property file is currently open.

func (*PropertyFile) NextIdentifiers

func (p *PropertyFile) NextIdentifiers() (int64, int64)

Finds the next available action and object property identifiers.

func (*PropertyFile) NormalizeMap

func (p *PropertyFile) NormalizeMap(m map[string]interface{}) (map[int64]interface{}, error)

Converts a map with string keys to use property identifier keys.

func (*PropertyFile) Open

func (p *PropertyFile) Open() error

Opens the property file.

func (*PropertyFile) Path

func (p *PropertyFile) Path() string

The path to the property file on disk.

func (*PropertyFile) Reset

func (p *PropertyFile) Reset()

Clears out the property file.

func (*PropertyFile) Save

func (p *PropertyFile) Save() error

Saves the property file to disk.

type PropertyList

type PropertyList []*Property

A slice of Property objects.

func (PropertyList) Len

func (s PropertyList) Len() int

Determines the length of an event slice.

func (PropertyList) Less

func (s PropertyList) Less(i, j int) bool

Compares two properties in a list.

func (PropertyList) Swap

func (s PropertyList) Swap(i, j int)

Swaps two properties in a list

type Query

type Query struct {
	Steps           QueryStepList
	SessionIdleTime int
	// contains filtered or unexported fields
}

A Query is a structured way of aggregating data in the database.

func NewQuery

func NewQuery(table *Table, factors *Factors) *Query

NewQuery returns a new query.

func (*Query) Codegen

func (q *Query) Codegen() (string, error)

Generates Lua code for the query.

func (*Query) CodegenAggregateFunction

func (q *Query) CodegenAggregateFunction() string

Generates the 'aggregate()' function.

func (*Query) CodegenMergeFunction

func (q *Query) CodegenMergeFunction() string

Generates the 'merge()' function.

func (*Query) Decode

func (q *Query) Decode(reader io.Reader) error

Decodes a query from JSON.

func (*Query) Defactorize

func (q *Query) Defactorize(data interface{}) error

Converts factorized results from the aggregate function results to use the appropriate strings.

func (*Query) Deserialize

func (q *Query) Deserialize(obj map[string]interface{}) error

Decodes a query from an untyped map.

func (*Query) Encode

func (q *Query) Encode(writer io.Writer) error

Encodes a query to JSON.

func (*Query) Factors

func (q *Query) Factors() *Factors

Retrieves the factors this query is associated with.

func (*Query) NextIdentifier

func (q *Query) NextIdentifier() int

Returns an autoincrementing numeric identifier.

func (*Query) Serialize

func (q *Query) Serialize() map[string]interface{}

Encodes a query into an untyped map.

func (*Query) Table

func (q *Query) Table() *Table

Retrieves the table this query is associated with.

type QueryCondition

type QueryCondition struct {
	Expression       string
	WithinRangeStart int
	WithinRangeEnd   int
	WithinUnits      string
	Steps            QueryStepList
	// contains filtered or unexported fields
}

A condition step made within a query.

func NewQueryCondition

func NewQueryCondition(query *Query) *QueryCondition

Creates a new condition.

func (*QueryCondition) CodegenAggregateFunction

func (c *QueryCondition) CodegenAggregateFunction() (string, error)

Generates Lua code for the query.

func (*QueryCondition) CodegenExpression

func (c *QueryCondition) CodegenExpression() (string, error)

Generates Lua code for the expression.

func (*QueryCondition) CodegenMergeFunction

func (c *QueryCondition) CodegenMergeFunction() (string, error)

Generates Lua code for the query.

func (*QueryCondition) Defactorize

func (c *QueryCondition) Defactorize(data interface{}) error

Converts factorized fields back to their original strings.

func (*QueryCondition) Deserialize

func (c *QueryCondition) Deserialize(obj map[string]interface{}) error

Decodes a query condition from an untyped map.

func (*QueryCondition) FunctionName

func (c *QueryCondition) FunctionName() string

Retrieves the function name used during codegen.

func (*QueryCondition) GetSteps

func (c *QueryCondition) GetSteps() QueryStepList

Retrieves the child steps.

func (*QueryCondition) MergeFunctionName

func (c *QueryCondition) MergeFunctionName() string

Retrieves the merge function name used during codegen.

func (*QueryCondition) Query

func (c *QueryCondition) Query() *Query

Retrieves the query this condition is associated with.

func (*QueryCondition) Serialize

func (c *QueryCondition) Serialize() map[string]interface{}

Encodes a query condition into an untyped map.

type QuerySelection

type QuerySelection struct {
	Name       string
	Dimensions []string
	Fields     []*QuerySelectionField
	// contains filtered or unexported fields
}

A selection step aggregates data in a query.

func NewQuerySelection

func NewQuerySelection(query *Query) *QuerySelection

Creates a new selection.

func (*QuerySelection) CodegenAggregateFunction

func (s *QuerySelection) CodegenAggregateFunction() (string, error)

Generates Lua code for the selection aggregation.

func (*QuerySelection) CodegenInnerMergeFunction

func (s *QuerySelection) CodegenInnerMergeFunction(index int) (string, error)

Generates Lua code for the inner merge.

func (*QuerySelection) CodegenMergeFunction

func (s *QuerySelection) CodegenMergeFunction() (string, error)

Generates Lua code for the selection merge.

func (*QuerySelection) Defactorize

func (s *QuerySelection) Defactorize(data interface{}) error

Converts factorized fields back to their original strings.

func (*QuerySelection) Deserialize

func (s *QuerySelection) Deserialize(obj map[string]interface{}) error

Decodes a query selection from an untyped map.

func (*QuerySelection) FunctionName

func (s *QuerySelection) FunctionName() string

Retrieves the function name used during codegen.

func (*QuerySelection) GetSteps

func (s *QuerySelection) GetSteps() QueryStepList

Retrieves the child steps.

func (*QuerySelection) MergeFunctionName

func (s *QuerySelection) MergeFunctionName() string

Retrieves the merge function name used during codegen.

func (*QuerySelection) Query

func (s *QuerySelection) Query() *Query

Retrieves the query this selection is associated with.

func (*QuerySelection) Serialize

func (s *QuerySelection) Serialize() map[string]interface{}

Encodes a query selection into an untyped map.

type QuerySelectionField

type QuerySelectionField struct {
	Name       string
	Expression string
}

func NewQuerySelectionField

func NewQuerySelectionField(name string, expression string) *QuerySelectionField

Creates a new selection field.

func (*QuerySelectionField) CodegenExpression

func (f *QuerySelectionField) CodegenExpression() (string, error)

Generates Lua code for the expression.

func (*QuerySelectionField) CodegenMergeExpression

func (f *QuerySelectionField) CodegenMergeExpression() (string, error)

Generates Lua code for the merge expression.

func (*QuerySelectionField) Deserialize

func (f *QuerySelectionField) Deserialize(obj map[string]interface{}) error

Decodes a query selection from an untyped map.

func (*QuerySelectionField) Serialize

func (f *QuerySelectionField) Serialize() map[string]interface{}

Encodes a query selection into an untyped map.

type QueryStep

type QueryStep interface {
	FunctionName() string
	MergeFunctionName() string
	GetSteps() QueryStepList
	Serialize() map[string]interface{}
	Deserialize(map[string]interface{}) error
	CodegenAggregateFunction() (string, error)
	CodegenMergeFunction() (string, error)
	Defactorize(data interface{}) error
}

type QueryStepList

type QueryStepList []QueryStep

func DeserializeQueryStepList

func DeserializeQueryStepList(obj interface{}, q *Query) (QueryStepList, error)

Decodes a query step list from an untyped slice.

func (QueryStepList) CodegenAggregateFunctions

func (l QueryStepList) CodegenAggregateFunctions() (string, error)

Generates aggregate code for all steps.

func (QueryStepList) CodegenMergeFunctions

func (l QueryStepList) CodegenMergeFunctions() (string, error)

Generates merge code for all steps.

func (QueryStepList) CodegenMergeInvoke

func (l QueryStepList) CodegenMergeInvoke() string

Generates merge invocations.

func (QueryStepList) Defactorize

func (l QueryStepList) Defactorize(data interface{}) error

Defactorizes results generated from the aggregate function.

func (QueryStepList) Serialize

func (l QueryStepList) Serialize() []interface{}

Encodes a query step list into an untyped object.

type Server

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

A Server is the front end that controls access to tables.

func NewServer

func NewServer(port uint, path string) *Server

NewServer returns a new Server.

func (*Server) ApiHandleFunc

func (s *Server) ApiHandleFunc(route string, handlerFunction func(http.ResponseWriter, *http.Request, map[string]interface{}) (interface{}, error)) *mux.Route

Parses incoming JSON objects and converts outgoing responses to JSON.

func (*Server) DataPath

func (s *Server) DataPath() string

The path to the data directory.

func (*Server) DeleteTable

func (s *Server) DeleteTable(name string) error

Deletes a table.

func (*Server) FactorsPath

func (s *Server) FactorsPath() string

The path to the factors database.

func (*Server) GetAllTables

func (s *Server) GetAllTables() ([]*Table, error)

Retrieves a list of all tables in the database but does not open them. Do not use these table references for anything but informational purposes!

func (*Server) GetObjectContext

func (s *Server) GetObjectContext(tableName string, objectId string) (*Table, *Servlet, error)

Executes a function through a single-threaded servlet context.

func (*Server) GetObjectServletIndex

func (s *Server) GetObjectServletIndex(t *Table, objectId string) (uint32, error)

Calculates a tablet index based on the object identifier even hash.

func (*Server) GetTable

func (s *Server) GetTable(name string) *Table

Retrieves a table that has already been opened.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(shutdownChannel chan bool) error

Runs the server.

func (*Server) OpenTable

func (s *Server) OpenTable(name string) (*Table, error)

Opens a table and returns a reference to it.

func (*Server) Path

func (s *Server) Path() string

The root server path.

func (*Server) RunQuery

func (s *Server) RunQuery(table *Table, query *Query) (interface{}, error)

Runs a query against a table.

func (*Server) Running

func (s *Server) Running() bool

Checks if the server is listening for new connections.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Stops the server.

func (*Server) Silence

func (s *Server) Silence()

Silences the log.

func (*Server) TablePath

func (s *Server) TablePath(name string) string

Generates the path for a table attached to the server.

func (*Server) TablesPath

func (s *Server) TablesPath() string

The path to the table metadata directory.

type Servlet

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

A Servlet is a small wrapper around a single shard of a LevelDB data file.

func NewServlet

func NewServlet(path string, factors *Factors) *Servlet

NewServlet returns a new Servlet with a data shard stored at a given path.

func (*Servlet) Close

func (s *Servlet) Close()

Closes the underlying LevelDB database.

func (*Servlet) DeleteEvent

func (s *Servlet) DeleteEvent(table *Table, objectId string, timestamp time.Time) error

Removes an event for a given object in a table to a servlet.

func (*Servlet) DeleteEvents

func (s *Servlet) DeleteEvents(table *Table, objectId string) error

Deletes all events for a given object in a table.

func (*Servlet) GetEvent

func (s *Servlet) GetEvent(table *Table, objectId string, timestamp time.Time) (*Event, error)

Retrieves an event for a given object at a single point in time.

func (*Servlet) GetEvents

func (s *Servlet) GetEvents(table *Table, objectId string) ([]*Event, *Event, error)

Retrieves a list of events and the current state for a given object in a table.

func (*Servlet) GetState

func (s *Servlet) GetState(table *Table, objectId string) (*Event, []byte, error)

Retrieves the state and the remaining serialized event stream for an object.

func (*Servlet) Lock

func (s *Servlet) Lock()

Locks the entire servlet.

func (*Servlet) Open

func (s *Servlet) Open() error

Opens the underlying LevelDB database and starts the message loop.

func (*Servlet) PutEvent

func (s *Servlet) PutEvent(table *Table, objectId string, event *Event, replace bool) error

Adds an event for a given object in a table to a servlet.

func (*Servlet) SetEvents

func (s *Servlet) SetEvents(table *Table, objectId string, events []*Event, state *Event) error

Writes a list of events for an object in table.

func (*Servlet) SetRawEvents

func (s *Servlet) SetRawEvents(table *Table, objectId string, data []byte, state *Event) error

Writes a list of events for an object in table.

func (*Servlet) Unlock

func (s *Servlet) Unlock()

Unlocks the entire servlet.

type Table

type Table struct {
	Name string `json:"name"`
	// contains filtered or unexported fields
}

A Table is a collection of objects.

func NewTable

func NewTable(name string, path string) *Table

NewTable returns a new Table that is stored at a given path.

func (*Table) Close

func (t *Table) Close()

Closes the table.

func (*Table) Create

func (t *Table) Create() error

Creates a table directory structure.

func (*Table) CreateProperty

func (t *Table) CreateProperty(name string, transient bool, dataType string) (*Property, error)

Adds a property to the table.

func (*Table) DefactorizeEvent

func (t *Table) DefactorizeEvent(event *Event, factors *Factors) error

Defactorizes the values in an event.

func (*Table) Delete

func (t *Table) Delete() error

Deletes a table.

func (*Table) DeleteProperty

func (t *Table) DeleteProperty(property *Property) error

Deletes a single property on the table.

func (*Table) DenormalizeMap

func (t *Table) DenormalizeMap(m map[int64]interface{}) (map[string]interface{}, error)

Converts a map with property identifier keys to use string keys.

func (*Table) DeserializeEvent

func (t *Table) DeserializeEvent(m map[string]interface{}) (*Event, error)

Deserializes a map into a normalized event.

func (*Table) EncodeObjectId

func (t *Table) EncodeObjectId(objectId string) ([]byte, error)

Encodes an object identifier for this table.

func (*Table) Exists

func (t *Table) Exists() bool

Checks if the table exists on disk.

func (*Table) FactorizeEvent

func (t *Table) FactorizeEvent(event *Event, factors *Factors, createIfMissing bool) error

Factorizes the values in an event.

func (*Table) GetProperties

func (t *Table) GetProperties() ([]*Property, error)

Retrieves a list of all properties on the table.

func (*Table) GetProperty

func (t *Table) GetProperty(id int64) (*Property, error)

Retrieves a single property from the table by id.

func (*Table) GetPropertyByName

func (t *Table) GetPropertyByName(name string) (*Property, error)

Retrieves a single property from the table by name.

func (*Table) IsOpen

func (t *Table) IsOpen() bool

Checks if the table is currently open.

func (*Table) NormalizeMap

func (t *Table) NormalizeMap(m map[string]interface{}) (map[int64]interface{}, error)

Converts a map with string keys to use property identifier keys.

func (*Table) Open

func (t *Table) Open() error

Opens the table.

func (*Table) Path

func (t *Table) Path() string

Retrieves the path on the table.

func (*Table) SavePropertyFile

func (t *Table) SavePropertyFile() error

Saves the property file on the table.

func (*Table) SerializeEvent

func (t *Table) SerializeEvent(event *Event) (map[string]interface{}, error)

Serializes a normalized event into a map.

type TextPlainContentTypeError

type TextPlainContentTypeError struct {
}

Hackish way to return plain text for query codegen. Might fix later but it's rarely used.

func (*TextPlainContentTypeError) Error

func (e *TextPlainContentTypeError) Error() string

Jump to

Keyboard shortcuts

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