Merge branch 'raman/master_issue_489'
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-issue489/query-issue489.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-issue489/query-issue489.1.ddl.aql
new file mode 100644
index 0000000..93b9131
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-issue489/query-issue489.1.ddl.aql
@@ -0,0 +1,20 @@
+/*
+ * Description  : This test case is to verify the fix for issue 489
+ 	          https://code.google.com/p/asterixdb/issues/detail?id=489
+ * Expected Res : Success
+ * Date         : 31st May 2013
+ */
+ 
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create function f1()
+{
+"function with no input"
+}
+
+create function f1($a)
+{
+"function with input"
+}
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-issue489/query-issue489.2.query.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-issue489/query-issue489.2.query.aql
new file mode 100644
index 0000000..4dcf6e6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-issue489/query-issue489.2.query.aql
@@ -0,0 +1,12 @@
+/*
+ * Description  : This test case is to verify the fix for issue 489
+ 	          https://code.google.com/p/asterixdb/issues/detail?id=489
+ * Expected Res : Success
+ * Date         : 31st May 2013
+ */
+
+count(
+for $x in dataset Metadata.Function
+where $x.DataverseName='test'
+return $x
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-issue489/query-issue489.3.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-issue489/query-issue489.3.ddl.aql
new file mode 100644
index 0000000..867ae7a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-issue489/query-issue489.3.ddl.aql
@@ -0,0 +1,10 @@
+/*
+ * Description  : This test case is to verify the fix for issue 489
+ 	          https://code.google.com/p/asterixdb/issues/detail?id=489
+ * Expected Res : Success
+ * Date         : 31st May 2013
+ */
+ 
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-issue489/query-issue489.4.query.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-issue489/query-issue489.4.query.aql
new file mode 100644
index 0000000..4dcf6e6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-issue489/query-issue489.4.query.aql
@@ -0,0 +1,12 @@
+/*
+ * Description  : This test case is to verify the fix for issue 489
+ 	          https://code.google.com/p/asterixdb/issues/detail?id=489
+ * Expected Res : Success
+ * Date         : 31st May 2013
+ */
+
+count(
+for $x in dataset Metadata.Function
+where $x.DataverseName='test'
+return $x
+)
diff --git a/asterix-app/src/test/resources/runtimets/results/user-defined-functions/query-issue489/query-issue489.2.adm b/asterix-app/src/test/resources/runtimets/results/user-defined-functions/query-issue489/query-issue489.2.adm
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/user-defined-functions/query-issue489/query-issue489.2.adm
@@ -0,0 +1 @@
+2
diff --git a/asterix-app/src/test/resources/runtimets/results/user-defined-functions/query-issue489/query-issue489.4.adm b/asterix-app/src/test/resources/runtimets/results/user-defined-functions/query-issue489/query-issue489.4.adm
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/user-defined-functions/query-issue489/query-issue489.4.adm
@@ -0,0 +1 @@
+0
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index 0f3e005..2b68a40 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -3972,6 +3972,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="user-defined-functions">
+      <compilation-unit name="query-issue489">
+        <output-dir compare="Text">query-issue489</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="user-defined-functions">
       <compilation-unit name="udf01">
         <output-dir compare="Text">udf01</output-dir>
       </compilation-unit>
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/MetadataNode.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/MetadataNode.java
index 5aca7c4..4daf8b5 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/MetadataNode.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/MetadataNode.java
@@ -265,7 +265,7 @@
         ILSMIndex lsmIndex = (ILSMIndex) indexLifecycleManager.getIndex(resourceID);
         indexLifecycleManager.open(resourceID);
 
-        //prepare a Callback for logging
+        // prepare a Callback for logging
         IModificationOperationCallback modCallback = createIndexModificationCallback(jobId, resourceID, metadataIndex,
                 lsmIndex, IndexOperation.INSERT);
 
@@ -376,7 +376,8 @@
                         searchKey);
                 deleteTupleFromIndex(jobId, MetadataPrimaryIndexes.DATASET_DATASET, datasetTuple);
             } catch (TreeIndexException tie) {
-                //ignore this exception and continue deleting all relevant artifacts. 
+                // ignore this exception and continue deleting all relevant
+                // artifacts.
             }
 
             // Delete entry from secondary index 'group'.
@@ -390,7 +391,8 @@
                             MetadataSecondaryIndexes.GROUPNAME_ON_DATASET_INDEX, groupNameSearchKey);
                     deleteTupleFromIndex(jobId, MetadataSecondaryIndexes.GROUPNAME_ON_DATASET_INDEX, groupNameTuple);
                 } catch (TreeIndexException tie) {
-                    //ignore this exception and continue deleting all relevant artifacts.
+                    // ignore this exception and continue deleting all relevant
+                    // artifacts.
                 }
             }
             // Delete entry from secondary index 'type'.
@@ -402,7 +404,8 @@
                         MetadataSecondaryIndexes.DATATYPENAME_ON_DATASET_INDEX, dataTypeSearchKey);
                 deleteTupleFromIndex(jobId, MetadataSecondaryIndexes.DATATYPENAME_ON_DATASET_INDEX, dataTypeTuple);
             } catch (TreeIndexException tie) {
-                //ignore this exception and continue deleting all relevant artifacts.
+                // ignore this exception and continue deleting all relevant
+                // artifacts.
             }
 
             // Delete entry(s) from the 'indexes' dataset.
@@ -502,7 +505,8 @@
             // Searches the index for the tuple to be deleted. Acquires an S
             // lock on the 'datatype' dataset.
             ITupleReference tuple = getTupleToBeDeleted(jobId, MetadataPrimaryIndexes.DATATYPE_DATASET, searchKey);
-            // This call uses the secondary index on datatype. Get nested types before deleting entry from secondary index.
+            // This call uses the secondary index on datatype. Get nested types
+            // before deleting entry from secondary index.
             List<String> nestedTypes = getNestedDatatypeNames(jobId, dataverseName, datatypeName);
             deleteTupleFromIndex(jobId, MetadataPrimaryIndexes.DATATYPE_DATASET, tuple);
             deleteFromDatatypeSecondaryIndex(jobId, dataverseName, datatypeName);
@@ -568,7 +572,7 @@
         long resourceID = metadataIndex.getResourceID();
         ILSMIndex lsmIndex = (ILSMIndex) indexLifecycleManager.getIndex(resourceID);
         indexLifecycleManager.open(resourceID);
-        //prepare a Callback for logging
+        // prepare a Callback for logging
         IModificationOperationCallback modCallback = createIndexModificationCallback(jobId, resourceID, metadataIndex,
                 lsmIndex, IndexOperation.DELETE);
         IIndexAccessor indexAccessor = lsmIndex.createAccessor(modCallback, NoOpOperationCallback.INSTANCE);
@@ -822,7 +826,8 @@
         }
         try {
             // Delete entry from the 'function' dataset.
-            ITupleReference searchKey = createTuple(functionSignature.getNamespace(), functionSignature.getName());
+            ITupleReference searchKey = createTuple(functionSignature.getNamespace(), functionSignature.getName(), ""
+                    + functionSignature.getArity());
             // Searches the index for the tuple to be deleted. Acquires an S
             // lock on the 'function' dataset.
             ITupleReference datasetTuple = getTupleToBeDeleted(jobId, MetadataPrimaryIndexes.FUNCTION_DATASET,
@@ -853,7 +858,7 @@
         return results.get(0);
     }
 
-    //Debugging Method
+    // Debugging Method
     public String printMetadata() {
 
         StringBuilder sb = new StringBuilder();