diff --git a/code/common/checkinputs.q b/code/common/checkinputs.q index b5bf6796a..2eb81c0a6 100755 --- a/code/common/checkinputs.q +++ b/code/common/checkinputs.q @@ -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] diff --git a/code/common/dataaccess.q b/code/common/dataaccess.q index b4e646f95..6b45a8144 100644 --- a/code/common/dataaccess.q +++ b/code/common/dataaccess.q @@ -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;()]; @@ -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)]; ]; diff --git a/code/dataaccess/extractqueryparams.q b/code/dataaccess/extractqueryparams.q index 0acc6ce5b..4d9a6442c 100644 --- a/code/dataaccess/extractqueryparams.q +++ b/code/dataaccess/extractqueryparams.q @@ -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}; diff --git a/code/dataaccess/getdata.q b/code/dataaccess/getdata.q index e2925b75c..6d821c3f5 100644 --- a/code/dataaccess/getdata.q +++ b/code/dataaccess/getdata.q @@ -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]]; diff --git a/code/gateway/dataaccess.q b/code/gateway/dataaccess.q index 391569dba..2e349d2cb 100644 --- a/code/gateway/dataaccess.q +++ b/code/gateway/dataaccess.q @@ -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]]]; }; diff --git a/tests/dataaccess/gwquerytest/rdbhelper.q b/tests/dataaccess/gwquerytest/rdbhelper.q index d6c1dabd9..c214eca8a 100644 --- a/tests/dataaccess/gwquerytest/rdbhelper.q +++ b/tests/dataaccess/gwquerytest/rdbhelper.q @@ -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}; diff --git a/tests/dataaccess/queryorder/queryorder.csv b/tests/dataaccess/queryorder/queryorder.csv index a0cb5442b..995968144 100644 --- a/tests/dataaccess/queryorder/queryorder.csv +++ b/tests/dataaccess/queryorder/queryorder.csv @@ -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"