ASTERIXDB-2418][COMP] Fix NPE in SqlppExpressionToPlanTranslator
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Fixed NPE in SqlppExpressionToPlanTranslator for query:
select value $param
Change-Id: Ie3207d077480a90fd00fdd59923ea76e2ca6db25
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2789
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Taewoo Kim <wangsaeu@gmail.com>
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
index 3954135..033c92f 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
@@ -84,6 +84,7 @@
import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
import org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
import org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression;
@@ -683,7 +684,8 @@
LogicalVariable returnVar;
ILogicalOperator returnOperator;
SourceLocation sourceLoc = returnExpr.getSourceLocation();
- if (returnExpr.getKind() == Kind.VARIABLE_EXPRESSION) {
+ if (returnExpr.getKind() == Kind.VARIABLE_EXPRESSION
+ && eo.first.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
VariableExpr varExpr = (VariableExpr) returnExpr;
returnOperator = eo.second.getValue();
returnVar = context.getVar(varExpr.getVar().getId());
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/statement-params/named_04/named_04.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/statement-params/named_04/named_04.1.query.sqlpp
new file mode 100644
index 0000000..720c2f2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/statement-params/named_04/named_04.1.query.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * 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 fix for ASTERIXDB-2418
+ * Expected Res : Success
+ * Date : Jul 2018
+ */
+
+// requesttype=application/json
+
+// param $p_int:json=42
+
+select value $p_int
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/statement-params/named_04/named_04.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/statement-params/named_04/named_04.1.adm
new file mode 100644
index 0000000..f70d7bb
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/statement-params/named_04/named_04.1.adm
@@ -0,0 +1 @@
+42
\ 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 bc3b226..8b0f5a4 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -6168,6 +6168,11 @@
</compilation-unit>
</test-case>
<test-case FilePath="statement-params">
+ <compilation-unit name="named_04">
+ <output-dir compare="Text">named_04</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="statement-params">
<compilation-unit name="positional_01">
<output-dir compare="Text">positional_01</output-dir>
</compilation-unit>