2023.01.01 09:10 PM - edited 2023.01.01 10:20 PM
As per the subject - I have a beef with the Apply form for traversing larger nested data structures.
My Beef stems from the fact that I can't satisfy myself that literally any portion of a data object can be accessed by these functions (from this point, it's probably fair to focus on the . form). Previously, I had built a process for converting an HTML document (a web page) into a Q object and then traversing it essentially listing all the paths in the document and the value at the end of it. Problem was, I ended up re-inventing something like an apply function until I was advised that no, in fact Apply can be used to navigate any nested Q object. I had kind of moved on from the project by then so didn't really sweat it too much and, as I'm prone to being rubbish as much as the next person, wrote it off as user error on my part.
Anyway, I'm back and have hit on a similar issue again, this time with a much less nested object. So my question is this:
Given this data object (metaTbl):
A:(flip (enlist `c)!enlist `date`ric`alias`dmn`tStamp`gmtOffset`dtype`price`volume`bidPrice`bidSize`askPrice`askSize`tPriceCcy`uTid`ref);
B:(flip `t`f`a`k`s`p`m!("dssspsfffffffssg";
````````````````;
``g```s```````````;
0000000000000000b;
0N 0N 0N 0N -1 0N 0N 0N 0N 0N 0N 0N 0N 0N 0N 0Ni;
1 0N 0N 0N -1 0N 0N 0N 0N 0N 0N 0N 0N 0N 0N 0Ni;
(();();();();();();();();();();();();();();();
`ref`timestamp`note`tableName`sourceName`groupName`base`calcType`versn`recCount`import!("G"$"6bbb7ba2-b7dc-c40f-a936-0c136f87d198";2023.01.02D17:03:23.207315000;
enlist "import using flow";`trades;`$"DOW trade to 19.csv";`$"DOW JONES";`import;`csv;1;399546810;enlist(`ric`alias`dmn`tStamp`gmtOffset`dtype`price`volume`bidPrice`bidSize`askPrice`askSize`tPriceCcy`uTid!
"SSSPSFFFFFFFSS";enlist (flip (enlist `c)!enlist `date`ric`alias`dmn`tStamp`gmtOffset`dtype`price`volume`bidPrice`bidSize`askPrice`askSize`tPriceCcy`uTid`ref)!flip `t`f`a`k`s`p`m!
("dssspsfffffffssg";
````````````````mtaTrades;
``g```s```````````;
1111111111111111b;
0N 0N 0N 0N -1 0N 0N 0N 0N 0N 0N 0N 0N 0N 0N 0Ni;
1 0N 0N 0N -1 0N 0N 0N 0N 0N 0N 0N 0N 0N 0N 0Ni;
(();();();();();();();();();();();();();();();
`ref`timestamp`note`tableName`sourceName`groupName`base`calcType`versn`recCount`import!
("G"$"6bbb7ba2-b7dc-c40f-a936-0c136f87d198";2023.01.02D17:03:23.206957000;enlist "import using flow";`trades;`$"DOW trade to 19.csv";`$"DOW JONES";`import;`csv;1;399546810;
enlist (`ric`alias`dmn`tStamp`gmtOffset`dtype`price`volume`bidPrice`bidSize`askPrice`askSize`tPriceCcy`uTid!"SSSPSFFFFFFFSS";`)))))))));
metaTbl:A!B;
Using only the Apply syntax on metaTbl and a path, I want to access the dictionary which we can access using:
last value .[metaTbl;(::;`m)]
This is because in the larger project, I am looking to define any data in a data object (be it an item in a list or a value in a dictionary) in terms of a path to that data.
Can Apply do this? If so, how? If not, is this a 'known thing' and are there any advised ways to recover 'paths' without writing some sort of Apply equivalent that does that but without the mess, memory bloat and slowness you would expect from a half-arsed home-made attempt to re-engineer already well optimized solid functionality in Q?
Keen to hear - also Merry Christmas and Happy New Year.
Simon
2023.01.02 04:30 AM
A more direct path to that dictionary in this case would be:
.[metaTbl;(`ref;`m)]
2023.01.02 04:30 AM
A more direct path to that dictionary in this case would be:
.[metaTbl;(`ref;`m)]
2023.01.03 01:21 AM
rocuinneagain - you got the moves!
2023.01.06 01:55 AM - edited 2023.01.06 01:58 AM
Or, for that matter,
metaTbl . `ref`m
So, if you are thinking of defining objects by their paths, in this case the path would be `ref`m
.
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.