[NO ISSUE][COMP] Add IParser.parseMultipartIdentifier()

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

Details:
- Add helper method IParser.parseMultipartIdentifier()
  to parse multi-part identifiers

Change-Id: Ic142e30934c8762d5e3ffd9cbfaf62d15012c5aa
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/8443
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/DataverseNameParserTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/DataverseNameParserTest.java
index 1cd41ae..0d4d611 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/DataverseNameParserTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/DataverseNameParserTest.java
@@ -23,23 +23,15 @@
 
 import org.apache.asterix.common.metadata.DataverseName;
 import org.apache.asterix.common.metadata.DataverseNameTest;
-import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.IParser;
 import org.apache.asterix.lang.common.base.IParserFactory;
-import org.apache.asterix.lang.common.base.IRewriterFactory;
-import org.apache.asterix.lang.common.base.IStatementRewriter;
-import org.apache.asterix.lang.common.expression.FieldAccessor;
-import org.apache.asterix.lang.common.expression.VariableExpr;
 import org.apache.asterix.lang.sqlpp.parser.SqlppParserFactory;
-import org.apache.asterix.lang.sqlpp.rewrites.SqlppRewriterFactory;
 import org.junit.Assert;
 
 public class DataverseNameParserTest extends DataverseNameTest {
 
     private final IParserFactory parserFactory = new SqlppParserFactory();
 
-    private final IRewriterFactory rewriterFactory = new SqlppRewriterFactory(parserFactory);
-
     @Override
     protected void testDataverseNameImpl(DataverseName dataverseName, List<String> parts, String expectedCanonicalForm,
             String expectedDisplayForm) throws Exception {
@@ -49,22 +41,14 @@
 
         // check parse-ability of the display form
         IParser parser = parserFactory.createParser(displayForm);
-        Expression expr = parser.parseExpression();
-        IStatementRewriter rewriter = rewriterFactory.createStatementRewriter();
+        List<String> parsedParts = parser.parseMultipartIdentifier();
 
-        for (int i = parts.size() - 1; i >= 0; i--) {
+        int partCount = parts.size();
+        Assert.assertEquals("Unexpected parsed part count: " + parsedParts.size(), partCount, parsedParts.size());
+
+        for (int i = 0; i < partCount; i++) {
             String part = parts.get(i);
-            String parsedPart;
-            if (i > 0) {
-                Assert.assertEquals(Expression.Kind.FIELD_ACCESSOR_EXPRESSION, expr.getKind());
-                FieldAccessor faExpr = (FieldAccessor) expr;
-                parsedPart = faExpr.getIdent().getValue();
-                expr = faExpr.getExpr();
-            } else {
-                Assert.assertEquals(Expression.Kind.VARIABLE_EXPRESSION, expr.getKind());
-                VariableExpr varExpr = (VariableExpr) expr;
-                parsedPart = rewriter.toFunctionParameterName(varExpr.getVar());
-            }
+            String parsedPart = parsedParts.get(i);
             Assert.assertEquals("unexpected parsed part at position " + i + " in " + parts, part, parsedPart);
         }
     }
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IParser.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IParser.java
index bd05f28..86c4b1c 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IParser.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IParser.java
@@ -32,6 +32,8 @@
 
     Expression parseExpression() throws CompilationException;
 
+    List<String> parseMultipartIdentifier() throws CompilationException;
+
     FunctionDecl parseFunctionBody(FunctionSignature signature, List<String> paramNames) throws CompilationException;
 
     /**
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index bc0c1c2..5172020 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -359,6 +359,16 @@
     }
 
     @Override
+    public List<String> parseMultipartIdentifier() throws CompilationException {
+        return parseImpl(new ParseFunction<List<String>>() {
+            @Override
+            public List<String> parse() throws ParseException {
+                return SQLPPParser.this.MultipartIdentifier();
+            }
+        });
+    }
+
+    @Override
     public FunctionDecl parseFunctionBody(FunctionSignature signature, List<String> paramNames)
       throws CompilationException {
         return parseImpl(new ParseFunction<FunctionDecl>() {