fix issue625
diff --git a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue625/query-issue625.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue625/query-issue625.1.ddl.aql
new file mode 100644
index 0000000..44d9d32
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue625/query-issue625.1.ddl.aql
@@ -0,0 +1,17 @@
+/*
+ * Description     : Issue625
+ * Expected Result : Success
+ * Date            : 21 October 2013
+ * Notes           : This test was written to verify the fix for issue625.
+ */
+
+drop dataverse fooverse if exists;
+create dataverse fooverse;
+use dataverse fooverse;
+
+create type FooType as open {
+    id: int32,
+    numbers: [int32]
+}
+
+create dataset Foo(FooType) primary key id;
diff --git a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue625/query-issue625.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue625/query-issue625.2.update.aql
new file mode 100644
index 0000000..dbe69e6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue625/query-issue625.2.update.aql
@@ -0,0 +1,17 @@
+/*
+ * Description     : Issue592
+ * Expected Result : Success
+ * Date            : 21 October 2013
+ * Notes           : This test was written to verify the fix for issue592.
+ */
+
+use dataverse fooverse;
+ 
+insert into dataset Foo(
+let $number_strings := ["1", "2", "3"]
+let $numbers := for $x in $number_strings return int32($x)
+return {
+    "id": 1,
+    "numbers": $numbers
+}
+);
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue625/query-issue625.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue625/query-issue625.3.query.aql
new file mode 100644
index 0000000..1f087a8
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue625/query-issue625.3.query.aql
@@ -0,0 +1,11 @@
+/*
+ * Description     : Issue592
+ * Expected Result : Success
+ * Date            : 21 October 2013
+ * Notes           : This test was written to verify the fix for issue592.
+ */
+ 
+use dataverse fooverse;
+
+for $x in dataset Foo
+return $x
diff --git a/asterix-app/src/test/resources/runtimets/results/open-closed/query-issue625/query-issue625.1.adm b/asterix-app/src/test/resources/runtimets/results/open-closed/query-issue625/query-issue625.1.adm
new file mode 100644
index 0000000..a7adaa3
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/open-closed/query-issue625/query-issue625.1.adm
@@ -0,0 +1 @@
+{ "id": 1, "numbers": [ 1, 2, 3 ] }
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index ddf2a21..d36fbd4 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -2904,6 +2904,11 @@
         <output-dir compare="Text">query-issue592</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="open-closed">
+      <compilation-unit name="query-issue625">
+        <output-dir compare="Text">query-issue625</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="quantifiers">
     <test-case FilePath="quantifiers">
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/base/TypeComputerUtilities.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/base/TypeComputerUtilities.java
index 8959f2c..6464c4a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/base/TypeComputerUtilities.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/base/TypeComputerUtilities.java
@@ -15,8 +15,19 @@
 
 package edu.uci.ics.asterix.om.typecomputer.base;
 
+import java.util.List;
+
+import org.apache.commons.lang3.mutable.Mutable;
+
+import edu.uci.ics.asterix.om.types.ARecordType;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.AbstractCollectionType;
 import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression;
 
 public class TypeComputerUtilities {
 
@@ -55,4 +66,55 @@
         } else
             return null;
     }
+
+    public static boolean nullableType(ILogicalExpression expression, IVariableTypeEnvironment env)
+            throws AlgebricksException {
+        AbstractFunctionCallExpression func = (AbstractFunctionCallExpression) expression;
+        if (!(func instanceof ScalarFunctionCallExpression)) {
+            return true;
+        }
+        List<Mutable<ILogicalExpression>> args = func.getArguments();
+        for (Mutable<ILogicalExpression> arg : args) {
+            IAType type = (IAType) env.getType(arg.getValue());
+            if (type.getTypeTag() == ATypeTag.UNION || type.getTypeTag() == ATypeTag.NULL
+                    || type.getTypeTag() == ATypeTag.ANY) {
+                return true;
+            }
+            if (type.getTypeTag() == ATypeTag.RECORD || type.getTypeTag() == ATypeTag.UNORDEREDLIST
+                    || type.getTypeTag() == ATypeTag.ORDEREDLIST) {
+                if (nullableCompositeType(type)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    private static boolean nullableCompositeType(IAType type) {
+        if (type.getTypeTag() == ATypeTag.UNION || type.getTypeTag() == ATypeTag.NULL
+                || type.getTypeTag() == ATypeTag.ANY) {
+            return true;
+        } else if (type.getTypeTag() == ATypeTag.RECORD) {
+            ARecordType recordType = (ARecordType) type;
+            IAType[] fieldTypes = recordType.getFieldTypes();
+            for (IAType fieldType : fieldTypes) {
+                boolean nullable = nullableCompositeType(fieldType);
+                if (nullable) {
+                    return true;
+                }
+            }
+            return false;
+        } else if (type.getTypeTag() == ATypeTag.UNORDEREDLIST || type.getTypeTag() == ATypeTag.ORDEREDLIST) {
+            AbstractCollectionType collectionType = (AbstractCollectionType) type;
+            IAType itemType = collectionType.getItemType();
+            boolean nullable = nullableCompositeType(itemType);
+            if (nullable) {
+                return true;
+            } else {
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalABooleanTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalABooleanTypeComputer.java
index 71c69dd..764624f 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalABooleanTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalABooleanTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.ABOOLEAN);
-        return new AUnionType(unionList, "OptionalBoolean");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.ABOOLEAN);
+            return new AUnionType(unionList, "OptionalBoolean");
+        } else {
+            return BuiltinType.ABOOLEAN;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalACircleTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalACircleTypeComputer.java
index 411e201..92e26e0 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalACircleTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalACircleTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.ACIRCLE);
-        return new AUnionType(unionList, "OptionalCircle");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.ACIRCLE);
+            return new AUnionType(unionList, "OptionalCircle");
+        } else {
+            return BuiltinType.ACIRCLE;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADateTimeTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADateTimeTypeComputer.java
index 8ff0b1f..f0d2caf 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADateTimeTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADateTimeTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.ADATETIME);
-        return new AUnionType(unionList, "OptionalDatetime");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.ADATETIME);
+            return new AUnionType(unionList, "OptionalDatetime");
+        } else {
+            return BuiltinType.ADATETIME;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADateTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADateTypeComputer.java
index 1b17333..093849d 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADateTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADateTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.ADATE);
-        return new AUnionType(unionList, "OptionalDate");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.ADATE);
+            return new AUnionType(unionList, "OptionalDate");
+        } else {
+            return BuiltinType.ADATE;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADayTimeDurationTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADayTimeDurationTypeComputer.java
index 38f76e3..c3c7c25 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADayTimeDurationTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADayTimeDurationTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -40,10 +41,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.ADAYTIMEDURATION);
-        return new AUnionType(unionList, "OptionalDayTimeDuration");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.ADAYTIMEDURATION);
+            return new AUnionType(unionList, "OptionalDayTimeDuration");
+        } else {
+            return BuiltinType.ADAYTIMEDURATION;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADoubleTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADoubleTypeComputer.java
index 163b6b3..324e078 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADoubleTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADoubleTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,9 +37,13 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.ADOUBLE);
-        return new AUnionType(unionList, "OptionalDouble");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.ADOUBLE);
+            return new AUnionType(unionList, "OptionalDouble");
+        } else {
+            return BuiltinType.ADOUBLE;
+        }
     }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADurationTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADurationTypeComputer.java
index 48f0715..85556ed 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADurationTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalADurationTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.ADURATION);
-        return new AUnionType(unionList, "OptionalDuration");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.ADURATION);
+            return new AUnionType(unionList, "OptionalDuration");
+        } else {
+            return BuiltinType.ADURATION;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAFloatTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAFloatTypeComputer.java
index 6c93522..d9da2b8 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAFloatTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAFloatTypeComputer.java
@@ -18,9 +18,11 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
 import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
@@ -34,11 +36,15 @@
 
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
-            IMetadataProvider<?, ?> metadataProvider) {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.AFLOAT);
-        return new AUnionType(unionList, "OptionalFloat");
+            IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.AFLOAT);
+            return new AUnionType(unionList, "OptionalFloat");
+        } else {
+            return BuiltinType.AFLOAT;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt16TypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt16TypeComputer.java
index 575748e..a737ed2 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt16TypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt16TypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.AINT16);
-        return new AUnionType(unionList, "OptionalInt16");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.AINT16);
+            return new AUnionType(unionList, "OptionalInt16");
+        } else {
+            return BuiltinType.AINT16;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt32TypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt32TypeComputer.java
index 38aa0f3..c666d36 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt32TypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt32TypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.AINT32);
-        return new AUnionType(unionList, "OptionalInt32");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.AINT32);
+            return new AUnionType(unionList, "OptionalInt32");
+        } else {
+            return BuiltinType.AINT32;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt64TypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt64TypeComputer.java
index 571b266..701b1ae 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt64TypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt64TypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.AINT64);
-        return new AUnionType(unionList, "OptionalInt64");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.AINT64);
+            return new AUnionType(unionList, "OptionalInt64");
+        } else {
+            return BuiltinType.AINT64;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt8TypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt8TypeComputer.java
index 49c2994..ad6b130 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt8TypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAInt8TypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.AINT8);
-        return new AUnionType(unionList, "OptionalInt8");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.AINT8);
+            return new AUnionType(unionList, "OptionalInt8");
+        } else {
+            return BuiltinType.AINT8;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAIntervalTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAIntervalTypeComputer.java
index 6929a80..9c5a7d5 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAIntervalTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAIntervalTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
 
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.AINTERVAL);
-        return new AUnionType(unionList, "OptionalInterval");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.AINTERVAL);
+            return new AUnionType(unionList, "OptionalInterval");
+        } else {
+            return BuiltinType.AINTERVAL;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalALineTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalALineTypeComputer.java
index b7b89a9..e692dbd 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalALineTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalALineTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.ALINE);
-        return new AUnionType(unionList, "OptionalLine");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.ALINE);
+            return new AUnionType(unionList, "OptionalLine");
+        } else {
+            return BuiltinType.ALINE;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAPoint3DTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAPoint3DTypeComputer.java
index 7008ac6..8f0bf7a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAPoint3DTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAPoint3DTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.APOINT3D);
-        return new AUnionType(unionList, "OptionalPoint3d");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.APOINT3D);
+            return new AUnionType(unionList, "OptionalPoint3d");
+        } else {
+            return BuiltinType.APOINT3D;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAPointTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAPointTypeComputer.java
index c07d4fb..1a93ee6 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAPointTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAPointTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.APOINT);
-        return new AUnionType(unionList, "OptionalPoint");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.APOINT);
+            return new AUnionType(unionList, "OptionalPoint");
+        } else {
+            return BuiltinType.APOINT;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAPolygonTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAPolygonTypeComputer.java
index 398add3..405608c 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAPolygonTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAPolygonTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.APOLYGON);
-        return new AUnionType(unionList, "OptionalPolygon");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.APOLYGON);
+            return new AUnionType(unionList, "OptionalPolygon");
+        } else {
+            return BuiltinType.APOLYGON;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalARectangleTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalARectangleTypeComputer.java
index 936668b..c6a8026 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalARectangleTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalARectangleTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.ARECTANGLE);
-        return new AUnionType(unionList, "OptionalRectangle");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.ARECTANGLE);
+            return new AUnionType(unionList, "OptionalRectangle");
+        } else {
+            return BuiltinType.ARECTANGLE;
+        }
     }
 
 }
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAStringTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAStringTypeComputer.java
index 3758645..5b0642d 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAStringTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAStringTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.ASTRING);
-        return new AUnionType(unionList, "OptionalString");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.ASTRING);
+            return new AUnionType(unionList, "OptionalString");
+        } else {
+            return BuiltinType.ASTRING;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalATimeTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalATimeTypeComputer.java
index 19e6e30..4d466e7 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalATimeTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalATimeTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -36,10 +37,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.ATIME);
-        return new AUnionType(unionList, "OptionalTime");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.ATIME);
+            return new AUnionType(unionList, "OptionalTime");
+        } else {
+            return BuiltinType.ATIME;
+        }
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAYearMonthDurationTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAYearMonthDurationTypeComputer.java
index 4c08142..3350674 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAYearMonthDurationTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalAYearMonthDurationTypeComputer.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.base.TypeComputerUtilities;
 import edu.uci.ics.asterix.om.types.AUnionType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -40,10 +41,14 @@
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        List<IAType> unionList = new ArrayList<IAType>();
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(BuiltinType.AYEARMONTHDURATION);
-        return new AUnionType(unionList, "OptionalYearMonthDuration");
+        if (TypeComputerUtilities.nullableType(expression, env)) {
+            List<IAType> unionList = new ArrayList<IAType>();
+            unionList.add(BuiltinType.ANULL);
+            unionList.add(BuiltinType.AYEARMONTHDURATION);
+            return new AUnionType(unionList, "OptionalYearMonthDuration");
+        } else {
+            return BuiltinType.AYEARMONTHDURATION;
+        }
     }
 
 }