committing additional tests covering user defined functions

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization@872 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf01.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf01.aql
new file mode 100644
index 0000000..35718b1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf01.aql
@@ -0,0 +1,18 @@
+/*
+ * Description  : Pass an ordered list as input to UDF
+ *              : and return that ordered list.
+ * Expected Res : Success
+ * Date         : 4th September 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf01.adm";
+
+create function test.echo($list){
+$list
+}
+
+for $a in [1,2,3,4,5,6,7,8,9,10]
+return test.echo($a)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf02.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf02.aql
new file mode 100644
index 0000000..2605f7a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf02.aql
@@ -0,0 +1,17 @@
+/*
+ * Description  : Pass an ordered list as input to UDF and return the zeroth element of that list.
+ * Expected Res : Success
+ * Date         : 4th September 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf02.adm";
+
+create function test.getFirst($list){
+$list[0]
+}
+
+for $a in [[1,2],[3,4]]
+return test.getFirst($a)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf03.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf03.aql
new file mode 100644
index 0000000..747f29d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf03.aql
@@ -0,0 +1,20 @@
+/*
+ * Description  : Pass an ordered list as input to UDF and return the zeroth element of that list.
+ * Expected Res : Success
+ * Date         : 4th September 2012
+ * Ignored      : Not part of test build due to Issue 200
+ */
+
+// This test is returning NPE... Issue 200 
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf03.adm";
+
+create function test.echo($list){
+$list
+}
+
+for $a in [[1,2],["A","B"],["UCLA","UCSD","UCR","UCI"]]
+return test.echo($a)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf04.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf04.aql
new file mode 100644
index 0000000..bd6544f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf04.aql
@@ -0,0 +1,17 @@
+/*
+ * Description  : Pass as input an ordered list of Records as input to UDF and return the list.
+ * Expected Res : Success
+ * Date         : 4th September 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf04.adm";
+
+create function test.echo($list){
+$list
+}
+
+for $a in [{"name":"John","age":45,"id":123},{"name":"Jim","age":55,"id":103},{"name":"Bill","age":35,"id":125}]
+return test.echo($a)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf05.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf05.aql
new file mode 100644
index 0000000..2429f1c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf05.aql
@@ -0,0 +1,17 @@
+/*
+ * Description  : Create UDF and bind its return value to a variable and return that variable
+ * Expected Res : Success
+ * Date         : Sep 4th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf05.adm";
+
+create function test.echo($a){
+$a
+}
+
+let $b:=1234
+return test.echo($b)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf06.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf06.aql
new file mode 100644
index 0000000..3301d5c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf06.aql
@@ -0,0 +1,17 @@
+/*
+ * Description  : Pass input of type double to UDF
+ * Expected Res : Success
+ * Date         : 4th September 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf06.adm";
+
+create function test.echo($a){
+$a
+}
+
+let $b:=1234.1
+return test.echo($b)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf07.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf07.aql
new file mode 100644
index 0000000..0280e92
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf07.aql
@@ -0,0 +1,17 @@
+/*
+ * Description  : Pass value of type float to UDF
+ * Expected Res : Success
+ * Date         : Sep 4th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf07.adm";
+
+create function test.echo($a){
+$a
+}
+
+let $b:=1234.1f
+return test.echo($b)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf08.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf08.aql
new file mode 100644
index 0000000..5dfb9a2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf08.aql
@@ -0,0 +1,17 @@
+/*
+ * Description  : Pass a sting as input to UDF
+ * Expected Res : Success
+ * Date         : 4th September 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf08.adm";
+
+create function test.echo($a){
+$a
+}
+
+let $a:="This is a test string"
+return test.echo($a)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf09.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf09.aql
new file mode 100644
index 0000000..b16e2dd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf09.aql
@@ -0,0 +1,31 @@
+/*
+ * Description  : Create UDF to read from internal dataset 
+ * Expected Res : Success
+ * Date         : Sep 4th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf09.adm";
+
+create type test.TestType as open {
+id : int32
+}
+
+create dataset test.t1(TestType) partitioned by key id;
+
+insert into dataset test.t1({"id":345});
+insert into dataset test.t1({"id":315});
+insert into dataset test.t1({"id":245});
+insert into dataset test.t1({"id":385});
+insert into dataset test.t1({"id":241});
+insert into dataset test.t1({"id":745});
+insert into dataset test.t1({"id":349});
+insert into dataset test.t1({"id":845});
+
+create function test.readDataset($a) {
+$a
+}
+   
+test.readDataset(for $a in dataset('test.t1') order by $a.id return $a);
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf10.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf10.aql
new file mode 100644
index 0000000..d0da4e1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf10.aql
@@ -0,0 +1,17 @@
+/*
+ * Description  : Create UDF and pass an unordered list as input and return that list.
+ * Expected Res : Success
+ * Date         : 4th September 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf10.adm";
+
+create function test.echo($uolist){
+$uolist
+}
+
+let $a:={{"this is optional data","this is extra data","open types are good"}}
+return test.echo($a)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf11.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf11.aql
new file mode 100644
index 0000000..b842c93
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf11.aql
@@ -0,0 +1,17 @@
+/*
+ * Description  : Create UDF to return ordered list of integers
+ * Expected Res : Success
+ * Date         : Sep 4th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf11.adm";
+
+create function test.OList(){
+[1,2,3,4,5,6,7,8,9,10]
+}
+
+for $a in test.OList()
+return $a
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf12.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf12.aql
new file mode 100644
index 0000000..e3f8122
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf12.aql
@@ -0,0 +1,16 @@
+/*
+ * Description  : Create UDF to add two integers
+ * Expected Res : Success
+ * Date         : 4th September 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf12.adm";
+
+create function test.foo($a,$b) {
+$a+$b
+}
+
+test.foo(100,200)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf13.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf13.aql
new file mode 100644
index 0000000..533def7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf13.aql
@@ -0,0 +1,16 @@
+/*
+ * Description  : Create UDF to subtract two integers
+ * Expected Res : Success
+ * Date         : 4th September 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf13.adm";
+
+create function test.foo($a,$b) {
+$a - $b
+}
+
+test.foo(400,200)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf14.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf14.aql
new file mode 100644
index 0000000..fc3447d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf14.aql
@@ -0,0 +1,16 @@
+/*
+ * Description  : Create UDF to multiply two integers
+ * Expected Res : Success
+ * Date         : 4th September 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf14.adm";
+
+create function test.foo($a,$b) {
+$a*$b
+}
+
+test.foo(400,200)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf15.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf15.aql
new file mode 100644
index 0000000..4b4992a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf15.aql
@@ -0,0 +1,21 @@
+/*
+ * Description  : Create UDF that returns a heterogeneous ordered list
+ *              : invoke the UDF in the FOR expression of FLWOR
+ * Expected Res : Success
+ * Date         : Sep 5th 2012
+ * Ignored      : Not part of current tests because of Issue 200
+ */
+
+// this test resturns NPE:Issue 166
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf15.adm";
+
+create function test.OList2(){
+[[1,2,3,4,5,6,7,8,9,10],["a","b","c","d","e","f","g","h","y"]]
+}
+
+for $a in test.OList2()
+return $a
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf16.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf16.aql
new file mode 100644
index 0000000..e9f0742
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf16.aql
@@ -0,0 +1,18 @@
+/*
+ * Description  : Create UDF that returns string
+ *              : compute the string lenght of the string
+ * Expected Res : Success
+ * Date         : Sep 5th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf16.adm";
+
+create function test.fn02(){
+"Welcome to the world of Asterix"
+}
+
+let $str := test.fn02()
+return string-length($str)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf17.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf17.aql
new file mode 100644
index 0000000..b98d123
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf17.aql
@@ -0,0 +1,22 @@
+/*
+ * Description  : Create UDF and invoke it from another UDF and 
+ *              : child UDF returns a string to the parent.
+ * Expected Res : Success
+ * Date         : Sep 5th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf17.adm";
+
+create function test.parent(){
+test.child()
+}
+
+create function test.child() {
+"This data is from the child function"
+}
+
+let $str := test.parent()
+return $str
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf18.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf18.aql
new file mode 100644
index 0000000..aa6a57b
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf18.aql
@@ -0,0 +1,17 @@
+/*
+ * Description  : Create UDF and invoke the UDF from with in asterix built-in function
+ * Expected Res : Success
+ * Date         : Sep 5th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf18.adm";
+
+create function test.fn06(){
+false
+}
+
+let $val := not(test.fn06())
+return $val
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf19.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf19.aql
new file mode 100644
index 0000000..87c39a5
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf19.aql
@@ -0,0 +1,23 @@
+/*
+ * Description  : Create UDF and invoke in the WHERE clause of FLWOR expression
+ * Expected Res : Success
+ * Date         : Sep 5th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf19.adm";
+
+create function test.pie(){
+3.14
+}
+
+create function test.area($radius){
+test.pie() * $radius * $radius
+}
+
+for $a in [2,4,6,8,10,12]
+where test.area($a) > 100
+return test.area($a)
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf20.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf20.aql
new file mode 100644
index 0000000..e0a16a1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf20.aql
@@ -0,0 +1,23 @@
+/*
+ * Description  : Create UDF and invoke in the WHERE clause of FLWOR expression
+ * Expected Res : Success
+ * Date         : Sep 5th 2012
+ */
+
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf20.adm";
+
+create function test.pie(){
+3.14
+}
+
+create function test.area($radius){
+test.pie() * $radius * $radius
+}
+
+for $a in [2,4,6,8,10,12]
+where test.area($a) > 100
+return { "radius" : $a,"area" : test.area($a) }
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf21.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf21.aql
new file mode 100644
index 0000000..7e943c3
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf21.aql
@@ -0,0 +1,18 @@
+/*
+ * Description  : Create UDF to verify if input is odd
+ * Expected Res : Success
+ * Date         : Sep 5th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf21.adm";
+
+create function test.isOdd($b){
+$b%2 != 0
+}
+
+for $a in [10,20,2,30,4,3,6,44,5,7,9,1,13,17,992,19,40,50,60,25,45,65,75]
+where test.isOdd($a)
+return $a
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf22.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf22.aql
new file mode 100644
index 0000000..83e19e6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf22.aql
@@ -0,0 +1,18 @@
+/*
+ * Description  : Create UDF to concatenate two input strings.
+ * Expected Res : Success
+ * Date         : Sep 5th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf22.adm";
+
+create function test.getFullName($fname,$lname){
+string-concat([$fname,$lname])
+}
+
+let $fn := "Bob"
+let $ln := "Harbus"
+return test.getFullName($fn,$ln)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf23.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf23.aql
new file mode 100644
index 0000000..a2d8ec5
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf23.aql
@@ -0,0 +1,18 @@
+/*
+ * Description  : Create UDF and invoke it in limit clause
+ * Expected Res : Success
+ * Date         : Sep 5th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf23.adm";
+
+create function test.numRows(){
+6
+}
+   
+for $l in dataset('Metadata.Dataset')
+limit test.numRows()
+return $l
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf24.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf24.aql
new file mode 100644
index 0000000..eef906d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf24.aql
@@ -0,0 +1,21 @@
+/*
+ * Description  : Create UDF that returns a range
+ * Expected Res : Success
+ * Date         : Sep 5 2012
+ * Ignored      : Not part of current test build because of Issue 201
+ */
+
+// Returns java.lang.ClassCastException : Issue 195
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf24.adm";
+
+create function test.myRangeFn($n)
+{
+   range(1,$n)
+}
+
+for $i in test.myRangeFn(100)
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf25.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf25.aql
new file mode 100644
index 0000000..fefc07e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf25.aql
@@ -0,0 +1,23 @@
+/*
+ * Description  : Create UDF and invoke with negative inputs.
+ * Expected Res : Failure
+ * Date         : 5th Sep 2012
+ */
+
+// This one returns NPE...
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf25.adm";
+
+create function test.computeBonus($pbcRating,$salary)
+{
+   if ($pbcRating = 1) then
+        $salary * 0.25
+   else
+        $salary * 0.10
+}
+
+test.computeBonus(-1,-1)
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf26.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf26.aql
new file mode 100644
index 0000000..95420b7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf26.aql
@@ -0,0 +1,16 @@
+/*
+ * Description  : Create UDF and define with missing references.
+ * Expected Res : Failure
+ * Date         : Sep 6th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf26.adm";
+
+create function test.needs_f1($x){
+ $x + f1()
+}
+
+test.needs_f1(12345)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf27.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf27.aql
new file mode 100644
index 0000000..b9db17f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf27.aql
@@ -0,0 +1,20 @@
+/*
+ * Description  : Create UDF and invoke UDF from a quantified expression
+ * Expected Res : Success
+ * Date         : Sep 6th 2012
+ */
+
+// this test is not giving expected results.
+// issue 194 reported to track this
+
+drop dataverse test if exists;
+create dataverse test;
+
+write output to nc1:"rttest/user-defined-functions_udf27.adm";
+
+create function test.f1(){
+100
+}
+
+let $a := true
+return some $i in [100,200] satisfies test.f1()