[NO ISSUE][COMP] Change default for synonym's target object dataverse

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- If target object dataverse is not specified in CREATE SYNONYM
  statement then it should be set to the synonym's dataverse

Change-Id: I809900aa47a4d8ded2177e51b2ddba4a107f734b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/10726
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@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 64d0fd7..ab682c1 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
@@ -2639,7 +2639,8 @@
         CreateSynonymStatement css = (CreateSynonymStatement) stmt;
         DataverseName dataverseName = getActiveDataverseName(css.getDataverseName());
         String synonymName = css.getSynonymName();
-        DataverseName objectDataverseName = getActiveDataverseName(css.getObjectDataverseName());
+        DataverseName objectDataverseName =
+                css.getObjectDataverseName() != null ? css.getObjectDataverseName() : dataverseName;
         String objectName = css.getObjectName();
         lockUtil.createSynonymBegin(lockManager, metadataProvider.getLocks(), dataverseName, synonymName);
         try {
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/synonym/synonym-03/synonym-03.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/synonym/synonym-03/synonym-03.1.ddl.sqlpp
new file mode 100644
index 0000000..33397c9
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/synonym/synonym-03/synonym-03.1.ddl.sqlpp
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+/*
+ * Test that if the target object's dataverse is not specified then
+ * it defaults to the synonym's dataverse
+ */
+
+drop dataverse test1 if exists;
+create dataverse test1;
+
+drop  dataverse test2 if exists;
+create  dataverse test2;
+
+use test1;
+
+create synonym test2.md_syn_1 for `Metadata`.`Synonym`;
+
+create synonym test2.md_syn_2 for md_syn_1;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/synonym/synonym-03/synonym-03.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/synonym/synonym-03/synonym-03.2.query.sqlpp
new file mode 100644
index 0000000..8e0aaf9
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/synonym/synonym-03/synonym-03.2.query.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.
+ */
+
+select DataverseName, SynonymName, ObjectDataverseName, ObjectName
+from test2.md_syn_2
+where DataverseName like "test%"
+order by SynonymName;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/synonym/synonym-03/synonym-03.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/synonym/synonym-03/synonym-03.2.adm
new file mode 100644
index 0000000..32200e3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/synonym/synonym-03/synonym-03.2.adm
@@ -0,0 +1,2 @@
+{ "DataverseName": "test2", "SynonymName": "md_syn_1", "ObjectDataverseName": "Metadata", "ObjectName": "Synonym" }
+{ "DataverseName": "test2", "SynonymName": "md_syn_2", "ObjectDataverseName": "test2", "ObjectName": "md_syn_1" }
\ 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 7050d49..9dc621d 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -10475,6 +10475,11 @@
         <expected-error>ASX1063: Cannot find dataverse with name UNKNOWN_DATAVERSE</expected-error>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="synonym">
+      <compilation-unit name="synonym-03">
+        <output-dir compare="Text">synonym-03</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="tokenizers">
     <test-case FilePath="tokenizers">
diff --git a/asterixdb/asterix-doc/src/main/markdown/sqlpp/7_ddl_dml.md b/asterixdb/asterix-doc/src/main/markdown/sqlpp/7_ddl_dml.md
index e064f06..f32d603 100644
--- a/asterixdb/asterix-doc/src/main/markdown/sqlpp/7_ddl_dml.md
+++ b/asterixdb/asterix-doc/src/main/markdown/sqlpp/7_ddl_dml.md
@@ -437,8 +437,9 @@
 ![](../images/diagrams/CreateSynonym.png)
 
 The `CREATE SYNONYM` statement creates a synonym for a given dataset.
-This synonym may be used used instead of the dataset name in `SELECT`, `INSERT`, `UPSERT`, `DELETE`, and `LOAD` statements.
+This synonym may be used instead of the dataset name in `SELECT`, `INSERT`, `UPSERT`, `DELETE`, and `LOAD` statements.
 The target dataset does not need to exist when the synonym is created.
+A synonym may be created for another synonym.
 
 ##### Example