Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update kdb/tick Syntax to Latest Versions (Specifically 4.1) #1

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions tick.q
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,19 @@ if[not system"p";system"p 5010"]
\l tick/u.q
\d .u
ld:{if[not type key L::`$(-10_string L),string x;.[L;();:;()]];i::j::-11!(-2;L);if[0<=type i;-2 (string L)," is a corrupt log. Truncate to length ",(string last i)," and restart";exit 1];hopen L};
tick:{init[];if[not min(`time`sym~2#key flip value@)each t;'`timesym];@[;`sym;`g#]each t;d::.z.D;if[l::count y;L::`$":",y,"/",x,10#".";l::ld d]};
tick:{[x:{init[];$[not min(`time`sym~2#key flip value@)each t;'`timesym;x]};y]@[;`sym;`g#]each t;d::.z.D;if[l::count y;L::`$":",y,"/",x,10#".";l::ld d]};

endofday:{end d;d+:1;if[l;hclose l;l::0(`.u.ld;d)]};
ts:{if[d<x;if[d<x-1;system"t 0";'"more than one day?"];endofday[]]};

updC:{$[-16=type first first x;x;[a:.z.N;$[0>type first x;a,x;enlist[count[first x]#a],x]]]}; // Common function in both options (Batch; Real Time)
if[system"t";
.z.ts:{pub'[t;value each t];@[`.;t;@[;`sym;`g#]0#];i::j;ts .z.D};
upd:{[t;x]
if[not -16=type first first x;if[d<"d"$a:.z.P;.z.ts[]];a:"n"$a;x:$[0>type first x;a,x;(enlist(count first x)#a),x]];
t insert x;if[l;l enlist (`upd;t;x);j+:1];}];
upd:{{[t;x]t insert x;if[l;l enlist (`upd;t;x);j+:1];}[x]updC y}];

if[not system"t";system"t 1000";
.z.ts:{ts .z.D};
upd:{[t;x]ts"d"$a:.z.P;
if[not -16=type first first x;a:"n"$a;x:$[0>type first x;a,x;(enlist(count first x)#a),x]];
f:key flip value t;pub[t;$[0>type first x;enlist f!x;flip f!x]];if[l;l enlist (`upd;t;x);i+:1];}];
upd:{{[t;x]f:key flip value t;pub[t;$[0>type first x;enlist f!x;flip f!x]];if[l;l enlist (`upd;t;x);i+:1];}[x] updC y}];

\d .
.u.tick[src;.z.x 1];
Expand Down
8 changes: 4 additions & 4 deletions tick/u.q
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
/2006.05.08 add

\d .u
init:{w::t!(count t::tables`.)#()}
init:{w::(t::tables`.)!()}

del:{w[x]_:w[x;;0]?y};.z.pc:{del[;x]each t};

sel:{$[`~y;x;select from x where sym in y]}
sel:{(select from x where sym in y;x)`~y}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are not getting a performance bonus from the new implementation I think I would revert back to its previous version, since it's a bit confusing. When reading the code, you look for a conditional statement, but you get something else.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the main reason for this change was because it's shorter :)
I still believe it's quite clear, so I'll keep it until our master @neutropolis makes the decision

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, just to drag my point across, should we change all ifs to this syntax?

(then;)cond;

I.e:

if[x~`;:sub[;y]each t];
// to
(:sub[;y]each t];)x~`;

Haven't tested it yet, but I'll do so whenever I get to download v4.1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not new in 4.1. We are simply indexing. For example, in this case, x~ will return 0b or 1b. The idea is to index and return the first or second position from the list on the right. I believe this is suitable for small and simple cases.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point still stands. I personally would keep it as it was, but if we are changing it then we should keep it consistent and change every instance of a conditional statement OR every if/else ($) statement. Let's wait to see what @neutropolis has to say about this.


pub:{[t;x]{[t;x;w]if[count x:sel[x]w 1;(neg first w)(`upd;t;x)]}[t;x]each w t}
pub:{[t;x]{[t;x:sel[;w 1];w]if[count x;(neg first w)(`upd;t;x)]}[t;x]each w t}

add:{$[(count w x)>i:w[x;;0]?.z.w;.[`.u.w;(x;i;1);union;y];w[x],:enlist(.z.w;y)];(x;$[99=type v:value x;sel[v]y;@[0#v;`sym;`g#]])}

sub:{if[x~`;:sub[;y]each t];if[not x in t;'x];del[x].z.w;add[x;y]}
sub:{[x:{$[not x in t,`;'x;x]};y]if[x~`;:sub[;y]each t];del[x].z.w;add[x;y]}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose to add

,`

at the end of the condition?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I have been able to guess, since the ifs' are switched, you need to check if x is the null symbol on the first condition as well, and this can be achieved using in, like it has been done here. Still, I don't really see the point of doing this unless we get a speed benefit of some sort.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I just added it because I tried to incorporate the new syntax as much as possible. I need to measure how fast or slow this is, so once I do that, I'll determine if it's worthwhile or not


end:{(neg union/[w[;;0]])@\:(`.u.end;x)}