Getting type error when adding 2 dictionaries to KDB

I can add and assign a second dictionary (si) to someone with (dt)

 d1:`d`t!(.zd ;.zt) d1,:`s`i!`VOD`L d1 

However, the other way does not work, I get an error like:

 d2:`s`i!`VOD`L d2,:`d`t!(.zd ;.zt) d2 
+5
source share
2 answers

In the first case (dt) makes a heterogeneous dictionary:

 q)d1:`d`t!(.zd ;.zt) q)type value d1 0h 

now if you add and assign any kind of homogeneous or heterogeneous dictionary, it will work.

while in another case the first dictionary created is homogeneous and it throws an error when you add and assign a heterogeneous dictionary (or a homogeneous dictionary of a different type, for that matter)

 q)d2:`s`i!`VOD`L q)type value d2 11h q)type value `d`t!(.zd ;.zt) 

To solve this problem, you only need to add a dictionary and then assign it.

 q)d2:`s`i!`VOD`L q)d2:d2, `d`t!(.zd ;.zt) q)d2 s| `VOD i| `L d| 2018.03.25 t| 09:59:17.109 
+5
source

When the d2 dictionary was created all the values ​​in which the characters. When you try to update this with d2,: with non-character types, this causes kdb to throw an error due to inappropriate types. One way to prevent this is to add a null key to the dictionary, which ensures that you can have mixed types for your values:

 q)d2:enlist[`]!enlist(::) / add null key q)d2,:`s`i!`VOD`L q)d2 | :: s| `VOD i| `L q)d2,:`d`t!(.zd ;.zt) q)d2 | :: s| `VOD i| `L d| 2018.03.25 t| 09:42:52.754 

If you explore a namespace, such as .q or create your own, you will see that there is a null key to ensure that namespaces can contain mixed types.

+3
source

Source: https://habr.com/ru/post/1276065/


All Articles