ASTERIXDB-1695 Fix Functions in Default Dataverse
Change-Id: I7f08c0acaccdcfaeb4fc9cfb1529214b543d0e86
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1297
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
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 8a25888..d5b1415 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
@@ -1773,6 +1773,7 @@
throws Exception {
CreateFunctionStatement cfs = (CreateFunctionStatement) stmt;
String dataverse = getActiveDataverseName(cfs.getSignature().getNamespace());
+ cfs.getSignature().setNamespace(dataverse);
String functionName = cfs.getaAterixFunction().getName();
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
@@ -1801,6 +1802,7 @@
protected void handleFunctionDropStatement(AqlMetadataProvider metadataProvider, Statement stmt) throws Exception {
FunctionDropStatement stmtDropFunction = (FunctionDropStatement) stmt;
FunctionSignature signature = stmtDropFunction.getFunctionSignature();
+ signature.setNamespace(getActiveDataverseName(signature.getNamespace()));
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
metadataProvider.setMetadataTxnContext(mdTxnCtx);
MetadataLockManager.INSTANCE.functionStatementBegin(signature.getNamespace(),
@@ -1965,7 +1967,7 @@
@Override
public JobSpecification rewriteCompileQuery(AqlMetadataProvider metadataProvider, Query query,
ICompiledDmlStatement stmt)
- throws AsterixException, RemoteException, AlgebricksException, JSONException, ACIDException {
+ throws AsterixException, RemoteException, AlgebricksException, JSONException, ACIDException {
// Query Rewriting (happens under the same ongoing metadata transaction)
Pair<Query, Integer> reWrittenQuery = apiFramework.reWriteQuery(declaredFunctions, metadataProvider, query,
@@ -2266,7 +2268,7 @@
*/
protected Triple<FeedConnectionRequest, Boolean, List<IFeedJoint>> getFeedConnectionRequest(String dataverse,
Feed feed, String dataset, FeedPolicyEntity feedPolicy, MetadataTransactionContext mdTxnCtx)
- throws AsterixException {
+ throws AsterixException {
IFeedJoint sourceFeedJoint;
FeedConnectionRequest request;
List<String> functionsToApply = new ArrayList<>();
@@ -2557,7 +2559,7 @@
protected JobSpecification handleQuery(AqlMetadataProvider metadataProvider, Query query,
IHyracksClientConnection hcc, IHyracksDataset hdc, ResultDelivery resultDelivery, Stats stats)
- throws Exception {
+ throws Exception {
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
boolean bActiveTxn = true;
metadataProvider.setMetadataTxnContext(mdTxnCtx);
@@ -2591,7 +2593,7 @@
private void handleQueryResult(AqlMetadataProvider metadataProvider, IHyracksClientConnection hcc,
IHyracksDataset hdc, JobSpecification compiled, ResultDelivery resultDelivery, Stats stats)
- throws Exception {
+ throws Exception {
if (GlobalConfig.ASTERIX_LOGGER.isLoggable(Level.FINE)) {
GlobalConfig.ASTERIX_LOGGER.fine(compiled.toJSON().toString(1));
}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.1.ddl.sqlpp
new file mode 100644
index 0000000..63c275b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.1.ddl.sqlpp
@@ -0,0 +1,23 @@
+/*
+ * 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 function foo@0 if exists;
+CREATE function foo(){
+ 1
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.2.query.sqlpp
new file mode 100644
index 0000000..4664ffe
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.2.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 foo();
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.3.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.3.ddl.sqlpp
new file mode 100644
index 0000000..b515477
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.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.
+ */
+
+DROP function foo@0;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/default/default.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/default/default.2.adm
new file mode 100644
index 0000000..893f10e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/default/default.2.adm
@@ -0,0 +1 @@
+{ "$1": 1 }
\ No newline at end of file
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java
index 2bc78a1..4a03eef 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java
@@ -96,13 +96,15 @@
if (declaredFunctions != null && declaredFunctions.contains(signature)) {
continue;
}
- String dataverseName = signature.getNamespace() == null ? metadataProvider.getDefaultDataverseName()
- : signature.getNamespace();
+ if (signature.getNamespace() == null) {
+ signature.setNamespace(metadataProvider.getDefaultDataverseName());
+ }
+ String namespace = signature.getNamespace();
// Checks the existence of the referred dataverse.
- if (metadataProvider.findDataverse(dataverseName) == null
- && !dataverseName.equals(FunctionConstants.ASTERIX_NS)) {
- throw new AsterixException("In function call \"" + dataverseName + "." + signature.getName()
- + "(...)\", the dataverse \"" + dataverseName + "\" cannot be found!");
+ if (metadataProvider.findDataverse(namespace) == null
+ && !namespace.equals(FunctionConstants.ASTERIX_NS)) {
+ throw new AsterixException("In function call \"" + namespace + "." + signature.getName()
+ + "(...)\", the dataverse \"" + namespace + "\" cannot be found!");
}
Function function = lookupUserDefinedFunctionDecl(metadataProvider.getMetadataTxnContext(), signature);
if (function == null) {