Taewoo Kim has submitted this change and it was merged. Change subject: ASTERIXDB-1155: NULL handling of LimitClause in CloneAndSubstituteVariablesVisitor fixed. ......................................................................
ASTERIXDB-1155: NULL handling of LimitClause in CloneAndSubstituteVariablesVisitor fixed. Change-Id: Idd932f2b783454b0216a947bdb4ff35a6b101cd0 Reviewed-on: https://asterix-gerrit.ics.uci.edu/472 Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Till Westmann <ti...@apache.org> Reviewed-by: Steven Jacobs <sjaco...@ucr.edu> --- A asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.1.ddl.aql A asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.2.update.aql A asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.3.query.aql A asterix-app/src/test/resources/runtimets/results/user-defined-functions/udf31/udf31.1.adm M asterix-app/src/test/resources/runtimets/testsuite.xml M asterix-aql/src/main/java/org/apache/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java 6 files changed, 135 insertions(+), 5 deletions(-) Approvals: Steven Jacobs: Looks good to me, approved Till Westmann: Looks good to me, but someone else must approve Jenkins: Verified diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.1.ddl.aql new file mode 100644 index 0000000..4f8521c --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.1.ddl.aql @@ -0,0 +1,47 @@ +/* + * 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 : Declare a UDF that has a LIMIT in it and try to execute that function. + * Expected Res : Success + */ + +drop dataverse emergencyTest if exists; +create dataverse emergencyTest; +use dataverse emergencyTest; + +create type EmergencyReport as +{ + "id": int, + "intensity": int, + "message": string +} + +create dataset EmergencyReports(EmergencyReport) +primary key id; + +create function mostIntenseEarthquakeNearLocation() +{ + for $emergency in dataset EmergencyReports + order by $emergency.id + limit 1 + return $emergency.message +} + + diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.2.update.aql new file mode 100644 index 0000000..d9db485 --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.2.update.aql @@ -0,0 +1,40 @@ +/* + * 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 : Declare a UDF that has a LIMIT in it and try to execute that function. + * Expected Res : Success + */ + +use dataverse emergencyTest; + +insert into dataset EmergencyReports({ + "id":1,"intensity":1,"message":"emergency1" +}); + +insert into dataset EmergencyReports({ + "id":2,"intensity":2,"message":"emergency2" +}); + +insert into dataset EmergencyReports({ + "id":3,"intensity":3,"message":"emergency3" +}); + + + diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.3.query.aql new file mode 100644 index 0000000..877a8be --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.3.query.aql @@ -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 : Declare a UDF that has a LIMIT in it and try to execute that function. + * Expected Res : Success + */ + +use dataverse emergencyTest; + +for $result in mostIntenseEarthquakeNearLocation() +return $result; + + diff --git a/asterix-app/src/test/resources/runtimets/results/user-defined-functions/udf31/udf31.1.adm b/asterix-app/src/test/resources/runtimets/results/user-defined-functions/udf31/udf31.1.adm new file mode 100644 index 0000000..b6ac4e0 --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/results/user-defined-functions/udf31/udf31.1.adm @@ -0,0 +1,2 @@ +[ "emergency1" + ] diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml index aef2b54..b6417bc 100644 --- a/asterix-app/src/test/resources/runtimets/testsuite.xml +++ b/asterix-app/src/test/resources/runtimets/testsuite.xml @@ -5932,6 +5932,11 @@ </compilation-unit> </test-case> <test-case FilePath="user-defined-functions"> + <compilation-unit name="udf31"> + <output-dir compare="Text">udf31</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="user-defined-functions"> <compilation-unit name="f01"> <output-dir compare="Text">f01</output-dir> <expected-error>org.apache.asterix.common.exceptions.AsterixException</expected-error> @@ -6159,7 +6164,7 @@ </test-group> <test-group name="hdfs"> - <test-case FilePath="hdfs"> + <test-case FilePath="hdfs"> <compilation-unit name="hdfs_shortcircuit"> <output-dir compare="Text">hdfs_shortcircuit</output-dir> </compilation-unit> diff --git a/asterix-aql/src/main/java/org/apache/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java b/asterix-aql/src/main/java/org/apache/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java index b6223cb..adca38c 100644 --- a/asterix-aql/src/main/java/org/apache/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java +++ b/asterix-aql/src/main/java/org/apache/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java @@ -87,8 +87,8 @@ import org.apache.asterix.common.exceptions.AsterixException; import org.apache.hyracks.algebricks.common.utils.Pair; -public class CloneAndSubstituteVariablesVisitor implements - IAqlExpressionVisitor<Pair<IAqlExpression, List<VariableSubstitution>>, List<VariableSubstitution>> { +public class CloneAndSubstituteVariablesVisitor + implements IAqlExpressionVisitor<Pair<IAqlExpression, List<VariableSubstitution>>, List<VariableSubstitution>> { private AqlRewritingContext context; @@ -278,7 +278,14 @@ public Pair<IAqlExpression, List<VariableSubstitution>> visitLimitClause(LimitClause lc, List<VariableSubstitution> arg) throws AsterixException { Pair<IAqlExpression, List<VariableSubstitution>> p1 = lc.getLimitExpr().accept(this, arg); - Pair<IAqlExpression, List<VariableSubstitution>> p2 = lc.getOffset().accept(this, arg); + Pair<IAqlExpression, List<VariableSubstitution>> p2 = null; + // The offset expression can be null. + Expression lcOffsetExpr = lc.getOffset(); + if (lcOffsetExpr != null) { + p2 = lcOffsetExpr.accept(this, arg); + } else { + p2 = new Pair<IAqlExpression, List<VariableSubstitution>>(null, null); + } LimitClause c = new LimitClause((Expression) p1.first, (Expression) p2.first); return new Pair<IAqlExpression, List<VariableSubstitution>>(c, arg); } @@ -628,7 +635,6 @@ // TODO Auto-generated method stub return null; } - @Override public Pair<IAqlExpression, List<VariableSubstitution>> visitCreateFeedPolicyStatement( -- To view, visit https://asterix-gerrit.ics.uci.edu/472 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: Idd932f2b783454b0216a947bdb4ff35a6b101cd0 Gerrit-PatchSet: 5 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Taewoo Kim <wangs...@gmail.com> Gerrit-Reviewer: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Gerrit-Reviewer: Steven Jacobs <sjaco...@ucr.edu> Gerrit-Reviewer: Taewoo Kim <wangs...@gmail.com> Gerrit-Reviewer: Till Westmann <ti...@apache.org>