Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
614 views
in Technique[技术] by (71.8m points)

kdb - Why does not work select from a keyed table

A query result looks good if I break keyed table apart into key-value pair and combine them together: key!value. But a straight select from it gives an error. I constructed that keyed table in a slightly weird manner:

q)show t:([n:1 2] m:(`a`b!3 4;`a`b!5 6));
n| m
-| --------
1| `a`b!3 4
2| `a`b!5 6
q)t[;`m]
n| a b
-| ---
1| 3 4
2| 5 6
q)select from (key t[;`m])!value t[;`m]
n| a b
-| ---
1| 3 4
2| 5 6
q)select from t[;`m]
'type
  [0]  select from t[;`m]
       ^

Where does this 'type error come from?

question from:https://stackoverflow.com/questions/65941099/why-does-not-work-select-from-a-keyed-table

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Doing an exact match on what we expect t[;`m] to be shows that something is up. If we deconstruct and reconstruct we get them being equal.

q)([n:1 2]a:3 5;b:4 6)~t[;`m]
0b
q)([n:1 2]a:3 5;b:4 6)~{key[x]!value x}t[;`m]
1b

We can get clues from the internal byte representation using -8!, which unfortunately is not well documented. It seems that the values are being represented as a general list (type 0h => 0x00) of dictionaries instead of a table (type 98h => 0x62).

q)-8!`a`b!3 4
0x0100000029000000630b00020000006100620007000200000003000000000000000400000000000000
q)-8!t[;`m]
0x0100000078000000636200630b00010000006e0000000100000007000200000001000000000000000200000000000000000002000000630b00020000006100620007000200000003000000000000000400000000000000630b00020000006100620007000200000005000000000000000600000000000000
q)-8!([n:1 2]a:3 5;b:4 6)
0x010000006f000000636200630b00010000006e00000001000000070002000000010000000000000002000000000000006200630b0002000000610062000000020000000700020000000300000000000000050000000000000007000200000004000000000000000600000000000000

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...