上部功能不适用于KDB中的Latin-2字符

问题描述 投票:0回答:1

我正在尝试在包含非英语字符的列上运行upper:áéőí

q)t:([] nm: (`as;`$"áb"))
q)t
nm 
---
as 
áb
q)update upper_nm: upper nm from t
nm  upper_nm
------------
as  AS      
áb áB     

我发现了使用系统调用python的解决方法,但比内置函数慢得多:

q)upper_py: {`$ system "python -c \"print(\\\"",string[x],"\\\".upper())\""}
q)update upper_nm: upper_py'[nm] from t
nm  upper_nm
------------
as  AS      
áb ÁB  

应该有一个更好,更快的方法。

kdb
1个回答
0
投票

我认为Q中没有内置的支持此类字符的upper函数。

最干净的方法是到bind it from .so,但是这种方法有点麻烦

我会通过将字符串列表传递给python并将结果解析到Q-list来加快您的处理速度。这样可以防止对每个字符串进行系统调用:

t: ([] nm: (`as;`$"áb"));
toPythonList: {"[",("," sv "'",'x,'"'"),"]"};
pythonUpper: {system "python -c \"print([x.upper() for x in ",x,"])\""};
toQList: {-1_'1_'", " vs -1_1_x};
customUpper: {toQList first pythonUpper toPythonList x};
update upper_nm: customUpper string nm from t
© www.soinside.com 2019 - 2024. All rights reserved.