2017-02-28 55 views
0

我跟着this教程和槓桿this github項目,並寫了一個簡單的'mysum'UDF函數。將UDF功能插入Presto的步驟是什麼?

@ScalarFunction("mysum") 
@Description("Returns summation of two numbers") 
@SqlType(StandardTypes.BIGINT) 
public static long sum(@SqlType(StandardTypes.BIGINT) long num1, @SqlType(StandardTypes.BIGINT) long num2) 
{ 
    return num1 + num2; 
} 

我也跟着下面的步驟,以插件的UDF但普雷斯托無法導入該功能。 因爲,關於編寫和插入UDF的文檔很少,所以不勝感激。提前致謝。

  1. mvn compilemvn package
  2. 複製.jar文件到plugins文件夾下的急板(未壓縮)目錄/Users/nithin/presto-server-0.166/plugin/udfs/
  3. 開始使用bin/launcher run 在普雷斯托CLI跑select mysum(10,100)協調,但會拋出錯誤

當我嘗試在Presto CLI中運行我的UDF('mysum')時,下面是錯誤日誌。 很明顯,Presto無法找到UDF,因此插入不成功。如何解決這個問題?我錯過了任何一步嗎?

➜ Workspaces ./presto.jar --server localhost:8080 --catalog mysql --schema default --debug 
presto:default> select mysum(99,100); 
Query 20170228_183509_00002_vr5dt failed: line 1:8: Function mysum not registered 
com.facebook.presto.sql.analyzer.SemanticException: line 1:8: Function mysum not registered 
    at com.facebook.presto.sql.analyzer.ExpressionAnalyzer$Visitor.visitFunctionCall(ExpressionAnalyzer.java:824) 
    at com.facebook.presto.sql.analyzer.ExpressionAnalyzer$Visitor.visitFunctionCall(ExpressionAnalyzer.java:255) 
    at com.facebook.presto.sql.tree.FunctionCall.accept(FunctionCall.java:111) 
    at com.facebook.presto.sql.tree.StackableAstVisitor.process(StackableAstVisitor.java:26) 
    at com.facebook.presto.sql.analyzer.ExpressionAnalyzer$Visitor.process(ExpressionAnalyzer.java:274) 
    at com.facebook.presto.sql.analyzer.ExpressionAnalyzer.analyze(ExpressionAnalyzer.java:231) 
    at com.facebook.presto.sql.analyzer.ExpressionAnalyzer.analyzeExpression(ExpressionAnalyzer.java:1406) 
    at com.facebook.presto.sql.analyzer.StatementAnalyzer.analyzeExpression(StatementAnalyzer.java:1802) 
    at com.facebook.presto.sql.analyzer.StatementAnalyzer.analyzeSelect(StatementAnalyzer.java:1623) 
    at com.facebook.presto.sql.analyzer.StatementAnalyzer.visitQuerySpecification(StatementAnalyzer.java:800) 
    at com.facebook.presto.sql.analyzer.StatementAnalyzer.visitQuerySpecification(StatementAnalyzer.java:188) 
    at com.facebook.presto.sql.tree.QuerySpecification.accept(QuerySpecification.java:127) 
    at com.facebook.presto.sql.tree.AstVisitor.process(AstVisitor.java:27) 
    at com.facebook.presto.sql.analyzer.StatementAnalyzer.visitQuery(StatementAnalyzer.java:550) 
    at com.facebook.presto.sql.analyzer.StatementAnalyzer.visitQuery(StatementAnalyzer.java:188) 
    at com.facebook.presto.sql.tree.Query.accept(Query.java:94) 
    at com.facebook.presto.sql.tree.AstVisitor.process(AstVisitor.java:27) 
    at com.facebook.presto.sql.analyzer.Analyzer.analyze(Analyzer.java:68) 
    at com.facebook.presto.sql.analyzer.Analyzer.analyze(Analyzer.java:60) 
    at com.facebook.presto.execution.SqlQueryExecution.doAnalyzeQuery(SqlQueryExecution.java:290) 
    at com.facebook.presto.execution.SqlQueryExecution.analyzeQuery(SqlQueryExecution.java:276) 
    at com.facebook.presto.execution.SqlQueryExecution.start(SqlQueryExecution.java:234) 
    at com.facebook.presto.execution.QueuedExecution.lambda$start$1(QueuedExecution.java:63) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
select mysum(99,100) 

回答

0

你的連接器插件應該提供UDF類的列表。見Plugin#getFunctions

default Set<Class<?>> getFunctions() 
{ 
    return emptySet(); 
} 

請覆蓋的方法,揭露UDF類的類。