kdb

package module
v0.0.0-...-5b0205c Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: MIT Imports: 16 Imported by: 0

README

Go driver for kdb+

Build Status

This is an implementation of kdb+ driver native in Go. It implements Q IPC protocol.

Can be used both as a client(Go program connects to kdb+ process) and as a server(kdb+ connects to Go program). In server mode no execution capabilities are available.

For documentations and examples see godoc

Documentation

Overview

Package kdb implements encoding and decoding of q ipc message format

Index

Constants

View Source
const (
	ASYNC = iota
	SYNC
	RESPONSE
)

Request type

View Source
const (
	K0 int8 = 0 // generic type
	//      type bytes qtype     ctype  accessor
	KB int8 = 1  // 1 boolean   char   kG
	UU int8 = 2  // 16 guid     U      kU
	KG int8 = 4  // 1 byte      char   kG
	KH int8 = 5  // 2 short     short  kH
	KI int8 = 6  // 4 int       int    kI
	KJ int8 = 7  // 8 long      long   kJ
	KE int8 = 8  // 4 real      float  kE
	KF int8 = 9  // 8 float     double kF
	KC int8 = 10 // 1 char      char   kC
	KS int8 = 11 // * symbol    char*  kS

	KP int8 = 12 // 8 timestamp long   kJ (nanoseconds from 2000.01.01)
	KM int8 = 13 // 4 month     int    kI (months from 2000.01.01)
	KD int8 = 14 // 4 date      int    kI (days from 2000.01.01)
	KZ int8 = 15 // 8 datetime  double kF (DO NOT USE)
	KN int8 = 16 // 8 timespan  long   kJ (nanoseconds)
	KU int8 = 17 // 4 minute    int    kI
	KV int8 = 18 // 4 second    int    kI
	KT int8 = 19 // 4 time      int    kI (millisecond)

	// table,dict
	XT int8 = 98  //   x->k is XD
	XD int8 = 99  //   kK(x)[0] is keys. kK(x)[1] is values.
	SD int8 = 127 // sorted dict

	// function types
	KFUNC      int8 = 100
	KFUNCUP    int8 = 101 // unary primitive
	KFUNCBP    int8 = 102 // binary primitive
	KFUNCTR    int8 = 103 // ternary (operator)
	KPROJ      int8 = 104 // projection
	KCOMP      int8 = 105 // composition
	KEACH      int8 = 106 // f'
	KOVER      int8 = 107 //	f/
	KSCAN      int8 = 108 // f\
	KPRIOR     int8 = 109 // f':
	KEACHRIGHT int8 = 110 // f/:
	KEACHLEFT  int8 = 111 // f\:
	KDYNLOAD   int8 = 112 // dynamic load

	// error type
	KERR int8 = -128
)

Q type constants

Short nil

Int nil

Long nil

Short infinity

Int Infinity

Long Infinity

Variables

View Source
var ErrBadHeader = errors.New("Bad header")

Message header is invalid

View Source
var ErrSyncRequest = errors.New("nosyncrequest")

Cannot process sync requests

Double nil

View Source
var Wf float64 = math.Inf(1)

Double Infinity

Functions

func Compress

func Compress(b []byte) (dst []byte)

Compress b using Q IPC compression

func Encode

func Encode(w io.Writer, msgtype int, data *K) error

Encode data to ipc format as msgtype(sync/async/response) to specified writer

func HandleClientConnection

func HandleClientConnection(conn net.Conn)

process clients requests

func NewRuntimeError

func NewRuntimeError(msg string) error

NewRuntimeError initializes a new RuntimeError with a message.

func NewUnsupportedTypeError

func NewUnsupportedTypeError(msg string) error

NewUnsupportedTypeError initializes a new UnsupportedTypeError with a message.

func Uncompress

func Uncompress(b []byte) (dst []byte)

Ucompress byte array compressed with Q IPC compression

func UnmarshalDict

func UnmarshalDict(t Dict, v interface{}) error

Unmarshall dict to struct

func UnmarshalDictToMap

func UnmarshalDictToMap(t Dict, v interface{}) error

Unmarshall dict to map[string]{}interface

func UnmarshalTable

func UnmarshalTable(t Table, v interface{}) (interface{}, error)

Types

type Attr

type Attr uint8

Vector attributes

const (
	NONE Attr = iota
	SORTED
	UNIQUE
	PARTED
	GROUPED
)

type Dict

type Dict struct {
	Key   *K
	Value *K
}

Dictionary: ordered key->value mapping. Key and Value must be slices of the same length

func (Dict) String

func (d Dict) String() string

type Function

type Function struct {
	Namespace string
	Body      string
}

Function

type K

type K struct {
	Type int8
	Attr Attr
	Data interface{}
}

K structure

func Bool

func Bool(x bool) *K

func BoolV

func BoolV(x []bool) *K

func Byte

func Byte(x byte) *K

func ByteV

func ByteV(x []byte) *K

func Date

func Date(x time.Time) *K

func DateV

func DateV(x []time.Time) *K

func Decode

func Decode(src *bufio.Reader) (*K, int, error)

Decodes data from src in q ipc format.

func Enlist

func Enlist(x ...*K) *K

func Error

func Error(x error) *K

func Float

func Float(x float64) *K

func FloatV

func FloatV(x []float64) *K

func Int

func Int(x int32) *K

func IntV

func IntV(x []int32) *K

func Long

func Long(x int64) *K

func LongV

func LongV(x []int64) *K

func NewDict

func NewDict(k, v *K) *K

func NewFunc

func NewFunc(ctx, body string) *K

func NewTable

func NewTable(cols []string, data ...*K) *K

func Real

func Real(x float32) *K

func RealV

func RealV(x []float32) *K

func Short

func Short(x int16) *K

func ShortV

func ShortV(x []int16) *K

func String

func String(x string) *K

func Symbol

func Symbol(x string) *K

func SymbolV

func SymbolV(x []string) *K

func Time

func Time(x time.Time) *K

func TimeV

func TimeV(x []time.Time) *K

func Timespan

func Timespan(x time.Duration) *K

func TimespanV

func TimespanV(x []time.Duration) *K

func Timestamp

func Timestamp(x time.Time) *K

func TimestampV

func TimestampV(x []time.Time) *K

func UUID

func UUID(x uuid.UUID) *K

func UUIDV

func UUIDV(x []uuid.UUID) *K

func (*K) Index

func (k *K) Index(i int) interface{}

Index returns i'th element of K structure

func (*K) Len

func (k *K) Len() int

Len returns number of elements in K structure Special cases: Atoms and functions = 1 Dictionaries = number of keys Tables = number of rows

func (K) String

func (k K) String() string

Convert K structure to string

type KDBConn

type KDBConn struct {
	Host string
	Port string
	// contains filtered or unexported fields
}

KDBConn establishes connection and communicates using Q IPC protocol

func DialKDB

func DialKDB(host string, port int, auth string) (*KDBConn, error)

func DialKDBEx

func DialKDBEx(host string, port int, auth string, deadline time.Time, tlsCfg *tls.Config) (*KDBConn, error)

Connect to host:port using supplied user:password. Wait timeout for connection

func DialUnix

func DialUnix(host string, port int, auth string) (*KDBConn, error)

Connect to port using unix domain sockets. host parameter is ignored.

func (*KDBConn) AsyncCall

func (c *KDBConn) AsyncCall(cmd string, args ...*K) (err error)

Make asynchronous call to kdb+

func (*KDBConn) Call

func (c *KDBConn) Call(cmd string, args ...*K) (data *K, err error)

Make synchronous call to kdb+ similar to h(func;arg1;arg2;...)

func (*KDBConn) CallEx

func (c *KDBConn) CallEx(deadline time.Time, cmd string, args ...*K) (data *K, err error)

func (*KDBConn) Close

func (c *KDBConn) Close() error

Close connection to the server

func (*KDBConn) ReadMessage

func (c *KDBConn) ReadMessage() (data *K, msgtype int, e error)

Read complete message from connection

func (*KDBConn) Response

func (c *KDBConn) Response(data *K) (err error)

Send response to asynchronous call

func (*KDBConn) WriteMessage

func (c *KDBConn) WriteMessage(msgtype int, data *K) (err error)

Send data in Q IPC format

type Minute

type Minute time.Time

Minute

func (Minute) String

func (m Minute) String() string

type Month

type Month int32

Month

func (Month) String

func (m Month) String() string

type RuntimeError

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

RuntimeError is a runtime error thrown by a Q engine

func (*RuntimeError) Error

func (e *RuntimeError) Error() string

type Second

type Second time.Time

Second hh:mm:ss

func (Second) String

func (s Second) String() string

type Table

type Table struct {
	Columns []string
	Data    []*K
}

Table

func (*Table) Index

func (tbl *Table) Index(i int) Dict

func (Table) String

func (tbl Table) String() string

type UnsupportedTypeError

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

UnsupportedTypeError is an error returned when encoding or decoding a type that is not supported by kdb

func (*UnsupportedTypeError) Error

func (e *UnsupportedTypeError) Error() string

Jump to

Keyboard shortcuts

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