[ https://issues.apache.org/jira/browse/HIVE-15849?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Fei Hui updated HIVE-15849: --------------------------- Attachment: HIVE-15849.1.patch patch update with ut affter apply this patch, get the right result {quote} hive> add jar /usr/lib/hive-current/lib/antlr-runtime-4.5.jar; Added [/usr/lib/hive-current/lib/antlr-runtime-4.5.jar] to class path Added resources: [/usr/lib/hive-current/lib/antlr-runtime-4.5.jar] hive> add jar /usr/lib/hive-current/lib/hplsql.jar; Added [/usr/lib/hive-current/lib/hplsql.jar] to class path Added resources: [/usr/lib/hive-current/lib/hplsql.jar] hive> add file hplsqlrc; Added resources: [hplsqlrc] hive> CREATE TEMPORARY FUNCTION hplsql AS 'org.apache.hive.hplsql.Udf'; OK Time taken: 0.023 seconds hive> SELECT hplsql('hello(:1)', name) FROM users; OK Configuration file: file:/etc/emr/hive-conf-2.0.1/hplsql-site.xml Parser tree: (program (block (stmt (expr_stmt (expr (expr_func (ident hello) ( (expr_func_params (func_param (expr (expr_atom (ident :1))))) ))))))) INLCUDE CONTENT hplsqlrc (non-empty) Ln:1 CREATE FUNCTION hello Ln:1 EXEC FUNCTION hello Ln:1 SET PARAM text = fei Ln:4 RETURN Hello, fei! Time taken: 0.653 seconds, Fetched: 1 row(s) {quote} > hplsql should add enterGlobalScope func to UDF > ---------------------------------------------- > > Key: HIVE-15849 > URL: https://issues.apache.org/jira/browse/HIVE-15849 > Project: Hive > Issue Type: Bug > Components: hpl/sql > Affects Versions: 2.2.0 > Reporter: Fei Hui > Assignee: Fei Hui > Attachments: HIVE-15849.1.patch, HIVE-15849.patch > > > code in Udf.java > {code:title=Udf.java|borderStyle=solid} > if (exec == null) { > exec = new Exec(); > String query = queryOI.getPrimitiveJavaObject(arguments[0].get()); > String[] args = { "-e", query, "-trace" }; > try { > exec.setUdfRun(true); > exec.init(args); > } catch (Exception e) { > throw new HiveException(e.getMessage()); > } > } > if (arguments.length > 1) { > setParameters(arguments); > } > Var result = exec.run(); > if (result != null) { > return result.toString(); > } > {code} > Here is my thoughts > {quote} > we should add 'exec.enterGlobalScope(); ' between 'exec = new Exec();' and > 'setParameters(arguments);' > Because if we do not call exec.enterGlobalScope(), setParameters(arguments) > will useless. Vars are not added into scope , but exec.run() will use vars > which we set. The vars are parameters passed to UDF, [, :1, :2, ...n] which > are description in Udf.java > {quote} > Before add this function, the result as follow. we get the wrong result, > because the result contains empty string > {quote} > Starting pre-SQL statement > Starting pre-SQL statement > Starting pre-SQL statement > Starting pre-SQL statement > Starting pre-SQL statement > Starting query > Query executed successfully (2.30 sec) > Ln:8 SELECT completed successfully > Ln:8 Standalone SELECT executed: 1 columns in the result set > Hello, ! > Hello, ! > {quote} > After add this function, we get the right result > {quote} > Starting pre-SQL statement > Starting pre-SQL statement > Starting pre-SQL statement > Starting pre-SQL statement > Starting pre-SQL statement > Starting query > Query executed successfully (2.35 sec) > Ln:8 SELECT completed successfully > Ln:8 Standalone SELECT executed: 1 columns in the result set > Hello, fei! > Hello, fei! > {quote} > tests come from http://www.hplsql.org/udf -- This message was sent by Atlassian JIRA (v6.3.15#6346)