From a3d053e4cc64a00d21320cc9810c9835c1301fcd Mon Sep 17 00:00:00 2001 From: Marcos Jaen Date: Tue, 17 Nov 2026 07:19:51 -0500 Subject: [PATCH 1/4] Make the data-access postback work - .checkinputs.checkpostback rejected every postback. Its two checks look for a sync key, which is not a valid parameter (checkparamnames rejects any request that has one), and signal .schema.errors[`asyncpostback;`errormessage], which errormessages.csv does not define, so the error message was empty. Before #721 the two lines were missing their semicolons and never ran; once they ran, no postback got through. The check now asks the gateway: .gw.call says whether the caller's request is synchronous, and a postback on a sync request is refused with the existing checkpostback message ("Postback key only allowed for async requests"). On a process that is not a gateway, .gw.call does not exist and the check passes. - The gateway posts back (postback;query;result), and the client calls postback[query;result], while the data-access checks only accept a postback that takes one argument (the docs show {0N!x}). So even before #721 a valid postback failed with 'rank on the client. The gateway now hands asyncexecjpt {[f;q;r] f r}[postback], which takes the query and the result and gives the user's function the result. Through the gateway, an async getdata with the postback {`pbres set count x} now sets pbres to the row count on the client, and a sync getdata with a postback is refused with "Postback key only allowed for async requests". --- code/common/checkinputs.q | 5 +++-- code/gateway/dataaccess.q | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) 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/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]]]; }; From cf9c2724ee831a529a3836e09abcae01fc2470e8 Mon Sep 17 00:00:00 2001 From: Marcos Jaen Date: Tue, 17 Nov 2026 07:19:51 -0500 Subject: [PATCH 2/4] Initialise the data-access API at start-up when discovery is off; write three of its checks portably - .dataaccess.init runs on every new connection (.servers.connectcustom), and a process normally makes one at start-up, to discovery. Under a connection limit, such as KDB-X's free licence (16 connections), TorQ turns discovery off (#727), so a process with no other connection to make never got the data-access API, and most data-access tests failed there. With discovery off, init now also runs once at the end of start-up, and a failure there is only logged, as on a new connection. With discovery on nothing changes. - .checkinputs.checkeachparam iterates over the row indices of the parameter table rather than over the table itself, which not every q implementation can iterate. The result is the same. - .eqp.extractoptimisationkey sets optimisation from the request, or 1b, instead of filling one dictionary into another with ^. - readtableproperties writes its "all or blank" proctype list as ``all rather than `all` - the same two symbols - as some q implementations' functional selects return nothing when a literal symbol list ends with the null symbol. --- code/common/checkinputs.q | 3 ++- code/common/dataaccess.q | 11 +++++++++++ code/dataaccess/dataaccessutils.q | 4 ++-- code/dataaccess/extractqueryparams.q | 4 ++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/code/common/checkinputs.q b/code/common/checkinputs.q index 2eb81c0a6..37fcbe9d9 100755 --- a/code/common/checkinputs.q +++ b/code/common/checkinputs.q @@ -49,7 +49,8 @@ checkrepeatparams:{[dict] // loop thorugh input parameters to execute parameter specific checks checkeachparam:{[dict;isrequired] config:select from .checkinputs.checkinputsconfig where parameter in key dict,required=isrequired; - :checkparam/[dict;config]; + // over the row indices rather than over the table itself, which not every q implementation can iterate + :{[c;d;i] checkparam[d;c i]}[config]/[dict;til count config]; }; // extract parameter specific function from config to check the input 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/dataaccessutils.q b/code/dataaccess/dataaccessutils.q index fa90de91f..98091f7f4 100644 --- a/code/dataaccess/dataaccessutils.q +++ b/code/dataaccess/dataaccessutils.q @@ -4,9 +4,9 @@ readtableproperties:{[tablepropertiepath] .lg.o[`readtableproperties;"loading table properties"]; table:`tablename`proctype xkey readcsv[tablepropertiepath;"ssssstsss"]; //read in table from file - alltable:?[table;enlist(in;`proctype;enlist`all`);0b;()]; //find any instance of the use "all" or blank for proctype + alltable:?[table;enlist(in;`proctype;enlist``all);0b;()]; //find any instance of the use "all" or blank for proctype table:table,![alltable;();0b;(enlist`proctype)!enlist(enlist `hdb)],![alltable;();0b;(enlist`proctype)!enlist(enlist `rdb)]; //join rdb and hdb entries for any "all" or blank entries - table:![table;enlist(in;`proctype;enlist`all`);0b;`symbol$()]; //remove "all" or blank entries from table + table:![table;enlist(in;`proctype;enlist``all);0b;`symbol$()]; //remove "all" or blank entries from table table:?[table;$[.proc.proctype=`gateway;();enlist(=;`proctype;`.proc.proctype)];0b;()]; table:update .eodtime.datatimezone ^ datatimezone, .eodtime.rolltimeoffset ^ rolltimeoffset,.eodtime.rolltimezone^rolltimezone from table; table:update `date ^ partitionfield from table where proctype<>`rdb; 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}; From f0f121a98d3e939d2b56d2f24e6fee79f7594976 Mon Sep 17 00:00:00 2001 From: Marcos Jaen Date: Tue, 17 Nov 2026 07:19:51 -0500 Subject: [PATCH 3/4] Fix two data-access tests - dataaccess/gwquerytest: since #639 the RDB advertises its partition through .rdb.getpartition, which processes/rdb.q defines. The test's mock RDB does not load rdb.q and only set .rdb.rdbpartition, so .proc.getattributes failed, the gateway held no attributes for it, and every query routed to the RDB got "no info found for that table name and time range". The mock RDB now defines .rdb.getpartition as well. - dataaccess/queryorder loaded its HDB with \l hdb, which is $TORQHOME/hdb, not the test's own HDB with the attribute helpers. --- tests/dataaccess/gwquerytest/rdbhelper.q | 2 ++ tests/dataaccess/queryorder/queryorder.csv | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) 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" From c5029650cd62703b577fb788f60b6352483478e4 Mon Sep 17 00:00:00 2001 From: Marcos Jaen Date: Tue, 1 Dec 2026 09:45:02 -0500 Subject: [PATCH 4/4] Keep master's data-access forms and rename columns only when asked checkeachparam iterates over the config table again, and readtableproperties writes the symbol list as enlist`all` again. Both were rewritten for q engines that read them differently from kdb+. The current builds of those engines read master's forms as kdb+ does, so the rewrites are no longer needed. getdata renames its result's columns only where the query asks for a rename. Without one it called xcol with an empty dictionary, which kdb+ accepts and which gives 'type on some q engines, so every getdata call failed there. --- code/common/checkinputs.q | 3 +-- code/dataaccess/dataaccessutils.q | 4 ++-- code/dataaccess/getdata.q | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/code/common/checkinputs.q b/code/common/checkinputs.q index 37fcbe9d9..2eb81c0a6 100755 --- a/code/common/checkinputs.q +++ b/code/common/checkinputs.q @@ -49,8 +49,7 @@ checkrepeatparams:{[dict] // loop thorugh input parameters to execute parameter specific checks checkeachparam:{[dict;isrequired] config:select from .checkinputs.checkinputsconfig where parameter in key dict,required=isrequired; - // over the row indices rather than over the table itself, which not every q implementation can iterate - :{[c;d;i] checkparam[d;c i]}[config]/[dict;til count config]; + :checkparam/[dict;config]; }; // extract parameter specific function from config to check the input diff --git a/code/dataaccess/dataaccessutils.q b/code/dataaccess/dataaccessutils.q index 98091f7f4..fa90de91f 100644 --- a/code/dataaccess/dataaccessutils.q +++ b/code/dataaccess/dataaccessutils.q @@ -4,9 +4,9 @@ readtableproperties:{[tablepropertiepath] .lg.o[`readtableproperties;"loading table properties"]; table:`tablename`proctype xkey readcsv[tablepropertiepath;"ssssstsss"]; //read in table from file - alltable:?[table;enlist(in;`proctype;enlist``all);0b;()]; //find any instance of the use "all" or blank for proctype + alltable:?[table;enlist(in;`proctype;enlist`all`);0b;()]; //find any instance of the use "all" or blank for proctype table:table,![alltable;();0b;(enlist`proctype)!enlist(enlist `hdb)],![alltable;();0b;(enlist`proctype)!enlist(enlist `rdb)]; //join rdb and hdb entries for any "all" or blank entries - table:![table;enlist(in;`proctype;enlist``all);0b;`symbol$()]; //remove "all" or blank entries from table + table:![table;enlist(in;`proctype;enlist`all`);0b;`symbol$()]; //remove "all" or blank entries from table table:?[table;$[.proc.proctype=`gateway;();enlist(=;`proctype;`.proc.proctype)];0b;()]; table:update .eodtime.datatimezone ^ datatimezone, .eodtime.rolltimeoffset ^ rolltimeoffset,.eodtime.rolltimezone^rolltimezone from table; table:update `date ^ partitionfield from table where proctype<>`rdb; 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]];