问题
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