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

三世轮回 提交于 2021-01-29 05:29:19

问题


I have writeen code like belo but getting error as below:-

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);        
$$

回答1:


Create UDF syntax:

 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;
}      
';


来源:https://stackoverflow.com/questions/53879218/date-column-which-is-a-text-type-in-cassandra-so-i-need-a-udf-to-convert-that-te

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!