Code Monkey home page Code Monkey logo

erlang-q's Introduction

Build Status

Q interfacing with Erlang/OTP

Usage

If you use rebar just add

{deps, [
	{q, ".*", {git, "git://github.com/michaelwittig/erlang-q.git", {tag, "v0.1.2"}}}
]}.

to your dependencies.

A Q connection in Erlang is a gen_server.

execute Q code as string

{ok, Pid} = q:connect(<<"localhost">>, 5000).
2 = q:execute(Pid, <<"1+1">>).
q:close(Pid).

execute Q functions with params

{ok, Pid} = q:connect(<<"localhost">>, 5000).
15 = q:execute(Pid, <<"sum">>, q_ipcp:serialize_ints([1, 2, 3, 4, 5])).
q:close(Pid).

subscribe (kdb+tick)

After you subscribe, incoming data is distributed using the gen_event behaviour. Events are {q, Table, Data}. If you want to print the data to sysour you can use q_demo_handler module.

{ok, Pid} = q:connect({q_demo_handler, []}, <<"localhost">>, 5000).
q:subscribe(Pid, <<"trade">>, <<"TEST">>).

(De)Serialization

Keep in mind that null values in Q are deserialized to atom null in Erlang.

boolean

Q => Erlang

1b => true
0b => false

Erlang => Q

q_ipcp:serialize_boolean(true) => 1b
q_ipcp:serialize_boolean(false) => 0b

guid

Q => Erlang

0a369037-75d3-b24d-6721-5a1d44d4bed5 => <<10, 54, 144, 55, 117, 211, 178, 77, 103, 33, 90, 29, 68, 212, 190, 213>>
0Ng => null

Erlang => Q

q_ipcp:serialize_guid(<<10, 54, 144, 55, 117, 211, 178, 77, 103, 33, 90, 29, 68, 212, 190, 213>>) => 0a369037-75d3-b24d-6721-5a1d44d4bed5
q_ipcp:serialize_guid(null) => 0Ng

byte

Q => Erlang

0x01 => <<1>>

Erlang => Q

q_ipcp:serialize_byte(<<1>>) => 0x01

short

Q => Erlang

1h => 1
0Nh => null

Erlang => Q

q_ipcp:serialize_short(1) => 1h
q_ipcp:serialize_short(null) => 0Nh

int

Q => Erlang

1i => 1
0Ni => null

Erlang => Q

q_ipcp:serialize_int(1) => 1i
q_ipcp:serialize_int(null) => 0Ni

long

Q => Erlang

1j => 1
0Nj => null

Erlang => Q

q_ipcp:serialize_long(1) => 1j
q_ipcp:serialize_long(null) => 0Nj

real

Q => Erlang

1.0e => 1.0
0Ne => null

Erlang => Q

q_ipcp:serialize_real(1.0) => 1.0e
q_ipcp:serialize_long(null) => 0Ne

float

Q => Erlang

1.0f => 1.0
0Nf => null

Erlang => Q

q_ipcp:serialize_float(1.0) => 1.0f
q_ipcp:serialize_float(null) => 0Nf

char

Q => Erlang

"a" => <<"a">>

Erlang => Q

q_ipcp:serialize_char(<<"a">>) => "a"

symbol

Q => Erlang

`a => <<"a">>
` => null

Erlang => Q

q_ipcp:serialize_symbol(a) => `a
q_ipcp:serialize_symbol(<<"a">>) => `a
q_ipcp:serialize_symbol(null) => `

timestamp

Q => Erlang

2014.06.23D11:34:39.412547000 => 456838479412547000
0Np => null

Erlang => Q

q_ipcp:serialize_timestamp(456838479412547000) => 014.06.23D11:34:39.412547000
q_ipcp:serialize_timestamp(null) => 0Np

month

Q => Erlang

2014.01m => 168 % months since 2000.01
0Nm => null

Erlang => Q

q_ipcp:serialize_month(168) => 2014.01m
q_ipcp:serialize_month(null) => 0Nm

date

Q => Erlang

2014.01.01 => 5114 % days since 2000.01.01
0Nd => null

Erlang => Q

q_ipcp:serialize_date(5114) => 2014.01.01
q_ipcp:serialize_date(null) => 0Nd

datetime

Q => Erlang

2014.06.23T11:49:31.533 => 4662535674435194874
0Nz => null

Erlang => Q

q_ipcp:serialize_datetime(4662535674435194874) => 2014.06.23T11:49:31.533
q_ipcp:serialize_datetime(null) => 0Nz

timespan

Q => Erlang

00:01:00.000000000 => 60000000000
0Nn => null

Erlang => Q

q_ipcp:serialize_timespan(60000000000) => 00:01:00.000000000
q_ipcp:serialize_timespan(null) => 0Nn

minute

Q => Erlang

00:01 => 1
0Nu => null

Erlang => Q

q_ipcp:serialize_minute(1) => 00:01
q_ipcp:serialize_minute(null) => 0Nu

second

Q => Erlang

00:00:01 => 1
0Nv => null

Erlang => Q

q_ipcp:serialize_second(1) => 00:00:01
q_ipcp:serialize_second(null) => 0Nv

time

Q => Erlang

00:00:00.001 => 1
0Nt => null

Erlang => Q

q_ipcp:serialize_time(1) => 00:00:00.001
q_ipcp:serialize_time(null) => 0Nt

mixed list

Q => Erlang

(1j; 1b; `a) => [1, true, a]
() => []

Erlang => Q

q_ipcp:serialize_generallist([q_ipcp:serialize_long(1), q_ipcp:serialize_boolean(true), q_ipcp:serialize_symbol(a)])) => (1j; 1b; `a)

lists

Q => Erlang

The items of a list are deserialized like described in the type.

(1i;2i;3i) => [1, 2, 3]

Erlang => Q

Each q_ipcp:serialize_TYPE(VALUE) has a counterpart for lists q_ipcp:serialize_TYPEs([VALUE1, VALUE2])

q_ipcp:serialize_floats([1.0, 2.0, 3.0]) => (1.0f; 2.0f; 3.0f)

dict

Each key value pair is represented as a tuple {Key, Value}. The keys are values of a dict are deserialized like described in the type.

Q => Erlang

(`a`b)!(2 3) => [{<<"a">>, 2}, {<<"b">>, 3}]

Erlang => Q

NOT YET SUPPORTED

table

To handle tables in Erlang you should use q_table module.

Q => Erlang

([] a:enlist 2; b:enlist 3) => [{<<"a">>, [2]}, {<<"b">>, [3]}]

Erlang => Q

NOT YET SUPPORTED

Contribution

If you want to create a Pull-Request please make sure that make test runs without failures.

Development

Run tests

make test

Generate documentation

make doc

EDoc

click me

What is missing?

  • time types helper
  • decompression of received bytes if they are compressed
  • simple Erlang (de)serialization

erlang-q's People

Contributors

michaelwittig avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.