upper function not working for Latin-2 characters in KDB

Viewed 75

I'm trying to run upper on a column that contains non-English characters: áéőí

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     

I found a workaround using a system call to python but is much slower than the built-in function:

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  

There should be a nicer, faster way to do this.

1 Answers

I don't think there is any built-in upper function in Q which supports such characters.

The cleanest way to get it is to bind it from .so But this approach is a bit of hassle

I would speed up you approach by passing list of string to python and parsing outcome to Q-list. This would prevent from calling system for every string:

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
Related