-
Lists, dictionaries, tables and lists of dictionaries
Team,
I’ve got an interest in data processing for higher dimensional objects so have been putting in a bit of thought about how best to represent sometimes quite nested data structures in KDB/Q.
Using the Apply function has become part of my routine but as I’ve used it, I’ve come to realize that maybe the way it works at present could be a limited case of a more general model. I think these are the nubs of my thought bubble:
- lists and dictionaries are distinct and separate objects in KDB. However, even though they might be implemented as separate objects, wouldn’t it make more sense to consider a list as a special case of a dictionary where the keys are numbers?
- we can use ‘flip’ to move between a dictionary of lists and a table but actually, shouldn’t a table just be a special case of a dictionary of lists where all the lists are the same length? In that case, if we think back to what a function actually offers us, should we consider ‘flip’ as a function that primarily allows us to move from using dictionary type syntax to table type syntax even though the semantic representations are fundamentally of the same structure?
The reason this is an issue for me is in my nested structures, I can have dictionaries, lists or even tables at various depths. The apply function works well mostly but I’ve found situations but I find it fails where (for instance) one of the layers branches off to a list of strings.
What I’m thinking is, if the underlying object is equivalent, shouldn’t we regard the distinction between lists of dictionaries and tables as just a matter of the approach you choose to manipulate the object rather than a property of the object itself? In that case, wouldn’t a function such as Apply be better if it was agnostic about such things? Basically, you provide a set of keys and it should just operate on those keys, indifferent to whether it is traversing between dictionaries, lists or tables?
I’ve had a crack at a generic ‘Apply’ that kind of does this by incrementally traversing a set of keys using ‘over’ and flipping the structure at that level when needed. I’d be happy to share my efforts (I can’t currently start Q since I rebuilt my computer on the weekend and for some reason, I’m not getting a new license when I submit my email for the Q install).
However, before I disappear too far down this rabbit hole – are there arguments why it might make more sense to keep this separation between lists and dictionaries or tables and dictionaries of lists?
Log in to reply.