You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "soumyakanti3578 (via GitHub)" <gi...@apache.org> on 2023/05/18 21:43:16 UTC

[GitHub] [hive] soumyakanti3578 commented on a diff in pull request #4330: HIVE-27349: Move HMS call to get stored procedure out of Udf

soumyakanti3578 commented on code in PR #4330:
URL: https://github.com/apache/hive/pull/4330#discussion_r1198334021


##########
hplsql/src/main/java/org/apache/hive/hplsql/udf/Udf.java:
##########
@@ -66,48 +64,23 @@ public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumen
     if (!(arguments[0] instanceof StringObjectInspector)) {
       throw new UDFArgumentException("First argument must be a string");
     }
-    SessionState sessionState = SessionState.get();
-    if (sessionState != null) {
-      // we are still in HiveServer, get the source of the HplSQL function and store it.
-      functionDefinition = loadSource(sessionState, functionName(arguments[0]));
-    }
     queryOI = (StringObjectInspector)arguments[0];
+    funcDefOI = (StringObjectInspector)arguments[arguments.length-1];
     argumentsOI = arguments;
     return PrimitiveObjectInspectorFactory.javaStringObjectInspector;
   }
 
-  protected String loadSource(SessionState sessionState, String functionName) throws UDFArgumentException {
-    Exec exec = sessionState.getDynamicVar(Exec.class);
-    try {
-      StoredProcedure storedProcedure = exec.getMsc().getStoredProcedure(
-              new StoredProcedureRequest(
-                      SessionState.get().getCurrentCatalog(),
-                      SessionState.get().getCurrentDatabase(),
-                      functionName));
-      return storedProcedure != null ? storedProcedure.getSource() : null;
-    } catch (TException e) {
-      throw new UDFArgumentException(e);
-    }
-  }
-
-  protected String functionName(ObjectInspector argument) {
-    ConstantObjectInspector inspector = (ConstantObjectInspector) (argument);
-    String functionCall = inspector.getWritableConstantValue().toString();
-    return functionCall.split("\\(")[0].toUpperCase();
-  }
-
   /**
    * Execute UDF
    */
   @Override
   public Object evaluate(DeferredObject[] arguments) throws HiveException {
-    if (exec == null) {
-      exec = new Exec();

Review Comment:
   Yeah, it was mostly because it looks odd init-ing Exec in `evaluate` method. It was getting initialized only once anyway, so it's better to move it to the constructor of Udf.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org