mdayakar commented on code in PR #5084:
URL: https://github.com/apache/hive/pull/5084#discussion_r1502687819


##########
hplsql/src/main/java/org/apache/hive/hplsql/functions/InMemoryFunctionRegistry.java:
##########
@@ -132,39 +133,84 @@ private boolean execProc(String name, 
HplsqlParser.Expr_func_paramsContext ctx)
   /**
    * Set parameters for user-defined function call
    */
-  public static void setCallParameters(String procName, 
HplsqlParser.Expr_func_paramsContext actual, ArrayList<Var> actualValues,
-                         HplsqlParser.Create_routine_paramsContext formal,
-                         HashMap<String, Var> out,
-                         Exec exec) {
-    if (actual == null || actual.func_param() == null || actualValues == null) 
{
+  public static void setCallParameters(String procName, 
HplsqlParser.Expr_func_paramsContext actual,
+      ArrayList<Var> actualValues, HplsqlParser.Create_routine_paramsContext 
formal, HashMap<String, Var> out,
+      Exec exec) {
+    // if it is a non-parameter function then just return.
+    if (actual == null && formal == null) {
       return;
     }
-    int actualCnt = actualValues.size();
-    int formalCnt = formal.create_routine_param_item().size();
-    if (formalCnt != actualCnt) {
-      throw new ArityException(actual.getParent(), procName, formalCnt, 
actualCnt);
+    int actualCnt = (actualValues == null) ? 0 : actualValues.size();
+    int passedParamCnt = actualCnt;
+    List<HplsqlParser.Create_routine_param_itemContext> routineParamItem = 
formal.create_routine_param_item();
+    int formalCnt = routineParamItem.size();
+    ParserRuleContext ruleContext = (actual == null) ? null : 
actual.getParent();
+    if (actualCnt > formalCnt) {
+      throw new ArityException(ruleContext, procName, formalCnt, actualCnt);
     }
-    for (int i = 0; i < actualCnt; i++) {
-      HplsqlParser.ExprContext a = actual.func_param(i).expr(); 
-      HplsqlParser.Create_routine_param_itemContext p = 
getCallParameter(actual, formal, i);
-      String name = p.ident().getText();
-      String type = p.dtype().getText();
-      String len = null;
-      String scale = null;   
-      if (p.dtype_len() != null) {
-        len = p.dtype_len().L_INT(0).getText();
-        if (p.dtype_len().L_INT(1) != null) {
-          scale = p.dtype_len().L_INT(1).getText();
-        }
+    Map<String, Integer> defaultParamNamesVsIndexes = new HashMap<>();
+    if (actualCnt != formalCnt) {
+      populateDefaultParamDetails(routineParamItem, formalCnt, 
defaultParamNamesVsIndexes);

Review Comment:
   Yes it can be done that way also but here it is done above way to avoid 
NullPointerException as map is populated only `if (actualCnt != formalCnt)` 
condition satisfies. In the code flow we are using the map to have some checks 
otherwise there we need to add null check again. So first initializing the map 
and passing the same map to `populateDefaultParamDetails ()` API to populate 
the values. If there are no default params then this map will not be populated.



-- 
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-unsubscr...@hive.apache.org

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


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

Reply via email to