Xikui Wang has submitted this change and it was merged. Change subject: [NO ISSUE][FUN] Fix drop-if-exists for functions ......................................................................
[NO ISSUE][FUN] Fix drop-if-exists for functions - user model changes: no - storage format changes: no - interface changes: no Details: The current handleFunctionDropStatement method doesn't cover the case while function != null && stmt.getIfExists() == true. Change-Id: I83ad25de6aee6b38340843e9c9e150ea272a9dbd Reviewed-on: https://asterix-gerrit.ics.uci.edu/2798 Sonar-Qube: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> Contrib: Jenkins <[email protected]> Integration-Tests: Jenkins <[email protected]> Reviewed-by: abdullah alamoudi <[email protected]> --- M asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.1.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.2.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.3.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.4.ddl.sqlpp M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml 6 files changed, 96 insertions(+), 4 deletions(-) Approvals: Anon. E. Moose #1000171: abdullah alamoudi: Looks good to me, approved Jenkins: Verified; No violations found; ; Verified diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java index 0d884ba..76116c4 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java @@ -1811,12 +1811,15 @@ signature.getNamespace() + "." + signature.getName()); try { Function function = MetadataManager.INSTANCE.getFunction(mdTxnCtx, signature); + // If function == null && stmtDropFunction.getIfExists() == true, commit txn directly. if (function == null && !stmtDropFunction.getIfExists()) { throw new CompilationException(ErrorCode.UNKNOWN_FUNCTION, sourceLoc, signature); - } else if (isFunctionUsed(mdTxnCtx, signature, null)) { - throw new MetadataException(ErrorCode.METADATA_DROP_FUCTION_IN_USE, sourceLoc, signature); - } else { - MetadataManager.INSTANCE.dropFunction(mdTxnCtx, signature); + } else if (function != null) { + if (isFunctionUsed(mdTxnCtx, signature, null)) { + throw new MetadataException(ErrorCode.METADATA_DROP_FUCTION_IN_USE, sourceLoc, signature); + } else { + MetadataManager.INSTANCE.dropFunction(mdTxnCtx, signature); + } } MetadataManager.INSTANCE.commitTransaction(mdTxnCtx); } catch (Exception e) { diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.1.ddl.sqlpp new file mode 100644 index 0000000..63b76bb --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.1.ddl.sqlpp @@ -0,0 +1,25 @@ +/* + * 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. + */ + +drop dataverse test if exists; +create dataverse test; +use test; +create function test(){ + 1 +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.2.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.2.ddl.sqlpp new file mode 100644 index 0000000..14a68c0 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.2.ddl.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. + */ +use test; +drop function test@0 if exists; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.3.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.3.ddl.sqlpp new file mode 100644 index 0000000..14a68c0 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.3.ddl.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. + */ +use test; +drop function test@0 if exists; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.4.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.4.ddl.sqlpp new file mode 100644 index 0000000..45f4fae --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/function/drop_if_exists/drop_if_exists.4.ddl.sqlpp @@ -0,0 +1,19 @@ +/* + * 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. + */ +drop dataverse test; \ 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 c5775d8..16bf364 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -8787,6 +8787,11 @@ <output-dir compare="Text">issue-2394</output-dir> </compilation-unit> </test-case> + <test-case FilePath="function"> + <compilation-unit name="drop_if_exists"> + <output-dir compare="Text">drop_if_exists</output-dir> + </compilation-unit> + </test-case> </test-group> <test-group name="feeds"> <test-case FilePath="feeds"> -- To view, visit https://asterix-gerrit.ics.uci.edu/2798 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I83ad25de6aee6b38340843e9c9e150ea272a9dbd Gerrit-PatchSet: 4 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Xikui Wang <[email protected]> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Xikui Wang <[email protected]> Gerrit-Reviewer: abdullah alamoudi <[email protected]>
