cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Dictionary inside table

pranas
New Contributor
Hello kdb gurus,

I'm total qbie and can't figure out how to use basic tables in kdb+. I believe someone with some practical experience can solve the riddle on how to insert Dictionary to the table.

My attempt to create table with dictionary:

xxx:([]
ext_attrs:() / EXT_ATTRIBUTE
);

.u.upd:insert

Test code:
q)m:(`847`1328`99!("VWAP";"Invalid quantity";"50"))
q)m
847 | "VWAP"
1328| "Invalid quantity"
99  | "50"

Attempt to insert the dictionary to table:
q).u.upd[`xxx;m]
'mismatch

Result:
Failed with some kind of mismatch...

Can someone help me inserting dictionary into table?

If it is possible in q language would it be possible to perform from c.java?

Thanks ๐Ÿ˜‰
P
3 REPLIES 3

julia_partridge
New Contributor


On Tuesday, April 3, 2018 at 6:21:38 AM UTC+1, Pranas Baliuka wrote:
Hello kdb gurus,

I'm total qbie and can't figure out how to use basic tables in kdb+. I believe someone with some practical experience can solve the riddle on how to insert Dictionary to the table.

My attempt to create table with dictionary:

xxx:([]
ext_attrs:() / EXT_ATTRIBUTE
);

.u.upd:insert

Test code:
q)m:(`847`1328`99!("VWAP";"Invalid quantity";"50"))
q)m
847 | "VWAP"
1328| "Invalid quantity"
99  | "50"

Attempt to insert the dictionary to table:
q).u.upd[`xxx;m]
'mismatch

Result:
Failed with some kind of mismatch...

Can someone help me inserting dictionary into table?

If it is possible in q language would it be possible to perform from c.java?

Thanks ๐Ÿ˜‰
P


Hi Pranas,

I believe the following will insert your dictionary into your table:

q)xxx:([]ext_attrs:())

q).u.upd:insert

q)m:(`847`1328`99!("VWAP";"Invalid quantity";"50"))

q).u.upd[`xxx;enlist[`ext_attrs]!enlist m]

,0

q)xxx

ext_attrs

---------------------------------------------

`847`1328`99!("VWAP";"Invalid quantity";"50")


As for the q language in c.java try:

.c.k(".u.upd","xxx",m)

where m is previously constructed following similar examples that can be found here:
http://code.kx.com/q/interfaces/java-client-for-q/

e.g. to publish to a kdb+ consumer, here a kdb+ ticker plant, use

// Assuming a remote schema of

// mytable:([]time:`timespan$();sym:`symbol$();price:`float$();size:`long$())

Object[]row={new c.Timespan(),"SYMBOL",new Double(93.5),new Long(300)};

c.k(".u.upd","mytable",row);

I hope this helps,

Julia  

Hi Pranas

I wonder if you actually want a table at all. It looks like you want to associate the dictionary m with the key xxx. A dictionary would do that for you. A namespace is a dictionary. (Remember Kx reserves all 1-character namespaces to its own use.) 

q)xa:(enlist`)!enlist (::)  / extended attributes dictionary
q).ut.upd:@[`xa;;:;]
q).ut.upd[`xxx;(`847`1328`99!("VWAP";"Invalid quantity";"50"))]
q).ut.upd[`yyy;(`787`1492`99!("VWAP";"Invalid question";"42"))]
q)xa
   | ::
xxx| (`847`1328`99!("VWAP";"Invalid quantity";"50"))
yyy| (`787`1492`99!("VWAP";"Invalid question";"42"))

Note the initialisation of the dictionary. Initialise it as the generic empty dictionary ()!() instead only if every dictionary argument of .ut.upd has the same keys.

Stephen


Stephen Taylor | Librarian | Kx | +44 7713 400852 | stephen@kx.com

nitishkumar1101
New Contributor
q)tab:([]time:`timestamp$();details:())
q)tab
time details
------------
q)meta tab
c      | t f a
-------| -----
time   | p
details|

q)d:(`name`language)!(enlist "nks"; enlist `kdb)
q)d
name    | "nks"
language| kdb

q)`tab insert (.z.p;d)
,0
q)tab
time                          details
-----------------------------------------------------------
2018.04.08D10:00:48.240131000 `name`language!(,"nks";,`kdb)