Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-15849

hplsql should add enterGlobalScope func to UDF

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.2.0
    • 2.3.0
    • hpl/sql
    • None

    Description

      code in Udf.java

      Udf.java
          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();
          }
      

      Here is my thoughts

      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

      Before add this function, the result as follow. we get the wrong result, because the result contains empty string

      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, !

      After add this function, we get the right result

      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!

      tests come from http://www.hplsql.org/udf

      Attachments

        1. HIVE-15849.1.patch
          3 kB
          Hui Fei
        2. HIVE-15849.patch
          0.6 kB
          Hui Fei

        Activity

          People

            ferhui Hui Fei
            ferhui Hui Fei
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: