Skip to content
Merged
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
5 changes: 3 additions & 2 deletions code/common/checkinputs.q
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ checkjoin:{[dict;parameter]:checktype[107h;dict;parameter];};

checkpostback:{[dict;parameter]
if[()~dict parameter;:dict];
if[not `sync in key dict;'`$.schema.errors[`asyncpostback;`errormessage]];
if[not dict`sync;'`$.schema.errors[`asyncpostback;`errormessage]];
// a postback is only for async requests: in the gateway, .gw.call says whether the caller's request is sync
// (no request can carry a sync key: it is not a valid parameter)
if[@[{.gw.call x};.z.w;0b];'`$.schema.errors[`checkpostback;`errormessage]];
:checkpostprocessing[dict;parameter]};

checktimeout:{[dict;parameter]
Expand Down
11 changes: 11 additions & 0 deletions code/common/dataaccess.q
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ init:{[tablepropertiespath]
.lg.o[`.dataaccess.init;"running .dataaccess.init - finished"];
};

// init at the end of start-up: a failure is only logged, as it is when init runs on a new connection (an error in the
// init list would stop the process)
startupinit:{[tablepropertiespath] @[init;tablepropertiespath;{.lg.w[`.dataaccess.init;"could not initialise the data access API: ",x]}]};

// 1b when discovery is off. TorQ turns it off under a connection limit, such as KDB-X's free licence (DISCOVERYCONNECT
// in config/settings/default.q), and then a process may make no connection at all, so init, which runs on each new
// connection, would never run
nodiscovery:{[] not @[value;`.servers.DISCOVERYCONNECT;1b]};

connectcustom:{[f;connectiontab]
@[f;connectiontab;()];
@[.dataaccess.init;.dataaccess.tablepropertiespath;()];
Expand All @@ -55,4 +64,6 @@ if[`dataaccess in key .proc.params;
.dataaccess.settablepropertiespath[];
// re-initialize on new connections
if[.dataaccess.validtablepropertiespath[];.servers.connectcustom:.dataaccess.connectcustom];
// and, with discovery off, once start-up has finished (see nodiscovery)
if[.dataaccess.validtablepropertiespath[] and .dataaccess.nodiscovery[];.proc.addinitlist(`.dataaccess.startupinit;.dataaccess.tablepropertiespath)];
];
4 changes: 2 additions & 2 deletions code/dataaccess/extractqueryparams.q
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ extractfreeformcolumn:{[inputparams;queryparams]
};

extractoptimisationkey:{[inputparams;queryparams]
A:((1#`optimisation)!1#1b)^inputparams;
:@[queryparams;`optimisation;:;A`optimisation];
// optimisation defaults to 1b (set directly rather than by filling one dictionary into another with ^)
:@[queryparams;`optimisation;:;$[`optimisation in key inputparams;inputparams`optimisation;1b]];
};

jointableproperties:{[inputparams;queryparams]queryparams,enlist[`tableproperties]#inputparams};
Expand Down
4 changes: 2 additions & 2 deletions code/dataaccess/getdata.q
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ getdata:{[inputparams]
// order the query after it's fetched
if[not 0~count (queryparams`ordering);
table:f[table;;queryparams`ordering]/[1;last til count (queryparams`ordering)]];
// rename the columns
result:queryparams[`renamecolumn] xcol table;
// rename the columns, where there are any to rename (not every q implementation takes an empty dictionary in xcol)
result:$[count queryparams`renamecolumn;queryparams[`renamecolumn] xcol table;table];
// apply post-processing function if called in process or query to single process called from gateway
if[(10b~in[`postprocessing`procs;key inputparams])or((1b~`postprocessing in key inputparams)and(1~count inputparams `procs));
result:.eqp.processpostback[result;inputparams`postprocessing]];
Expand Down
5 changes: 3 additions & 2 deletions code/gateway/dataaccess.q
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ getdata:{[o]
:$[.gw.call .z.w;
// if sync
.gw.syncexecjt[(`getdata;o);options[`procs];autojoin[options];options[`timeout]];
// if async
.gw.asyncexecjpt[(`getdata;o);options[`procs];autojoin[options];options[`postback];options[`timeout]]];
// if async: the gateway calls a postback with the query and the result, and the data-access postback takes
// the result only
.gw.asyncexecjpt[(`getdata;o);options[`procs];autojoin[options];$[()~p:options`postback;();{[f;q;r] f r}p];options[`timeout]]];
};


Expand Down
2 changes: 2 additions & 0 deletions tests/dataaccess/gwquerytest/rdbhelper.q
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.rdb.rdbpartition: enlist 2000.01.06;
// rdbstandard.q advertises the partition with .rdb.getpartition (defined in processes/rdb.q, which this mock RDB does not load)
.rdb.getpartition:{[] .rdb.rdbpartition};
2 changes: 1 addition & 1 deletion tests/dataaccess/queryorder/queryorder.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
action,ms,bytes,lang,code,repeat,minver,comment
beforeany,0,0,q,system "sleep 1",1,,"Wait for all procs to go up"
before,0,0,q,\l hdb,1,,"load the HDB"
before,0,0,q,"loadhdb ` sv (hsym`$getenv`KDBTESTS),`dataaccess`queryorder`hdb",1,,"load the test HDB (\l hdb loaded $TORQHOME/hdb instead)"
before,0,0,q,.servers.startup[],1,,"Get connection management set up"
before,0,0,q,.dataaccess.init[.dataaccess.tablepropertiespath],1,,"Run the init function"
true,0,0,q,testfunction[`basicsymquery],1,,"Basic sym check"
Expand Down