我创建了一个已注册的自定义 udf,但是当我尝试选择 custom_udf(10) 时出现以下错误:
Exact implementation of BasicPlatform do not match expected java types
这是我的 udf,我似乎无法弄清楚它有什么问题: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);
}
Run Code Online (Sandbox Code Playgroud)
}
有什么明显的错误吗?我希望它返回一个字符串,给定一个 int 作为参数,我认为 java 和 sql 类型匹配 (Integer -> Integer), (Slice -> varchar)。
谢谢
在presto-users上也提出并回答了这个问题:
您必须使用@SqlNullable @SqlType(StandardTypes.INTEGER) Long id(因为 SQLinteger由LongJava支持)。