Reputation: 1228
I've created a custom udf that is registered but when I try to select custom_udf(10) I get the following error:
Exact implementation of BasicPlatform do not match expected java types
Here is my udf, I can't seem to figure out what is wrong with it:
public class ScalarUdfs {
private ScalarUdfs() {};
@ScalarFunction("basic_platform")
@SqlType(StandardTypes.VARCHAR)
public static Slice BasicPlatform(@SqlNullable @SqlType(StandardTypes.INTEGER) Integer id) {
final Slice IOS = Slices.utf8Slice("iOS");
final Slice ANDROID = Slices.utf8Slice("Android");
final Slice WEB = Slices.utf8Slice("Web");
final Slice OTHER = Slices.utf8Slice("Other");
final Map<Integer, Slice> PLATFORM_MAP = new HashMap<Integer, Slice>() {{
put(20, IOS);
put(42, ANDROID);
put(100, WEB);
}};
if (id == null || !PLATFORM_MAP.containsKey(id)) {
return OTHER;
}
return PLATFORM_MAP.get(id);
}
}
Does anything seem obviously wrong? I want it to return a string given an int as a parameter, and I think the java and sql types match (Integer -> Integer), (Slice -> varchar).
Thanks
Upvotes: 5
Views: 1962
Reputation: 20770
The question was also asked and answered on presto-users:
You have to use @SqlNullable @SqlType(StandardTypes.INTEGER) Long id
(as SQL integer
is backed by Long
in Java).
Upvotes: 6