fix issue410
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/typecast/StaticTypeCastUtil.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/typecast/StaticTypeCastUtil.java
index 6cb4d5c..6e3ab37 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/typecast/StaticTypeCastUtil.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/typecast/StaticTypeCastUtil.java
@@ -17,7 +17,9 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.apache.commons.lang3.mutable.Mutable;
import org.apache.commons.lang3.mutable.MutableObject;
@@ -160,6 +162,10 @@
changed = changed || rewriteFuncExpr(argFuncExpr, exprType, exprType, env);
}
}
+ if (!compatible(reqType, inputType)) {
+ throw new AlgebricksException("type mistmach, requred: " + reqType.toString() + " actual: "
+ + inputType.toString());
+ }
return changed;
}
}
@@ -489,4 +495,42 @@
exprRef.setValue(cast);
TypeComputerUtilities.setRequiredAndInputTypes(cast, reqType, inputType);
}
+
+ /**
+ * Determine if two types are compatible
+ *
+ * @param reqType
+ * the required type
+ * @param inputType
+ * the input type
+ * @return true if the two types are compatiable; false otherwise
+ */
+ private static boolean compatible(IAType reqType, IAType inputType) {
+ if (reqType.getTypeTag() == ATypeTag.ANY || inputType.getTypeTag() == ATypeTag.ANY) {
+ return true;
+ }
+ if (reqType.getTypeTag() != ATypeTag.UNION && inputType.getTypeTag() != ATypeTag.UNION) {
+ if (reqType.equals(inputType)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ Set<IAType> reqTypePossible = new HashSet<IAType>();
+ Set<IAType> inputTypePossible = new HashSet<IAType>();
+ if (reqType.getTypeTag() == ATypeTag.UNION) {
+ AUnionType unionType = (AUnionType) reqType;
+ reqTypePossible.addAll(unionType.getUnionList());
+ } else {
+ reqTypePossible.add(reqType);
+ }
+
+ if (inputType.getTypeTag() == ATypeTag.UNION) {
+ AUnionType unionType = (AUnionType) inputType;
+ inputTypePossible.addAll(unionType.getUnionList());
+ } else {
+ inputTypePossible.add(inputType);
+ }
+ return reqTypePossible.equals(inputTypePossible);
+ }
}
diff --git a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue410/query-issue410.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue410/query-issue410.1.ddl.aql
new file mode 100644
index 0000000..6d4a301
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue410/query-issue410.1.ddl.aql
@@ -0,0 +1,10 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type Emp as closed {
+id:int32,
+name:string
+}
+
+create dataset Employee(Emp) primary key id;
diff --git a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue410/query-issue410.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue410/query-issue410.2.update.aql
new file mode 100644
index 0000000..04235e7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue410/query-issue410.2.update.aql
@@ -0,0 +1,3 @@
+use dataverse test;
+
+insert into dataset Employee({"id":float("59138237473282.3293"), "name": double("0.01")});
diff --git a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue410/query-issue410.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue410/query-issue410.3.query.aql
new file mode 100644
index 0000000..c855ffb
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue410/query-issue410.3.query.aql
@@ -0,0 +1,4 @@
+use dataverse test;
+
+for $x in dataset('Employee')
+return $x
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/open-closed/query-issue410/query-issue410.1.adm b/asterix-app/src/test/resources/runtimets/results/open-closed/query-issue410/query-issue410.1.adm
new file mode 100644
index 0000000..ee2dfa4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/open-closed/query-issue410/query-issue410.1.adm
@@ -0,0 +1 @@
+{"id":0, "name": ""}
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index 91624dd..536fc6c 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -2726,6 +2726,12 @@
<output-dir compare="Text">query-issue377</output-dir>
</compilation-unit>
</test-case>
+ <test-case FilePath="open-closed">
+ <compilation-unit name="query-issue410">
+ <output-dir compare="Text">query-issue40</output-dir>
+ <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
+ </compilation-unit>
+ </test-case>
</test-group>
<test-group name="quantifiers">
<test-case FilePath="quantifiers">