KDB:如何将字符串数据类型分配给所有列
KDB: How to assign string datatype to all columns
当我创建 table 选项卡时,我将列指定为字符串,
Tab: ([Key1:string()] Col1:string();Col2:string();Col3:string())
但是列数据类型 (t) 为空。我想将列指定为字符串无效。
meta Tab
c t f a
--------------------
Key1
Col1
Col2
Col3
在 Java 中进行批量更新后...
c.Dict dict = new c.Dict((Object[]) columns.toArray(new String[columns.size()]), data);
c.Flip flip = new c.Flip(dict);
conn.c.ks("upsert", table, flip);
数据类型均为符号:
meta Tab
c t f a
--------------------
Key1 s
Col1 s
Col2 s
Col3 s
如何将列的数据类型指定为字符串并使其保持为字符串?
您不能用字符串定义空列 table,因为它们只是字符列表的列表
您可以将它们设置为空列表,这就是您的代码所做的。
但是该列将采用插入其中的任何数据的类型。
真正的问题是您的 java 进程在应该发送字符串时发送符号。在发布到 KDB
之前,您需要在那里进行更改
请注意,如果您定义为字符,您仍然无法插入字符串
q)Tab: ([Key1:`char$()] Col1:`char$();Col2:`char$();Col3:`char$())
q)Tab upsert ([Key1:enlist"test"] Col1:enlist"test";Col2:enlist"test";Col3:enlist "test")
'rank
[0] Tab upsert ([Key1:enlist"test"] Col1:enlist"test";Col2:enlist"test";Col3:enlist "test")
^
q)Tab: ([Key1:()] Col1:();Col2:();Col3:())
q)Tab upsert ([Key1:enlist"test"] Col1:enlist"test";Col2:enlist"test";Col3:enlist "test")
Key1 | Col1 Col2 Col3
------| --------------------
"test"| "test" "test" "test"
KDB 在创建 table 期间不允许将列类型定义为列表。所以这意味着您不能将列类型定义为 String,因为它也是一个列表。
唯一的方法是将列定义为空列表,如:
q) t:([]id:`int$();val:())
然后当您向此 table 插入数据时,该列将自动采用该数据的类型。
q)`t insert (4;"row1")
q) meta t
c | t f a
---| -----
id | i
val| C
在您的情况下,一种选择是按照用户 'emc211' 所述从您的 Java 进程发送字符串数据,或者其他选择是在插入之前将您的数据转换为 KDB 进程中的字符串。
当我创建 table 选项卡时,我将列指定为字符串,
Tab: ([Key1:string()] Col1:string();Col2:string();Col3:string())
但是列数据类型 (t) 为空。我想将列指定为字符串无效。
meta Tab
c t f a
--------------------
Key1
Col1
Col2
Col3
在 Java 中进行批量更新后...
c.Dict dict = new c.Dict((Object[]) columns.toArray(new String[columns.size()]), data);
c.Flip flip = new c.Flip(dict);
conn.c.ks("upsert", table, flip);
数据类型均为符号:
meta Tab
c t f a
--------------------
Key1 s
Col1 s
Col2 s
Col3 s
如何将列的数据类型指定为字符串并使其保持为字符串?
您不能用字符串定义空列 table,因为它们只是字符列表的列表
您可以将它们设置为空列表,这就是您的代码所做的。
但是该列将采用插入其中的任何数据的类型。
真正的问题是您的 java 进程在应该发送字符串时发送符号。在发布到 KDB
之前,您需要在那里进行更改请注意,如果您定义为字符,您仍然无法插入字符串
q)Tab: ([Key1:`char$()] Col1:`char$();Col2:`char$();Col3:`char$())
q)Tab upsert ([Key1:enlist"test"] Col1:enlist"test";Col2:enlist"test";Col3:enlist "test")
'rank
[0] Tab upsert ([Key1:enlist"test"] Col1:enlist"test";Col2:enlist"test";Col3:enlist "test")
^
q)Tab: ([Key1:()] Col1:();Col2:();Col3:())
q)Tab upsert ([Key1:enlist"test"] Col1:enlist"test";Col2:enlist"test";Col3:enlist "test")
Key1 | Col1 Col2 Col3
------| --------------------
"test"| "test" "test" "test"
KDB 在创建 table 期间不允许将列类型定义为列表。所以这意味着您不能将列类型定义为 String,因为它也是一个列表。
唯一的方法是将列定义为空列表,如:
q) t:([]id:`int$();val:())
然后当您向此 table 插入数据时,该列将自动采用该数据的类型。
q)`t insert (4;"row1")
q) meta t
c | t f a
---| -----
id | i
val| C
在您的情况下,一种选择是按照用户 'emc211' 所述从您的 Java 进程发送字符串数据,或者其他选择是在插入之前将您的数据转换为 KDB 进程中的字符串。