[ASTERIXDB-2748][RT] CASE fails if default value is TRUE
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Fix ArrayIndexOutOfBoundsException in CASE expression
when the default value is TRUE and none of its WHEN
clauses match at runtime
Change-Id: I8d16c200fa4b65008c241aeb8a0ebb86f7b4a6c0
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/6823
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: 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/misc/case_09/case_09.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/case_09/case_09.1.query.sqlpp
new file mode 100644
index 0000000..791ad01
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/case_09/case_09.1.query.sqlpp
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+SELECT VALUE (CASE WHEN t = 1 THEN FALSE ELSE TRUE END) FROM [0] t
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/case_09/case_09.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/case_09/case_09.1.adm
new file mode 100644
index 0000000..f32a580
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/case_09/case_09.1.adm
@@ -0,0 +1 @@
+true
\ 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 bcd9f18..e1f3084 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -6488,6 +6488,11 @@
</compilation-unit>
</test-case>
<test-case FilePath="misc">
+ <compilation-unit name="case_09">
+ <output-dir compare="Text">case_09</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="misc">
<compilation-unit name="dataset_nodegroup">
<output-dir compare="Text">dataset_nodegroup</output-dir>
</compilation-unit>
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SwitchCaseDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SwitchCaseDescriptor.java
index dc182ee..3e1eb49 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SwitchCaseDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SwitchCaseDescriptor.java
@@ -77,7 +77,7 @@
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
int n = args.length;
evals[0].evaluate(tuple, condPtr);
- for (int i = 1; i < n; i += 2) {
+ for (int i = 1; i < n - 1; i += 2) {
evals[i].evaluate(tuple, casePtr);
if (equals(condPtr, casePtr)) {
evals[i + 1].evaluate(tuple, argPtr);