[ASTERIXDB-2530][COMP] Error computing type for numeric add
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Fixed type computation for numeric add when first argument
is of type ANY and second argument is of a temporal type
Change-Id: I4beac66a6a71179bb3214d27a820f3306533b03c
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3271
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/query-ASTERIXDB-2530/query-ASTERIXDB-2530.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/query-ASTERIXDB-2530/query-ASTERIXDB-2530.1.query.sqlpp
new file mode 100644
index 0000000..d4e533b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/query-ASTERIXDB-2530/query-ASTERIXDB-2530.1.query.sqlpp
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ /*
+ * Description : Test type computation for numeric add when first
+ * : argument is of type ANY and second argument is a duration
+ * Success : Yes
+ */
+
+from range(1, 2) x
+let y =
+ case when x > 1
+ then date("2011-11-11")
+ else datetime("2011-11-11T11:11:11Z")
+ end
+select y + year_month_duration("P" || tostring(x) || "Y") res
+order by x
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/query-ASTERIXDB-2530/query-ASTERIXDB-2530.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/query-ASTERIXDB-2530/query-ASTERIXDB-2530.1.adm
new file mode 100644
index 0000000..6dd4bdb
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/query-ASTERIXDB-2530/query-ASTERIXDB-2530.1.adm
@@ -0,0 +1,2 @@
+{ "res": datetime("2012-11-11T11:11:11.000Z") }
+{ "res": date("2013-11-11") }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 42e3024..0b221bf 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -6852,6 +6852,11 @@
</compilation-unit>
</test-case>
<test-case FilePath="numeric">
+ <compilation-unit name="query-ASTERIXDB-2530">
+ <output-dir compare="Text">query-ASTERIXDB-2530</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="numeric">
<compilation-unit name="radians">
<output-dir compare="Text">radians</output-dir>
</compilation-unit>
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAddSubMulDivTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAddSubMulDivTypeComputer.java
index 47ad411..41a60c6 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAddSubMulDivTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAddSubMulDivTypeComputer.java
@@ -195,8 +195,14 @@
case INTEGER:
case BIGINT:
case FLOAT:
- case ANY:
case DOUBLE:
+ case DATE:
+ case TIME:
+ case DATETIME:
+ case DURATION:
+ case YEARMONTHDURATION:
+ case DAYTIMEDURATION:
+ case ANY:
type = BuiltinType.ANY;
break;
default: