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 == null) ? 0 : actualValues.size();
    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);
    }
    Map<String, Integer> defaultParamNamesVsIndexes = new HashMap<>();
    if (actualCnt != formalCnt) {
      populateDefaultParamDetails(routineParamItem, defaultParamNamesVsIndexes);
    }

    // set the passed params
    for (int i = 0; i < actualCnt; i++) {
      HplsqlParser.ExprContext exprContext = actual.func_param(i).expr();
      HplsqlParser.Create_routine_param_itemContext paramItemContext = getCallParameter(actual, formal, i);
      Var value = actualValues.get(i);
      // for any default param value is passed then remove it from default param list
      defaultParamNamesVsIndexes.remove(paramItemContext.ident().getText());
      setCallParameter(actual, out, exec, exprContext, paramItemContext, value);
    }
    // set the remaining default params
    for (int index : defaultParamNamesVsIndexes.values()) {
      HplsqlParser.Create_routine_param_itemContext paramItemContext = formal.create_routine_param_item().get(index);
      HplsqlParser.ExprContext exprContext = paramItemContext.dtype_default().expr();
      Var value = exec.evalPop(paramItemContext.dtype_default().expr());
      setCallParameter(actual, out, exec, exprContext, paramItemContext, value);
    }
    // if actual param count + remaining default param count is lesser than formal param count then throw exception as some params are missing
    if ((actualCnt + defaultParamNamesVsIndexes.size()) != formalCnt) {
      throw new ArityException(ruleContext, procName, formalCnt, actualCnt);
    }
  }
Set parameters for user-defined function call
hplsql/src/main/java/org/apache/hive/hplsql/functions/InMemoryFunctionRegistry.java