abdullah alamoudi has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/1297

Change subject: ASTERIXDB-1695 Fix Functions in Default Dataverse
......................................................................

ASTERIXDB-1695 Fix Functions in Default Dataverse

Change-Id: I7f08c0acaccdcfaeb4fc9cfb1529214b543d0e86
---
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.1.ddl.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.2.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/default/default.3.ddl.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/types/default/default.2.adm
M 
asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java
6 files changed, 73 insertions(+), 4 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/97/1297/1

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..31ec9eb 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
@@ -93,6 +93,9 @@
         boolean includePrivateFunctions = (value != null) ? 
Boolean.valueOf(value.toLowerCase()) : false;
         Set<FunctionSignature> functionCalls = 
functionCollector.getFunctionCalls(expression);
         for (FunctionSignature signature : functionCalls) {
+            if(signature.getNamespace() == null){
+                
signature.setNamespace(metadataProvider.getDefaultDataverseName());
+            }
             if (declaredFunctions != null && 
declaredFunctions.contains(signature)) {
                 continue;
             }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1297
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7f08c0acaccdcfaeb4fc9cfb1529214b543d0e86
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: abdullah alamoudi <bamou...@gmail.com>

Reply via email to