日期列,它是Cassandra ..中的文本类型,因此我需要UDF将文本转换为时间戳,以便可以在该列上查询 [英] date column which is a text type in Cassandra.so I need a UDF to convert that text to timestamp so I can query on that column
本文介绍了日期列,它是Cassandra ..中的文本类型,因此我需要UDF将文本转换为时间戳,以便可以在该列上查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经编写了类似belo的代码,但出现如下错误:-
I have writeen code like belo but getting error as below:-
InvalidRequest:服务器错误:code = 2200 [Invalid query] message ="Java源代码编译失败:第1行:java.util.String无法解析为类型第1行:令牌"Date"上的语法错误,@预期的第4行:SimpleDateFormat无法解析为类型
InvalidRequest: Error from server: code=2200 [Invalid query] message="Java source compilation failed: Line 1: java.util.String cannot be resolved to a type Line 1: Syntax error on token "Date", @ expected Line 4: SimpleDateFormat cannot be resolved to a type
CREATE FUNCTION saumya.text2dt ( input text )
RETURNS NULL ON NULL INPUT
RETURNS timestamp
LANGUAGE java
AS $$
java.text.ParseException
java.text.SimpleDateFormat
java.util.Date
String ms = input;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date date = sdf.parse(ms);
return sdf.format(date);
$$
推荐答案
创建UDF语法:
CREATE FUNCTION text2dt ( input text )
RETURNS NULL ON NULL INPUT
RETURNS timestamp
LANGUAGE java
AS '
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
try{
java.util.Date date = sdf.parse(input);
return date;
}catch(Exception e){
return null;
}
';
这篇关于日期列,它是Cassandra ..中的文本类型,因此我需要UDF将文本转换为时间戳,以便可以在该列上查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文