snowflake

package module
v0.0.0-...-22abb2a Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2016 License: MIT Imports: 6 Imported by: 2

README

Snowflake UDF for SensorBee

This UDF generates IDs using Snowflake algorithm proposed by Twitter. The ID is a 63 bit integer consisting of:

  • 41 bit of timestamp in milliseconds (works for 69 years)
  • 10 bit of machine id which must manually be assigned to each machine
  • 12 bit of counter used for IDs having the same timestamp (generates up to 4096 IDs within a millisecond)

Usage

Registering plugin

Just import plugin package from an application:

import (
    _ "pfi/sensorbee/snowflake/plugin"
)

Or, register the user defined state and UDF manually to bql package.

Using UDF from BQL

-- Create a user defined state for snowflake UDF.
CREATE STATE event_id_seq TYPE snowflake_id WITH machine_id=1

-- Assign IDs to an event sequence. IDs will be generated based on
-- the state 'event_id_seq'
CREATE STREAM events_with_id AS SELECT snowflake_id('event_id_seq'), * FROM events;

TODO

  • Provide timestamp_offset which allows users to generate ID available for 69 years from "now"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewState

func NewState(ctx *core.Context, params data.Map) (core.SharedState, error)

NewState returns a user defined state for snowflake ID generation. This function can be registered as UDSCreator.

func Snowflake

func Snowflake(ctx *core.Context, stateName data.Value) (data.Value, error)

Snowflake generates a new ID based on snowflake ID generation algorithm. stateName must point to a shared state created by NewState.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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