Cassandra查询字符串长度 [英] Cassandra query string length

查看:314
本文介绍了Cassandra查询字符串长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Cassandra中获取字符串的长度?似乎没有任何内置函数可以为我执行此操作。

How can I get the length of a string in Cassandra? There don't seem to be any built-in functions to do this for me.

正在寻找类似这样的内容:

Looking for something like this:

SELECT size(myStr) FROM myTable WHERE ...

我知道可以使用用户定义的函数来实现,但是我不确定是否具有创建函数的适当权限。

I know this may be possible using user-defined functions, but I'm not sure if I have the appropriate permissions to be able to create functions.

推荐答案

没有内置函数,但是可以在Cassandra中创建 UDF 来查找String列的长度,然后使用该 UDF 。在创建此UDF之前,请确保已在 cassandra.yml 文件中启用udf属性,即 enable_user_defined_functions:true

There is no inbuilt function for it but you can create UDF in Cassandra to find the length of the String column and then use that UDF in your query. Before creating this UDF make sure you have enabled udf property in your cassandra.yml file i.e. enable_user_defined_functions: true

CREATE FUNCTION IF NOT EXISTS len (input text) 
   CALLED ON NULL INPUT 
   RETURNS int 
   LANGUAGE java AS '
   return input.length();';

然后您可以在查询中使用它,

Then you can use it in your query as,

cqlsh:test> SELECT len(event_data) as length from event where id = 1;

您应该得到输出,

 length
--------
     14

这篇关于Cassandra查询字符串长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆