Coordinated change for CREATE FUNCTION w/ UDFs

Change-Id: I50cff0948dad342f0d2e5b5250e3247bfd6fcd0d
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateProcedureStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateProcedureStatement.java
index fba4aea..1d38597 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateProcedureStatement.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateProcedureStatement.java
@@ -190,13 +190,18 @@
                     getProcedureBodyStatement(), hcc, null, ResultDelivery.ASYNC, null, stats, true, null, null, null),
                     PrecompiledType.INSERT);
         } else if (getProcedureBodyStatement().getKind() == Statement.Kind.QUERY) {
+            //TODO: Fix type dependency computation
             SqlppRewriterFactory fact = new SqlppRewriterFactory();
-            dependencies.get(1).addAll(FunctionUtil.getFunctionDependencies(fact.createQueryRewriter(),
-                    ((Query) getProcedureBodyStatement()).getBody(), metadataProvider).get(1));
+            dependencies.get(1)
+                    .addAll(FunctionUtil.getFunctionDependencies(fact.createQueryRewriter(),
+                            ((Query) getProcedureBodyStatement()).getBody(), metadataProvider, new ArrayList<>())
+                            .get(1));
             Pair<JobSpecification, PrecompiledType> pair = new Pair<>(BADJobService.compileQueryJob(statementExecutor,
                     metadataProvider, hcc, (Query) getProcedureBodyStatement()), PrecompiledType.QUERY);
-            dependencies.get(0).addAll(FunctionUtil.getFunctionDependencies(fact.createQueryRewriter(),
-                    ((Query) getProcedureBodyStatement()).getBody(), metadataProvider).get(0));
+            dependencies.get(0)
+                    .addAll(FunctionUtil.getFunctionDependencies(fact.createQueryRewriter(),
+                            ((Query) getProcedureBodyStatement()).getBody(), metadataProvider, new ArrayList<>())
+                            .get(0));
             return pair;
         } else if (getProcedureBodyStatement().getKind() == Statement.Kind.DELETE) {
             getProcedureBodyStatement().accept(SqlppDeleteRewriteVisitor.INSTANCE, metadataProvider);
@@ -204,7 +209,7 @@
 
             SqlppRewriterFactory fact = new SqlppRewriterFactory();
             dependencies = FunctionUtil.getFunctionDependencies(fact.createQueryRewriter(), delete.getQuery().getBody(),
-                    metadataProvider);
+                    metadataProvider, new ArrayList<>());
             Pair<JobSpecification, PrecompiledType> pair =
                     new Pair<>(((QueryTranslator) statementExecutor).handleDeleteStatement(metadataProvider,
                             getProcedureBodyStatement(), hcc, true, null, null), PrecompiledType.DELETE);
diff --git a/asterix-bad/src/main/resources/lang-extension/lang.txt b/asterix-bad/src/main/resources/lang-extension/lang.txt
index 1c729a7..3cc4b7b 100644
--- a/asterix-bad/src/main/resources/lang-extension/lang.txt
+++ b/asterix-bad/src/main/resources/lang-extension/lang.txt
@@ -120,7 +120,7 @@
 {
   FunctionName fctName = null;
   FunctionSignature signature;
-  List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
+  List<Pair<VarIdentifier,IndexedTypeExpression>> paramList = new ArrayList<Pair<VarIdentifier,IndexedTypeExpression>>();
   List<Integer> paramIds = new ArrayList<Integer>();
   String functionBody;
   Token beginPos;
@@ -135,12 +135,12 @@
      {
         defaultDataverse = fctName.dataverse;
      }
-     paramList = ParameterList()
+     paramList = FunctionParameters()
     <LEFTBRACE>
   {
-    for (VarIdentifier param : paramList)
+    for (Pair<VarIdentifier,IndexedTypeExpression> param : paramList)
     {
-      VarIdentifier v = new VarIdentifier(param.toString());
+      VarIdentifier v = new VarIdentifier(param.getFirst().toString());
       getCurrentScope().addNewVarSymbolToScope(v);
       paramIds.add(v.getId());
     }
@@ -156,7 +156,11 @@
     }
   ("period" period = FunctionCallExpr())?
   {
-  return new CreateProcedureStatement(signature, paramList, paramIds, functionBody, period);
+  List<VarIdentifier> paramListVariablesOnly = new ArrayList<VarIdentifier>();
+  for(Pair<VarIdentifier,IndexedTypeExpression> p: paramList){
+    paramListVariablesOnly.add(p.first);
+  }
+  return new CreateProcedureStatement(signature, paramListVariablesOnly, paramIds, functionBody, period);
   }
 }
 
diff --git a/asterix-bad/src/test/resources/runtimets/results/procedure/create_procedure_check_metadata/create_procedure_check_metadata.1.adm b/asterix-bad/src/test/resources/runtimets/results/procedure/create_procedure_check_metadata/create_procedure_check_metadata.1.adm
index 4753113..461cc14 100644
--- a/asterix-bad/src/test/resources/runtimets/results/procedure/create_procedure_check_metadata/create_procedure_check_metadata.1.adm
+++ b/asterix-bad/src/test/resources/runtimets/results/procedure/create_procedure_check_metadata/create_procedure_check_metadata.1.adm
@@ -1,6 +1,6 @@
 { "DataverseName": "two", "ProcedureName": "addMe", "Arity": "0", "Params": [  ], "Type": "INSERT", "Definition": "use `two`;\ninsert into channels.UserLocations([\n    {\"timeStamp\":current_datetime(), \"roomNumber\":222}]\n  );", "Language": "SQLPP", "Duration": "", "Dependencies": [ [ [ "channels", "UserLocations" ] ], [  ] ] }
-{ "DataverseName": "two", "ProcedureName": "deleteSome", "Arity": "2", "Params": [ "r", "otherRoom" ], "Type": "DELETE", "Definition": "use `two`;\ndelete from channels.UserLocations\nwhere roomNumber = get_job_param(\"r\")\nor roomNumber = get_job_param(\"otherRoom\")\nand channels.really_contains(roomNumber,\"l\");", "Language": "SQLPP", "Duration": "", "Dependencies": [ [ [ "channels", "UserLocations" ] ], [ [ "two", "get_job_param", "1" ], [ "channels", "really_contains", "2" ], [ "two", "get_job_param", "1" ] ] ] }
+{ "DataverseName": "two", "ProcedureName": "deleteSome", "Arity": "2", "Params": [ "r", "otherRoom" ], "Type": "DELETE", "Definition": "use `two`;\ndelete from channels.UserLocations\nwhere roomNumber = get_job_param(\"r\")\nor roomNumber = get_job_param(\"otherRoom\")\nand channels.really_contains(roomNumber,\"l\");", "Language": "SQLPP", "Duration": "", "Dependencies": [ [ [ "channels", "UserLocations" ] ], [ [ "two", "get_job_param", "1" ], [ "channels", "really_contains", "2" ], [ "two", "get_job_param", "1" ] ], [  ] ] }
 { "DataverseName": "two", "ProcedureName": "localAddMe", "Arity": "0", "Params": [  ], "Type": "INSERT", "Definition": "use `two`;\ninsert into UserLocations([\n    {\"timeStamp\":current_datetime(), \"roomNumber\":222}]\n  );", "Language": "SQLPP", "Duration": "", "Dependencies": [ [ [ "two", "UserLocations" ] ], [  ] ] }
-{ "DataverseName": "two", "ProcedureName": "localDeleteSome", "Arity": "2", "Params": [ "r", "otherRoom" ], "Type": "DELETE", "Definition": "use `two`;\ndelete from UserLocations\nwhere roomNumber = get_job_param(\"r\")\nor roomNumber = get_job_param(\"otherRoom\")\nand really_contains(roomNumber,\"l\");", "Language": "SQLPP", "Duration": "", "Dependencies": [ [ [ "two", "UserLocations" ] ], [ [ "two", "get_job_param", "1" ], [ "two", "really_contains", "2" ], [ "two", "get_job_param", "1" ] ] ] }
+{ "DataverseName": "two", "ProcedureName": "localDeleteSome", "Arity": "2", "Params": [ "r", "otherRoom" ], "Type": "DELETE", "Definition": "use `two`;\ndelete from UserLocations\nwhere roomNumber = get_job_param(\"r\")\nor roomNumber = get_job_param(\"otherRoom\")\nand really_contains(roomNumber,\"l\");", "Language": "SQLPP", "Duration": "", "Dependencies": [ [ [ "two", "UserLocations" ] ], [ [ "two", "get_job_param", "1" ], [ "two", "really_contains", "2" ], [ "two", "get_job_param", "1" ] ], [  ] ] }
 { "DataverseName": "two", "ProcedureName": "localSelectSome", "Arity": "2", "Params": [ "r", "otherRoom" ], "Type": "QUERY", "Definition": "use `two`;\nselect roomNumber from UserLocations\nwhere roomNumber = get_job_param(\"r\")\nor roomNumber = get_job_param(\"otherRoom\")\nand really_contains(roomNumber,\"l\")\norder by id;", "Language": "SQLPP", "Duration": "", "Dependencies": [ [ [ "two", "UserLocations" ] ], [ [ "two", "get_job_param", "1" ], [ "two", "really_contains", "2" ], [ "two", "get_job_param", "1" ] ] ] }
-{ "DataverseName": "two", "ProcedureName": "selectSome", "Arity": "2", "Params": [ "r", "otherRoom" ], "Type": "QUERY", "Definition": "use `two`;\nselect roomNumber from channels.UserLocations\nwhere roomNumber = get_job_param(\"r\")\nor roomNumber = get_job_param(\"otherRoom\")\nand channels.really_contains(roomNumber,\"l\")\norder by id;", "Language": "SQLPP", "Duration": "", "Dependencies": [ [ [ "channels", "UserLocations" ] ], [ [ "two", "get_job_param", "1" ], [ "channels", "really_contains", "2" ], [ "two", "get_job_param", "1" ] ] ] }
\ No newline at end of file
+{ "DataverseName": "two", "ProcedureName": "selectSome", "Arity": "2", "Params": [ "r", "otherRoom" ], "Type": "QUERY", "Definition": "use `two`;\nselect roomNumber from channels.UserLocations\nwhere roomNumber = get_job_param(\"r\")\nor roomNumber = get_job_param(\"otherRoom\")\nand channels.really_contains(roomNumber,\"l\")\norder by id;", "Language": "SQLPP", "Duration": "", "Dependencies": [ [ [ "channels", "UserLocations" ] ], [ [ "two", "get_job_param", "1" ], [ "channels", "really_contains", "2" ], [ "two", "get_job_param", "1" ] ] ] }