Wednesday, April 18, 2012

My model of the NoSql Json database engine

As my readers know, I am moving from the lab beta to production model of the open architecture semantic processor.  I move ahead because Moore's Law dictates that we can execute Json expression trees right out of database.  I like Berkeley DB, but I am sticking with Sqlite3. But the interface between Json grammar is clean, 30 lines of code actually.  Let us talk about the new programming interface:

Here is Hello World.
#include "machine.h"
const Key helloKey={4,"hello"};
Element helloElement = {",",1,hello};
Join j = InitJoin;
int main() {
Graph console;
Graph mem;
InitMem(&graph,0);
graph.exec(&graph,Append,&helloElement);
InitConsole(&console,0);
join.result=console.cursors;
join.right=mem.cursors;
left_join();}

And the Typeface equivalent:

Console@"Hello",*


The central interface object is the Graph, under the new semantics. The graph is the link between the cursor and the installed database. The graph has the exec method and a nested cursor list.

A cursor is built on the row pointer in each element:
typedef struct RowSequenc {int row;int total;int offset} RowSequence;

Then we get the cursor:
typedef struct {RowSequence rdx;Graph * graph;} Cursor;
//and the Join
typedef struct { Cursor result; Cursor left; Cursor right;} Join;
So everything runs as if by cursors crawling exo skeletal expression graphs.

The file out method:
#define EX(obj,method,e) obj->exec(obj,method,&e)
int file_out(*) {
Element n;Graph * obj,file;Cursor * c;
obj = join.left->graph;
EX(obj,StepFetch,n);
InitFile(&file,n.key.bytes);
c = join.result; join.result=file.cursors;
left_joint();
join.result=c;}

The whole principle is that stack operation have been replaced by graph crawling. Here is open an sql table:
Graph sql;
InitSql(&sql,"TableName");
Then tryp:
join.left=sql.cursors;
left_join();

// So based on that and on my parser, I have built a simple Json engine, well simple is a modest description, here it is:
 int left_join() {
while(left.cursors->row < left.cursors.total)
   while(right.cursors->row < left.cursors.total)
do_left_operator();
}
Everything else is very small snippets of code that obey Lazy J match,pass and collect grammar for nested stores. All the Sqlite3 code went into the sqlite3 adapter layer, and is almost working again. MyJson unit comes complete with the memory data base. I have also defined the 9 lines of code Yes database which does: *@*,* // Agree with anything!

The Yes database is real, is makes the join seem act like two initialized counters.

No comments: