John Dempster - John Dempster
Forum Replies Created
-
AuthorPosts
-
John DempsterMemberhttps://www.timestored.com/pulse/help/faq/timeseries-zoom
Left click and drag to select area = Zoom in
Double click = Zoom outIf chart has a zoom bar shown.
Mouse-wheel Up = Zoom in
Mouse-wheel Down = Zoom out
John DempsterMemberSet one of the columns to the right hand side axis and multiple axis will automatically be created.
A new expander will appear allowing customization of the right and left axis:See https://www.timestored.com/pulse/help/chart-customization#multiAxis
John DempsterMemberFor a full list of available date time types see here:
http://www.timestored.com/b/forums/topic/kdb-date-time-types/
John DempsterMemberThe date time types available in kdb are:
char size num literal null name sql java .net p 8 12 dateDtimespan 0Np timestamp Timestamp DateTime (r/w) m 4 13 2000.01m 0Nm month d 4 14 2000.01.01 0Nd date date Date z 8 15 dateTtime 0Nz datetime timestamp Timestamp DateTime*(read only) n 8 16 00:00:00.000000000 0Nn timespan Timespan TimeSpan u 4 17 00:00 0Nu minute v 4 18 00:00:00 0Nv second t 4 19 00:00:00.000 0Nt time time Time TimeSpan Our cheat sheet includes the full data types table:
http://www.timestored.com/kdb-guides/kdb-reference-card
John DempsterMemberIn qStudio right click on the result panel and choose an export option.
John DempsterMemberFrom official customer list:
Goldman Sachs
Morgan Stanley
Merrill Lynch
J.P. Morgan
Deutsche Bank
Oppenheimer Capital Markets
UniCredit Bank AG
DekaBank
ConvergEx
Commerzbank AG
RBC Capital Markets
Connor, Clark & Lunn Financial Group
GSA Capital
Total Gas & Power UKOther ones include:
Numerous hedge funds
Nomura
MUSI
UBS
Barclays Bank
Citi Bank
John DempsterMemberMany people use cron.tab or autosys for scheduled tasks. From a shell script they can then run q scripts and return exit codes to log success.
John DempsterMemberOr you can mangle strings together and use eval:
q)f:{value “select “,(“,” sv string x),” from t”}
q)t:([] q:til 9; w:til 9; e:9?9)
q)t
q w e
—–
0 0 4
1 1 2
2 2 7
3 3 0
4 4 1
5 5 2
6 6 1
7 7 8
8 8 8
q)f:{value “select “,(“,” sv string x),” from t”}
q)f[`q`e]
q e
—
0 4
1 2
2 7
3 0
4 1
5 2
6 1
7 8
8 8
q)- This reply was modified 10 years, 8 months ago by John Dempster.
John DempsterMemberSomeone has actually written up a guide to importing a regular expression library:
http://code.kx.com/wiki/Cookbook/regexkdb+ has some builtin regex features, for use with like and ssr.
For those who need something more flexible, it’s possible to leverage regex libs such as re2, described below.
The home for re2 can be found at [1] The code below was compiled for kdb+v3.1 with this release [2] The k.h file can be downloaded from [3] For 64bit linux, this can be compiled as
g++ -m64 -O2 re2.cc -o re2.so -I . re2/obj/libre2.a -DKXVER=3 -shared -static
and the resulting re2.so should be copied into $QHOME/l64 subdirectory.
It can then be loaded and called in kdb+ via
q)f:`re2 2:(`FullMatch;2) / bind FullMatch to f
q)f[“hello world”;”hello ..rld”]#include
#include
#include//malloc
#include
#include”k.h”using namespace re2;
extern “C” {
Z S makeErrStr(S s1,S s2){Z __thread char b[256];snprintf(b,256,”%s – %s”,s1,s2);R b;}
Z __inline S c2s(S s,J n){S r=(S)malloc(n+1);R r?memcpy(r,s,n),r[n]=0,r:(S)krr((S)”wsfull (re2)”);}
K FullMatch(K x,K y){
S s,sy;K r;
P(x->t&&x->t!=KC&&x->t!=KS&&x->t!=-KS||y->t!=KC,krr((S)”type”))
U(sy=c2s((S)kC(y),y->n))
RE2 pattern(sy,RE2::Quiet);
free(sy);
P(!pattern.ok(),krr(makeErrStr((S)”bad regex”,(S)pattern.error().c_str())))
if(!x->t||x->t==KS){
J i=0;
K r=ktn(KB,x->n);
for(;in;i++){
K z=0;
P(!x->t&&(z=kK(x)[i])->t!=KC,(r0(r),krr((S)”type”)))
s=z?c2s((S)kC(z),z->n):kS(x)[i];P(!s,(r0(r),(K)0))
kG(r)[i]=RE2::FullMatch(s,pattern);
if(z)free(s);
}
R r;
}
s=x->t==-KS?x->s:c2s((S)kC(x),x->n);
r=kb(RE2::FullMatch(s,pattern));
if(s!=x->s)free(s);
R r;
}
}
John DempsterMemberThe uppercase letters return local date time e.g. .z.Z
While the lowercase letters return GMT time
The offset is based on the OS settings.
John DempsterMemberkdb+ does not have a scheduler, it provides a timer which can be used to schedule simple regular tasks.
The \t timer is specified in milliseconds, saying how long the delay between firings are.
The event handler .z.ts can then be defined to perform an action every X milliseconds.e.g.
\t can be used to either find the current timer setting (0 is off) or set the between
`
q)\t
0i
q) / Set our timer handler to show the current time
q).z.ts:{show .z.t}
q)\t 11000
q)15:40:58.353
15:41:09.353
15:41:20.352q)\t 5000
q)15:41:23.724
15:41:28.723
15:41:33.723`Turn it off, then set timer to increment a variable, restart timer to trigger every 100 milliseconds.
`
q)\t 0
q)a:1
q).z.ts:{a::a+1}
q)\t 100
q)a
10
q)a
17
q)a
25
q)a
32`
John DempsterMemberMost programming languages follow the substitution principle that assigning a value to a variable, means anywhere that variable is used the user can consider it as if the value was directly entered in place. Breaking this common rule to allow simplification of the parser at the expense of user friendliness is not a choice many other languages have made.
Because this is such uncommon and non-intuitive behavior for what is a common piece of code, I would call it a bug.
John DempsterMemberWhen selecting based on the condition of a string or char array column, “like” is normally used.
The verb like takes two arguments
1. The list of strings to search
2. The pattern to be searched for
The pattern has certain meta characters like *,? and [] that allow pattern matching.
However full regular expressions are not supported.Here are some examples:
q)t:([] a:til 6; name:(“John Smith”;”John Doe”;”Kate Beck”;”George Bush”;”Isaac Asimov”; “Dave Beck”))
q)t
a name
—————-
0 “John Smith”
1 “John Doe”
2 “Kate Beck”
3 “George Bush”
4 “Isaac Asimov”
5 “Dave Beck”/ perfect matches, rely on correct case
q)select from t where name like “John Smith”
a name
————–
0 “John Smith”
q)select from t where name like “John smith”
a name
——/ * – matches any number of characters
q)select from t where name like “John*”
a name
————–
0 “John Smith”
1 “John Doe”/ ? – Represents any single character
q)select from t where name like “???? Beck”
a name
————-
2 “Kate Beck”
5 “Dave Beck”/ [] – square brackets contain allowed character sets
q)select from t where name like “John [S]*”
a name
————–
0 “John Smith”q)select from t where name like “John [SD]*”
a name
————–
0 “John Smith”
1 “John Doe”Here we used it to match a table with a string column, you can use it on a plain list of strings or symbols as well.
Regards,
John
John DempsterMemberKX regularly hold workshops internationally: http://www.kx.com/events-kx.php
We provide free kdb+ tutorials for learning kdb: http://www.timestored.com/kdb-guides
We can come deliver a training course at your company: http://www.timestored.com/kdb-training
There are two mailing lists, a few linkedin groupsBest way to learn is to go through q for mortals, our free tutorials then try and use it to solve an actual problem you have or make up one.
Best of luck.
-JD
John DempsterMemberCurly brackets contain a function. e.g.
{x+1}
would be a function that adds one to it’s argument.{[a] b:a*10; b}
In this function we have named the argument a
Created a variable b which is ten times a
and returned that vlue (Since it’s the last statement){} is only used to contain function bodies there is no other use in kdb.
-
AuthorPosts