some database operations

stevan apter — 2003-05-23 22:26:21

i've implemented a few of the basic SQL table operations
in ck - those which involve only a single table:

(cols) select .. f .. from t
(rows) select * from t where .. c ..
(order) select * from t order by .. f asc/desc
(group) select .. agg f .. from t group by .. g ..

plus insert, update, and delete, and a method (table) for
generating random tables of various size and type.

(since the operations are functions which return tables,
they can be embedded in obvious ways to construct any
single-table SQL expression.)

the ck code is a straightforward (well ...) transcription
of the k algorithms:

http://www.nsl.com/k/t.k
http://www.nsl.com/k/ck/t.ck

timings are indistinguishable, which is good. on my pentium
II (a four year old machine) the following million-record
operations take <2, <1, <1, and <1 seconds respectively:

[`F`G`H`I`J] 1000000 [[`a`b`c`d`e] 7 0 0 0] table `T def show time;
T [`G`F] [[desc] [asc]] order T swap rows `V def show time;
T [`F`G] [[[`a`b] lin &:] [5 = &:]] where T swap rows `U def show time;
T [`F`G] [`H`H`H`I] [count sum avg sum] group `W def show time;

on a windows machine, the gui kicks in (show) and you get
displays of the tables. i'll probably add a method similar
to isql to show chunks of the table in the console.

i use pseudo-lambda notation extenstively. at this point,
it's easier to get the code correct, then work on lambda
elimination.