minor fix for recursive static casting

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_opentype@319 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceStaticTypeCastRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceStaticTypeCastRule.java
index f76d6a7..0b429a9 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceStaticTypeCastRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceStaticTypeCastRule.java
@@ -10,6 +10,7 @@
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.base.AString;
 import edu.uci.ics.asterix.om.constants.AsterixConstantValue;
+import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.ARecordType;
 import edu.uci.ics.asterix.om.types.ATypeTag;
@@ -109,7 +110,7 @@
                     ILogicalExpression expr = expressionPointers.get(position).getValue();
                     if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
                         ScalarFunctionCallExpression funcExpr = (ScalarFunctionCallExpression) expr;
-                        if(TypeComputerUtilities.getRequiredType(funcExpr)!=null)
+                        if (TypeComputerUtilities.getRequiredType(funcExpr) != null)
                             return false;
                         rewriteFuncExpr(funcExpr, requiredRecordType, inputRecordType);
                     }
@@ -135,7 +136,10 @@
                 ILogicalExpression arg = args.get(j).getValue();
                 if (arg.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
                     AbstractFunctionCallExpression argFunc = (AbstractFunctionCallExpression) arg;
-                    TypeComputerUtilities.setOpenType(argFunc, true);
+                    if (argFunc.getFunctionIdentifier() == AsterixBuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR
+                            || argFunc.getFunctionIdentifier() == AsterixBuiltinFunctions.ORDERED_LIST_CONSTRUCTOR) {
+                        TypeComputerUtilities.setOpenType(argFunc, true);
+                    }
                 }
             }
         }
diff --git a/asterix-app/src/test/resources/runtimets/queries/nestrecords/nestrecord.aql b/asterix-app/src/test/resources/runtimets/queries/nestrecords/nestrecord.aql
index 42d93a8..6c4c87b 100644
--- a/asterix-app/src/test/resources/runtimets/queries/nestrecords/nestrecord.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/nestrecords/nestrecord.aql
@@ -14,7 +14,7 @@
   city: string
 }
 
-create type testtype as closed {
+create type testtype as open {
   name: string,
   id: string,
   address: AddressType?
@@ -34,6 +34,10 @@
 { "id": "003", "name": "Person Three", "address": {"street": "2019 DBH",  "city": "Irvine"} }
 );
 
+insert into dataset testds (
+{ "id": "004", "name": "Person Four", "home": {"street": "2019 DBH",  "city": {"name": "Irvine", "zip": 92697} } }
+);
+
 write output to nc1:"rttest/nestrecords_nestrecord.adm";
 
 for $d in dataset("testds") 
diff --git a/asterix-app/src/test/resources/runtimets/results/nestrecords/nestrecord.adm b/asterix-app/src/test/resources/runtimets/results/nestrecords/nestrecord.adm
index 3a67eae..2b255b0 100644
--- a/asterix-app/src/test/resources/runtimets/results/nestrecords/nestrecord.adm
+++ b/asterix-app/src/test/resources/runtimets/results/nestrecords/nestrecord.adm
@@ -1,3 +1,4 @@
 { "name": "Person One", "id": "001", "address": { "street": "3019 DBH", "city": "Irvine", "zip": 92697 } }
 { "name": "Person Two", "id": "002", "address": null }
 { "name": "Person Three", "id": "003", "address": { "street": "2019 DBH", "city": "Irvine" } }
+{ "name": "Person Four", "id": "004", "address": null, "home": { "street": "2019 DBH", "city": { "name": "Irvine", "zip": 92697 } } }