Repository: asterixdb
Updated Branches:
  refs/heads/master c6ee017f5 -> e3e49c174


ASTERIXDB-1695 Fix Functions in Default Dataverse

Change-Id: I7f08c0acaccdcfaeb4fc9cfb1529214b543d0e86
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1297
Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyin...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/e3e49c17
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/e3e49c17
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/e3e49c17

Branch: refs/heads/master
Commit: e3e49c174708ca2bd0ae08b0c5785d4d2938ef85
Parents: c6ee017
Author: Abdullah Alamoudi <bamou...@gmail.com>
Authored: Tue Oct 18 18:09:10 2016 -0700
Committer: abdullah alamoudi <bamou...@gmail.com>
Committed: Tue Oct 18 22:20:39 2016 -0700

----------------------------------------------------------------------
 .../asterix/app/translator/QueryTranslator.java | 10 +++++----
 .../types/default/default.1.ddl.sqlpp           | 23 ++++++++++++++++++++
 .../types/default/default.2.query.sqlpp         | 20 +++++++++++++++++
 .../types/default/default.3.ddl.sqlpp           | 20 +++++++++++++++++
 .../results/types/default/default.2.adm         |  1 +
 .../asterix/lang/common/util/FunctionUtil.java  | 14 +++++++-----
 6 files changed, 78 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/e3e49c17/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
----------------------------------------------------------------------
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 @@ public class QueryTranslator extends 
AbstractLangTranslator implements IStatemen
             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 @@ public class QueryTranslator extends 
AbstractLangTranslator implements IStatemen
     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 @@ public class QueryTranslator extends 
AbstractLangTranslator implements IStatemen
     @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 @@ public class QueryTranslator extends 
AbstractLangTranslator implements IStatemen
      */
     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 @@ public class QueryTranslator extends 
AbstractLangTranslator implements IStatemen
 
     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 @@ public class QueryTranslator extends 
AbstractLangTranslator implements IStatemen
 
     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));
         }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/e3e49c17/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.1.ddl.sqlpp
----------------------------------------------------------------------
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

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/e3e49c17/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.2.query.sqlpp
----------------------------------------------------------------------
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

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/e3e49c17/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.3.ddl.sqlpp
----------------------------------------------------------------------
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

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/e3e49c17/asterixdb/asterix-app/src/test/resources/runtimets/results/types/default/default.2.adm
----------------------------------------------------------------------
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

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/e3e49c17/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java
----------------------------------------------------------------------
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 @@ public class FunctionUtil {
             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) {

Reply via email to