Taewoo Kim has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/471
Change subject: ASTERIXDB-1155: NULL handling of LimitClause in CloneAndSubstituteVariablesVisitor fixed. ...................................................................... ASTERIXDB-1155: NULL handling of LimitClause in CloneAndSubstituteVariablesVisitor fixed. Change-Id: I20eec8f26240bcca05a6db35bc25bd306c3fa8ba --- 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, 121 insertions(+), 4 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/71/471/1 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..cb1db18 --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.1.ddl.aql @@ -0,0 +1,46 @@ +/* + * 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 and try to use the function parameter outside + * of the function. + * Expected Res : Failure + * Date : Apr 10th 2013 + */ + +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..0630231 --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.2.update.aql @@ -0,0 +1,31 @@ +/* + * 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 and try to use the function parameter outside + * of the function. + * Expected Res : Failure + * Date : Apr 10th 2013 + */ + +use dataverse emergencyTest; + +use dataverse emergencyTest; + +insert into dataset EmergencyReports({"id":1,"intensity":1,"message":"emergency1"}); +insert into dataset EmergencyReports({"id":2,"intensity":2,"message":"emergency2"}); 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..75ee077 --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.3.query.aql @@ -0,0 +1,28 @@ +/* + * 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 but use ';' for terminating the declare function statement. Invoke the function + * Expected Res : Success + * Date : Apr 10th 2013 + */ + +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..c67e341 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> 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..c65dbc7 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,13 @@ 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; + 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 +634,6 @@ // TODO Auto-generated method stub return null; } - @Override public Pair<IAqlExpression, List<VariableSubstitution>> visitCreateFeedPolicyStatement( -- To view, visit https://asterix-gerrit.ics.uci.edu/471 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I20eec8f26240bcca05a6db35bc25bd306c3fa8ba Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Taewoo Kim <[email protected]>
