You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by AsterixDB Code Review <do...@vitalstatistix.ics.uci.edu> on 2019/11/26 22:35:56 UTC

Change in asterixdb[master]: [NO ISSUE][SQLPP] Refactor SQL++ grammar

From Dmitry Lychagin <dm...@couchbase.com>:

Dmitry Lychagin has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/4365 )


Change subject: [NO ISSUE][SQLPP] Refactor SQL++ grammar
......................................................................

[NO ISSUE][SQLPP] Refactor SQL++ grammar

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

Details:
- Refactor SQL++ grammar for better extensibility

Change-Id: Ief23b91a18cd2e3dc6015d91ced1f1f22a2aacec
---
M asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
1 file changed, 478 insertions(+), 226 deletions(-)



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

diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index 13cebb6..7672c56 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -578,20 +578,31 @@
 {
   <CREATE> { startToken = token; }
   (
-    stmt = TypeSpecification(startToken)
-    | stmt = NodegroupSpecification(startToken)
-    | stmt = DatasetSpecification(startToken)
-    | stmt = IndexSpecification(startToken)
-    | stmt = DataverseSpecification(startToken)
-    | stmt = FunctionSpecification(startToken)
-    | stmt = FeedSpecification(startToken)
-    | stmt = FeedPolicySpecification(startToken)
+    stmt = CreateTypeStatement(startToken)
+    | stmt = CreateNodegroupStatement(startToken)
+    | stmt = CreateDatasetStatement(startToken)
+    | stmt = CreateIndexStatement(startToken)
+    | stmt = CreateDataverseStatement(startToken)
+    | stmt = CreateFunctionStatement(startToken)
+    | stmt = CreateFeedStatement(startToken)
+    | stmt = CreateFeedPolicyStatement(startToken)
   )
   {
     return stmt;
   }
 }
 
+TypeDecl CreateTypeStatement(Token startStmtToken) throws ParseException:
+{
+  TypeDecl stmt = null;
+}
+{
+  <TYPE> stmt = TypeSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
 TypeDecl TypeSpecification(Token startStmtToken) throws ParseException:
 {
   Pair<DataverseName,Identifier> nameComponents = null;
@@ -599,28 +610,39 @@
   TypeExpression typeExpr = null;
 }
 {
-  <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists()
+  nameComponents = TypeName() ifNotExists = IfNotExists()
   <AS> typeExpr = RecordTypeDef()
-    {
-      boolean dgen = false;
-      long numValues = -1;
-      String filename = null;
-      Token hintToken = fetchHint(startStmtToken, SqlppHint.DGEN_HINT);
-      if (hintToken != null) {
-          String hintParams = hintToken.hintParams;
-          String[] splits = hintParams != null ? hintParams.split("\\s+") : null;
-          if (splits == null || splits.length != 2) {
-            throw new SqlppParseException(getSourceLocation(hintToken),
-              "Expecting /*+ dgen <filename> <numberOfItems> */");
-          }
-          dgen = true;
-          filename = splits[0];
-          numValues = Long.parseLong(splits[1]);
-      }
-      TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
-      TypeDecl stmt = new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
-      return addSourceLocation(stmt, startStmtToken);
+  {
+    boolean dgen = false;
+    long numValues = -1;
+    String filename = null;
+    Token hintToken = fetchHint(startStmtToken, SqlppHint.DGEN_HINT);
+    if (hintToken != null) {
+        String hintParams = hintToken.hintParams;
+        String[] splits = hintParams != null ? hintParams.split("\\s+") : null;
+        if (splits == null || splits.length != 2) {
+          throw new SqlppParseException(getSourceLocation(hintToken),
+            "Expecting /*+ dgen <filename> <numberOfItems> */");
+        }
+        dgen = true;
+        filename = splits[0];
+        numValues = Long.parseLong(splits[1]);
     }
+    TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
+    TypeDecl stmt = new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+NodegroupDecl CreateNodegroupStatement(Token startStmtToken) throws ParseException:
+{
+  NodegroupDecl stmt = null;
+}
+{
+  <NODEGROUP> stmt = NodegroupSpecification(startStmtToken)
+  {
+    return stmt;
+  }
 }
 
 NodegroupDecl NodegroupSpecification(Token startStmtToken) throws ParseException:
@@ -628,24 +650,44 @@
   String name = null;
   String tmp = null;
   boolean ifNotExists = false;
-  List<Identifier>ncNames = null;
+  List<Identifier> ncNames = new ArrayList<Identifier>();
 }
 {
-  <NODEGROUP> name = Identifier()
-  ifNotExists = IfNotExists() <ON> tmp = Identifier()
-    {
-      ncNames = new ArrayList<Identifier>();
-      ncNames.add(new Identifier(tmp));
-    }
+  name = Identifier() ifNotExists = IfNotExists()
+  <ON> tmp = Identifier()
+  {
+    ncNames.add(new Identifier(tmp));
+  }
   ( <COMMA> tmp = Identifier()
     {
       ncNames.add(new Identifier(tmp));
     }
   )*
-    {
-      NodegroupDecl stmt = new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
-      return addSourceLocation(stmt, startStmtToken);
-    }
+  {
+    NodegroupDecl stmt = new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+void Dataset() throws ParseException:
+{
+}
+{
+    (<DATASET>|<COLLECTION>)
+}
+
+DatasetDecl CreateDatasetStatement(Token startStmtToken) throws ParseException:
+{
+  DatasetDecl stmt = null;
+}
+{
+  (
+    (<INTERNAL>)? Dataset() stmt = DatasetSpecification(startStmtToken)
+    | <EXTERNAL> Dataset() stmt = ExternalDatasetSpecification(startStmtToken)
+  )
+  {
+    return stmt;
+  }
 }
 
 DatasetDecl DatasetSpecification(Token startStmtToken) throws ParseException:
@@ -666,88 +708,81 @@
   RecordConstructor withRecord = null;
 }
 {
+  nameComponents = QualifiedName()
+  <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
   (
-    <EXTERNAL> Dataset() nameComponents = QualifiedName()
-    <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
-    ifNotExists = IfNotExists()
-    <USING> adapterName = AdapterName() properties = Configuration()
-    ( <ON> nodeGroupName = Identifier() )?
-    ( <HINTS> hints = Properties() )?
-    ( <WITH> withRecord = RecordConstructor() )?
-      {
-        ExternalDetailsDecl edd = new ExternalDetailsDecl();
-        edd.setAdapter(adapterName);
-        edd.setProperties(properties);
-        try{
-        stmt = new DatasetDecl(nameComponents.first,
-                                   nameComponents.second,
-                                   typeComponents.first,
-                                   typeComponents.second,
-                                   metaTypeComponents.first,
-                                   metaTypeComponents.second,
-                                   nodeGroupName != null? new Identifier(nodeGroupName): null,
-                                   hints,
-                                   DatasetType.EXTERNAL,
-                                   edd,
-                                   withRecord,
-                                   ifNotExists);
-        } catch (CompilationException e){
-           throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
-        }
-      }
-
-    | ( <INTERNAL> )?
-    Dataset() nameComponents = QualifiedName()
-    <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
-    (
-        { String name; }
-        <WITH>
-        name = Identifier()
-        {
-            if (!name.equalsIgnoreCase("meta")){
-                throw new SqlppParseException(getSourceLocation(startStmtToken),
-                    "We can only support one additional associated field called \"meta\".");
-            }
-        }
-        <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
-    )?
-    ifNotExists = IfNotExists()
-    primaryKeyFields = PrimaryKey()
-    (<AUTOGENERATED> { autogenerated = true; } )?
-    (<ON> nodeGroupName = Identifier() )?
-    ( <HINTS> hints = Properties() )?
-    ( LOOKAHEAD(2) <WITH> <FILTER> <ON>  filterField = NestedField() )?
-    ( <WITH> withRecord = RecordConstructor() )?
-      {
-        if(filterField!=null && filterField.first!=0){
-          throw new SqlppParseException(getSourceLocation(startStmtToken),
-            "A filter field can only be a field in the main record of the dataset.");
-        }
-        InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
-                                                          primaryKeyFields.first,
-                                                          autogenerated,
-                                                          filterField == null? null : filterField.second);
-        try{
-        stmt = new DatasetDecl(nameComponents.first,
-                                   nameComponents.second,
-                                   typeComponents.first,
-                                   typeComponents.second,
-                                   metaTypeComponents.first,
-                                   metaTypeComponents.second,
-                                   nodeGroupName != null ? new Identifier(nodeGroupName) : null,
-                                   hints,
-                                   DatasetType.INTERNAL,
-                                   idd,
-                                   withRecord,
-                                   ifNotExists);
-        } catch (CompilationException e){
-           throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
-        }
-      }
-  )
+    { String name; }
+    <WITH>
+    name = Identifier()
     {
-      return addSourceLocation(stmt, startStmtToken);
+        if (!name.equalsIgnoreCase("meta")){
+            throw new SqlppParseException(getSourceLocation(startStmtToken),
+                "We can only support one additional associated field called \"meta\".");
+        }
     }
+    <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
+  )?
+  ifNotExists = IfNotExists()
+  primaryKeyFields = PrimaryKey()
+  (<AUTOGENERATED> { autogenerated = true; } )?
+  (<ON> nodeGroupName = Identifier() )?
+  ( <HINTS> hints = Properties() )?
+  ( LOOKAHEAD(2) <WITH> <FILTER> <ON>  filterField = NestedField() )?
+  ( <WITH> withRecord = RecordConstructor() )?
+  {
+    if(filterField!=null && filterField.first!=0){
+      throw new SqlppParseException(getSourceLocation(startStmtToken),
+        "A filter field can only be a field in the main record of the dataset.");
+    }
+    InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second, primaryKeyFields.first, autogenerated,
+      filterField == null? null : filterField.second);
+    try {
+      stmt = new DatasetDecl(nameComponents.first, nameComponents.second, typeComponents.first, typeComponents.second,
+        metaTypeComponents.first, metaTypeComponents.second,
+        nodeGroupName != null ? new Identifier(nodeGroupName) : null, hints, DatasetType.INTERNAL, idd, withRecord,
+        ifNotExists);
+      return addSourceLocation(stmt, startStmtToken);
+    } catch (CompilationException e) {
+       throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
+    }
+  }
+}
+
+DatasetDecl ExternalDatasetSpecification(Token startStmtToken) throws ParseException:
+{
+  Pair<DataverseName,Identifier> nameComponents = null;
+  boolean ifNotExists = false;
+  Pair<DataverseName,Identifier> typeComponents = null;
+  String adapterName = null;
+  Map<String,String> properties = null;
+  String nodeGroupName = null;
+  Map<String,String> hints = new HashMap<String,String>();
+  DatasetDecl stmt = null;
+  Pair<DataverseName,Identifier> metaTypeComponents = new Pair<DataverseName, Identifier>(null, null);
+  RecordConstructor withRecord = null;
+}
+{
+  nameComponents = QualifiedName()
+  <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
+  ifNotExists = IfNotExists()
+  <USING> adapterName = AdapterName() properties = Configuration()
+  ( <ON> nodeGroupName = Identifier() )?
+  ( <HINTS> hints = Properties() )?
+  ( <WITH> withRecord = RecordConstructor() )?
+  {
+    ExternalDetailsDecl edd = new ExternalDetailsDecl();
+    edd.setAdapter(adapterName);
+    edd.setProperties(properties);
+    try {
+      stmt = new DatasetDecl(nameComponents.first, nameComponents.second, typeComponents.first, typeComponents.second,
+        metaTypeComponents.first, metaTypeComponents.second,
+        nodeGroupName != null? new Identifier(nodeGroupName): null, hints, DatasetType.EXTERNAL, edd, withRecord,
+        ifNotExists);
+      return addSourceLocation(stmt, startStmtToken);
+    } catch (CompilationException e) {
+       throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
+    }
+  }
 }
 
 RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
@@ -757,13 +792,27 @@
   String datasetName = null;
 }
 {
-    <REFRESH> { startToken = token; } <EXTERNAL> Dataset() nameComponents = QualifiedName()
-    {
-      RefreshExternalDatasetStatement stmt = new RefreshExternalDatasetStatement();
-      stmt.setDataverseName(nameComponents.first);
-      stmt.setDatasetName(nameComponents.second);
-      return addSourceLocation(stmt, startToken);
-    }
+  <REFRESH> { startToken = token; } <EXTERNAL> Dataset() nameComponents = QualifiedName()
+  {
+    RefreshExternalDatasetStatement stmt = new RefreshExternalDatasetStatement();
+    stmt.setDataverseName(nameComponents.first);
+    stmt.setDatasetName(nameComponents.second);
+    return addSourceLocation(stmt, startToken);
+  }
+}
+
+CreateIndexStatement CreateIndexStatement(Token startStmtToken) throws ParseException:
+{
+  CreateIndexStatement stmt = null;
+}
+{
+  (
+    <INDEX> stmt = IndexSpecification(startStmtToken)
+    | <PRIMARY> <INDEX> stmt = PrimaryIndexSpecification(startStmtToken)
+  )
+  {
+    return stmt;
+  }
 }
 
 CreateIndexStatement IndexSpecification(Token startStmtToken) throws ParseException:
@@ -775,12 +824,10 @@
   Pair<Integer, Pair<List<String>, IndexedTypeExpression>> fieldPair = null;
   IndexParams indexType = null;
   boolean enforced = false;
-  boolean isPrimaryIdx = false;
 }
 {
   (
-    (<INDEX> indexName = Identifier()
-    ifNotExists = IfNotExists()
+    indexName = Identifier() ifNotExists = IfNotExists()
     <ON> nameComponents = QualifiedName()
     <LEFTPAREN> ( fieldPair = OpenField()
       {
@@ -792,19 +839,9 @@
         stmt.addFieldExprPair(fieldPair.second);
         stmt.addFieldIndexIndicator(fieldPair.first);
       }
-    )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?)
-    |
-    (<PRIMARY> <INDEX> {isPrimaryIdx = true;}
-      (
-        (indexName = Identifier())? ifNotExists = IfNotExists()
-      )
-      <ON> nameComponents = QualifiedName() (<TYPE> <BTREE>)?
-    )
+    )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?
   )
   {
-    if (isPrimaryIdx && indexName == null) {
-      indexName = "primary_idx_" + nameComponents.second;
-    }
     stmt.setIndexName(new Identifier(indexName));
     stmt.setIfNotExists(ifNotExists);
     stmt.setDataverseName(nameComponents.first);
@@ -818,6 +855,28 @@
   }
 }
 
+CreateIndexStatement PrimaryIndexSpecification(Token startStmtToken) throws ParseException:
+{
+  CreateIndexStatement stmt = new CreateIndexStatement();
+  String indexName = null;
+  boolean ifNotExists = false;
+  Pair<DataverseName,Identifier> nameComponents = null;
+}
+{
+  (indexName = Identifier())? ifNotExists = IfNotExists()
+  <ON> nameComponents = QualifiedName() (<TYPE> <BTREE>)?
+  {
+    if (indexName == null) {
+      indexName = "primary_idx_" + nameComponents.second;
+    }
+    stmt.setIndexName(new Identifier(indexName));
+    stmt.setIfNotExists(ifNotExists);
+    stmt.setDataverseName(nameComponents.first);
+    stmt.setDatasetName(nameComponents.second);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
 String CompactionPolicy() throws ParseException :
 {
   String compactionPolicy = null;
@@ -873,18 +932,39 @@
     }
 }
 
+CreateDataverseStatement CreateDataverseStatement(Token startStmtToken) throws ParseException :
+{
+  CreateDataverseStatement stmt = null;
+}
+{
+  <DATAVERSE> stmt = DataverseSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
 CreateDataverseStatement DataverseSpecification(Token startStmtToken) throws ParseException :
 {
   List<String> dvName = null;
   boolean ifNotExists = false;
 }
 {
-  <DATAVERSE> dvName = MultipartIdentifier()
-  ifNotExists = IfNotExists()
-    {
-      CreateDataverseStatement stmt = new CreateDataverseStatement(DataverseName.create(dvName), null, ifNotExists);
-      return addSourceLocation(stmt, startStmtToken);
-    }
+  dvName = MultipartIdentifier() ifNotExists = IfNotExists()
+  {
+    CreateDataverseStatement stmt = new CreateDataverseStatement(DataverseName.create(dvName), null, ifNotExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+CreateFunctionStatement CreateFunctionStatement(Token startStmtToken) throws ParseException:
+{
+  CreateFunctionStatement stmt = null;
+}
+{
+  <FUNCTION> stmt = FunctionSpecification(startStmtToken)
+  {
+    return stmt;
+  }
 }
 
 CreateFunctionStatement FunctionSpecification(Token startStmtToken) throws ParseException:
@@ -903,7 +983,7 @@
   createNewScope();
 }
 {
-  <FUNCTION> fctName = FunctionName()
+  fctName = FunctionName()
   {
      defaultDataverse = fctName.dataverse;
   }
@@ -915,17 +995,28 @@
   }
   (functionBodyExpr = SelectExpression(true) | functionBodyExpr = Expression())
   <RIGHTBRACE>
-    {
-      endPos = token;
-      functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
-      // TODO use fctName.library
-      signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
-      getCurrentScope().addFunctionDescriptor(signature, false);
-      removeCurrentScope();
-      defaultDataverse = currentDataverse;
-      CreateFunctionStatement stmt = new CreateFunctionStatement(signature, paramList, functionBody, functionBodyExpr, ifNotExists);
-      return addSourceLocation(stmt, startStmtToken);
-    }
+  {
+    endPos = token;
+    functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
+    // TODO use fctName.library
+    signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
+    getCurrentScope().addFunctionDescriptor(signature, false);
+    removeCurrentScope();
+    defaultDataverse = currentDataverse;
+    CreateFunctionStatement stmt = new CreateFunctionStatement(signature, paramList, functionBody, functionBodyExpr, ifNotExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+CreateFeedStatement CreateFeedStatement(Token startStmtToken) throws ParseException:
+{
+  CreateFeedStatement stmt = null;
+}
+{
+  <FEED> stmt = FeedSpecification(startStmtToken)
+  {
+    return stmt;
+  }
 }
 
 CreateFeedStatement FeedSpecification(Token startStmtToken) throws ParseException:
@@ -939,7 +1030,7 @@
   RecordConstructor withRecord = null;
 }
 {
-  <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
+  nameComponents = QualifiedName() ifNotExists = IfNotExists()
   <WITH> withRecord = RecordConstructor()
   {
     try {
@@ -951,6 +1042,17 @@
   }
 }
 
+CreateFeedPolicyStatement CreateFeedPolicyStatement(Token startStmtToken) throws ParseException:
+{
+  CreateFeedPolicyStatement stmt = null;
+}
+{
+  <INGESTION> <POLICY> stmt = FeedPolicySpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
 CreateFeedPolicyStatement FeedPolicySpecification(Token startStmtToken) throws ParseException:
 {
   String policyName = null;
@@ -962,23 +1064,20 @@
   CreateFeedPolicyStatement stmt = null;
 }
 {
-  (
-    <INGESTION> <POLICY>  policyName = Identifier() ifNotExists = IfNotExists()
-      <FROM>
-      (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = ConstantString())?
-      {
-        stmt = new CreateFeedPolicyStatement(policyName,
-                                   basePolicyName, properties, definition, ifNotExists);
-      }
-     | <PATH> sourcePolicyFile = ConstantString() (<DEFINITION> definition = ConstantString())?
-       {
-        stmt = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
-       }
-     )
-  )
+  policyName = Identifier() ifNotExists = IfNotExists()
+  <FROM>
+  (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = ConstantString())?
     {
-      return addSourceLocation(stmt, startStmtToken);
+      stmt = new CreateFeedPolicyStatement(policyName, basePolicyName, properties, definition, ifNotExists);
     }
+  | <PATH> sourcePolicyFile = ConstantString() (<DEFINITION> definition = ConstantString())?
+    {
+      stmt = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
+    }
+  )
+  {
+    return addSourceLocation(stmt, startStmtToken);
+  }
 }
 
 List<VarIdentifier> ParameterList() throws ParseException:
@@ -1024,10 +1123,10 @@
 }
 {
   <APPLY> <FUNCTION> functionName = FunctionName()
-    {
-       fqFunctionName = functionName.library == null ? functionName.function : functionName.library + "#" + functionName.function;
-       funcSigs.add(new FunctionSignature(functionName.dataverse, fqFunctionName, 1));
-    }
+  {
+     fqFunctionName = functionName.library == null ? functionName.function : functionName.library + "#" + functionName.function;
+     funcSigs.add(new FunctionSignature(functionName.dataverse, fqFunctionName, 1));
+  }
   (
       <COMMA> functionName = FunctionName()
       {
@@ -1094,52 +1193,214 @@
 Statement DropStatement() throws ParseException:
 {
   Token startToken = null;
-  String id = null;
-  List<String> multipartId = null;
-  Pair<DataverseName,Identifier> pairId = null;
-  Triple<DataverseName,Identifier,Identifier> tripleId = null;
-  FunctionSignature funcSig = null;
-  boolean ifExists = false;
-  AbstractStatement stmt = null;
+  Statement stmt = null;
 }
 {
   <DROP> { startToken = token; }
   (
-    Dataset() pairId = QualifiedName() ifExists = IfExists()
-      {
-        stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists);
-      }
-    | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists()
-      {
-        stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
-      }
-    | <NODEGROUP> id = Identifier() ifExists = IfExists()
-      {
-        stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
-      }
-    | <TYPE> pairId = TypeName() ifExists = IfExists()
-      {
-        stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
-      }
-    | <DATAVERSE> multipartId = MultipartIdentifier() ifExists = IfExists()
-      {
-        stmt = new DataverseDropStatement(DataverseName.create(multipartId), ifExists);
-      }
-    | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists()
-      {
-        stmt = new FunctionDropStatement(funcSig, ifExists);
-      }
-    | <FEED> pairId = QualifiedName() ifExists = IfExists()
-      {
-        stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
-      }
-    | <INGESTION> <POLICY> pairId = QualifiedName() ifExists = IfExists()
-      {
-        stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists);
-      }
+    stmt = DropDatasetStatement(startToken)
+    | stmt = DropIndexStatement(startToken)
+    | stmt = DropNodeGroupStatement(startToken)
+    | stmt = DropTypeStatement(startToken)
+    | stmt = DropDataverseStatement(startToken)
+    | stmt = DropFunctionStatement(startToken)
+    | stmt = DropFeedStatement(startToken)
+    | stmt = DropFeedPolicyStatement(startToken)
   )
   {
-    return addSourceLocation(stmt, startToken);
+    return stmt;
+  }
+}
+
+DropDatasetStatement DropDatasetStatement(Token startStmtToken) throws ParseException:
+{
+  DropDatasetStatement stmt = null;
+}
+{
+  Dataset() stmt = DropDatasetSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+DropDatasetStatement DropDatasetSpecification(Token startStmtToken) throws ParseException:
+{
+  Pair<DataverseName,Identifier> pairId = null;
+  boolean ifExists = false;
+}
+{
+  pairId = QualifiedName() ifExists = IfExists()
+  {
+    DropDatasetStatement stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+IndexDropStatement DropIndexStatement(Token startStmtToken) throws ParseException:
+{
+  IndexDropStatement stmt = null;
+}
+{
+  <INDEX> stmt = DropIndexSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+IndexDropStatement DropIndexSpecification(Token startStmtToken) throws ParseException:
+{
+  Triple<DataverseName,Identifier,Identifier> tripleId = null;
+  boolean ifExists = false;
+}
+{
+  tripleId = DoubleQualifiedName() ifExists = IfExists()
+  {
+    IndexDropStatement stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+NodeGroupDropStatement DropNodeGroupStatement(Token startStmtToken) throws ParseException:
+{
+  NodeGroupDropStatement stmt = null;
+}
+{
+  <NODEGROUP> stmt = DropNodeGroupSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+NodeGroupDropStatement DropNodeGroupSpecification(Token startStmtToken) throws ParseException:
+{
+  String id = null;
+  boolean ifExists = false;
+}
+{
+  id = Identifier() ifExists = IfExists()
+  {
+    NodeGroupDropStatement stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+TypeDropStatement DropTypeStatement(Token startStmtToken) throws ParseException:
+{
+  TypeDropStatement stmt = null;
+}
+{
+  <TYPE> stmt = DropTypeSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+TypeDropStatement DropTypeSpecification(Token startStmtToken) throws ParseException:
+{
+  Pair<DataverseName,Identifier> pairId = null;
+  boolean ifExists = false;
+}
+{
+  pairId = TypeName() ifExists = IfExists()
+  {
+    TypeDropStatement stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+DataverseDropStatement DropDataverseStatement(Token startStmtToken) throws ParseException:
+{
+  DataverseDropStatement stmt = null;
+}
+{
+  <DATAVERSE> stmt = DropDataverseSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+DataverseDropStatement DropDataverseSpecification(Token startStmtToken) throws ParseException:
+{
+  List<String> multipartId = null;
+  boolean ifExists = false;
+}
+{
+  multipartId = MultipartIdentifier() ifExists = IfExists()
+  {
+    DataverseDropStatement stmt = new DataverseDropStatement(DataverseName.create(multipartId), ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+FunctionDropStatement DropFunctionStatement(Token startStmtToken) throws ParseException:
+{
+  FunctionDropStatement stmt = null;
+}
+{
+  <FUNCTION> stmt = DropFunctionSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+FunctionDropStatement DropFunctionSpecification(Token startStmtToken) throws ParseException:
+{
+  FunctionSignature funcSig = null;
+  boolean ifExists = false;
+}
+{
+  funcSig = FunctionSignature() ifExists = IfExists()
+  {
+    FunctionDropStatement stmt = new FunctionDropStatement(funcSig, ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+FeedDropStatement DropFeedStatement(Token startStmtToken) throws ParseException:
+{
+  FeedDropStatement stmt = null;
+}
+{
+  <FEED> stmt = DropFeedSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+FeedDropStatement DropFeedSpecification(Token startStmtToken) throws ParseException:
+{
+  Pair<DataverseName,Identifier> pairId = null;
+  boolean ifExists = false;
+}
+{
+  pairId = QualifiedName() ifExists = IfExists()
+  {
+    FeedDropStatement stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+FeedPolicyDropStatement DropFeedPolicyStatement(Token startStmtToken) throws ParseException:
+{
+  FeedPolicyDropStatement stmt = null;
+}
+{
+  <INGESTION> <POLICY> stmt = DropFeedPolicySpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+FeedPolicyDropStatement DropFeedPolicySpecification(Token startStmtToken) throws ParseException:
+{
+  Pair<DataverseName,Identifier> pairId = null;
+  boolean ifExists = false;
+}
+{
+  pairId = QualifiedName() ifExists = IfExists()
+  {
+    FeedPolicyDropStatement stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists);
+    return addSourceLocation(stmt, startStmtToken);
   }
 }
 
@@ -1384,7 +1645,6 @@
 Statement StartStatement(Token startStmtToken) throws ParseException:
 {
   Pair<DataverseName,Identifier> feedNameComponents = null;
-
   AbstractStatement stmt = null;
 }
 {
@@ -1398,7 +1658,6 @@
 AbstractStatement StopStatement(Token startStmtToken) throws ParseException:
 {
   Pair<DataverseName,Identifier> feedNameComponents = null;
-
   AbstractStatement stmt = null;
 }
 {
@@ -1762,13 +2021,6 @@
   )
 }
 
-void Dataset() throws ParseException:
-{
-}
-{
-    (<DATASET>|<COLLECTION>)
-}
-
 Pair<Integer, Pair<List<String>, IndexedTypeExpression>> OpenField() throws ParseException:
 {
   IndexedTypeExpression fieldType = null;

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/4365
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: Ief23b91a18cd2e3dc6015d91ced1f1f22a2aacec
Gerrit-Change-Number: 4365
Gerrit-PatchSet: 1
Gerrit-Owner: Dmitry Lychagin <dm...@couchbase.com>
Gerrit-MessageType: newchange

Change in asterixdb[master]: [NO ISSUE][SQLPP] Refactor SQL++ grammar

Posted by AsterixDB Code Review <do...@vitalstatistix.ics.uci.edu>.
Anon. E. Moose #1000171 has posted comments on this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/4365 )

Change subject: [NO ISSUE][SQLPP] Refactor SQL++ grammar
......................................................................


Patch Set 1: Contrib-2

Analytics Compatibility Compilation Failed
https://cbjenkins.page.link/2nPv : UNSTABLE


-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/4365
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: Ief23b91a18cd2e3dc6015d91ced1f1f22a2aacec
Gerrit-Change-Number: 4365
Gerrit-PatchSet: 1
Gerrit-Owner: Dmitry Lychagin <dm...@couchbase.com>
Gerrit-Reviewer: Anon. E. Moose #1000171
Gerrit-CC: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Comment-Date: Tue, 26 Nov 2019 22:42:16 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

Change in asterixdb[master]: [NO ISSUE][SQLPP] Refactor SQL++ grammar

Posted by AsterixDB Code Review <do...@vitalstatistix.ics.uci.edu>.
From Dmitry Lychagin <dm...@couchbase.com>:

Dmitry Lychagin has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/4365 )


Change subject: [NO ISSUE][SQLPP] Refactor SQL++ grammar
......................................................................

[NO ISSUE][SQLPP] Refactor SQL++ grammar

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

Details:
- Refactor SQL++ grammar for better extensibility

Change-Id: Ief23b91a18cd2e3dc6015d91ced1f1f22a2aacec
---
M asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
1 file changed, 478 insertions(+), 226 deletions(-)



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

diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index 13cebb6..7672c56 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -578,20 +578,31 @@
 {
   <CREATE> { startToken = token; }
   (
-    stmt = TypeSpecification(startToken)
-    | stmt = NodegroupSpecification(startToken)
-    | stmt = DatasetSpecification(startToken)
-    | stmt = IndexSpecification(startToken)
-    | stmt = DataverseSpecification(startToken)
-    | stmt = FunctionSpecification(startToken)
-    | stmt = FeedSpecification(startToken)
-    | stmt = FeedPolicySpecification(startToken)
+    stmt = CreateTypeStatement(startToken)
+    | stmt = CreateNodegroupStatement(startToken)
+    | stmt = CreateDatasetStatement(startToken)
+    | stmt = CreateIndexStatement(startToken)
+    | stmt = CreateDataverseStatement(startToken)
+    | stmt = CreateFunctionStatement(startToken)
+    | stmt = CreateFeedStatement(startToken)
+    | stmt = CreateFeedPolicyStatement(startToken)
   )
   {
     return stmt;
   }
 }
 
+TypeDecl CreateTypeStatement(Token startStmtToken) throws ParseException:
+{
+  TypeDecl stmt = null;
+}
+{
+  <TYPE> stmt = TypeSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
 TypeDecl TypeSpecification(Token startStmtToken) throws ParseException:
 {
   Pair<DataverseName,Identifier> nameComponents = null;
@@ -599,28 +610,39 @@
   TypeExpression typeExpr = null;
 }
 {
-  <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists()
+  nameComponents = TypeName() ifNotExists = IfNotExists()
   <AS> typeExpr = RecordTypeDef()
-    {
-      boolean dgen = false;
-      long numValues = -1;
-      String filename = null;
-      Token hintToken = fetchHint(startStmtToken, SqlppHint.DGEN_HINT);
-      if (hintToken != null) {
-          String hintParams = hintToken.hintParams;
-          String[] splits = hintParams != null ? hintParams.split("\\s+") : null;
-          if (splits == null || splits.length != 2) {
-            throw new SqlppParseException(getSourceLocation(hintToken),
-              "Expecting /*+ dgen <filename> <numberOfItems> */");
-          }
-          dgen = true;
-          filename = splits[0];
-          numValues = Long.parseLong(splits[1]);
-      }
-      TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
-      TypeDecl stmt = new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
-      return addSourceLocation(stmt, startStmtToken);
+  {
+    boolean dgen = false;
+    long numValues = -1;
+    String filename = null;
+    Token hintToken = fetchHint(startStmtToken, SqlppHint.DGEN_HINT);
+    if (hintToken != null) {
+        String hintParams = hintToken.hintParams;
+        String[] splits = hintParams != null ? hintParams.split("\\s+") : null;
+        if (splits == null || splits.length != 2) {
+          throw new SqlppParseException(getSourceLocation(hintToken),
+            "Expecting /*+ dgen <filename> <numberOfItems> */");
+        }
+        dgen = true;
+        filename = splits[0];
+        numValues = Long.parseLong(splits[1]);
     }
+    TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
+    TypeDecl stmt = new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+NodegroupDecl CreateNodegroupStatement(Token startStmtToken) throws ParseException:
+{
+  NodegroupDecl stmt = null;
+}
+{
+  <NODEGROUP> stmt = NodegroupSpecification(startStmtToken)
+  {
+    return stmt;
+  }
 }
 
 NodegroupDecl NodegroupSpecification(Token startStmtToken) throws ParseException:
@@ -628,24 +650,44 @@
   String name = null;
   String tmp = null;
   boolean ifNotExists = false;
-  List<Identifier>ncNames = null;
+  List<Identifier> ncNames = new ArrayList<Identifier>();
 }
 {
-  <NODEGROUP> name = Identifier()
-  ifNotExists = IfNotExists() <ON> tmp = Identifier()
-    {
-      ncNames = new ArrayList<Identifier>();
-      ncNames.add(new Identifier(tmp));
-    }
+  name = Identifier() ifNotExists = IfNotExists()
+  <ON> tmp = Identifier()
+  {
+    ncNames.add(new Identifier(tmp));
+  }
   ( <COMMA> tmp = Identifier()
     {
       ncNames.add(new Identifier(tmp));
     }
   )*
-    {
-      NodegroupDecl stmt = new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
-      return addSourceLocation(stmt, startStmtToken);
-    }
+  {
+    NodegroupDecl stmt = new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+void Dataset() throws ParseException:
+{
+}
+{
+    (<DATASET>|<COLLECTION>)
+}
+
+DatasetDecl CreateDatasetStatement(Token startStmtToken) throws ParseException:
+{
+  DatasetDecl stmt = null;
+}
+{
+  (
+    (<INTERNAL>)? Dataset() stmt = DatasetSpecification(startStmtToken)
+    | <EXTERNAL> Dataset() stmt = ExternalDatasetSpecification(startStmtToken)
+  )
+  {
+    return stmt;
+  }
 }
 
 DatasetDecl DatasetSpecification(Token startStmtToken) throws ParseException:
@@ -666,88 +708,81 @@
   RecordConstructor withRecord = null;
 }
 {
+  nameComponents = QualifiedName()
+  <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
   (
-    <EXTERNAL> Dataset() nameComponents = QualifiedName()
-    <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
-    ifNotExists = IfNotExists()
-    <USING> adapterName = AdapterName() properties = Configuration()
-    ( <ON> nodeGroupName = Identifier() )?
-    ( <HINTS> hints = Properties() )?
-    ( <WITH> withRecord = RecordConstructor() )?
-      {
-        ExternalDetailsDecl edd = new ExternalDetailsDecl();
-        edd.setAdapter(adapterName);
-        edd.setProperties(properties);
-        try{
-        stmt = new DatasetDecl(nameComponents.first,
-                                   nameComponents.second,
-                                   typeComponents.first,
-                                   typeComponents.second,
-                                   metaTypeComponents.first,
-                                   metaTypeComponents.second,
-                                   nodeGroupName != null? new Identifier(nodeGroupName): null,
-                                   hints,
-                                   DatasetType.EXTERNAL,
-                                   edd,
-                                   withRecord,
-                                   ifNotExists);
-        } catch (CompilationException e){
-           throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
-        }
-      }
-
-    | ( <INTERNAL> )?
-    Dataset() nameComponents = QualifiedName()
-    <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
-    (
-        { String name; }
-        <WITH>
-        name = Identifier()
-        {
-            if (!name.equalsIgnoreCase("meta")){
-                throw new SqlppParseException(getSourceLocation(startStmtToken),
-                    "We can only support one additional associated field called \"meta\".");
-            }
-        }
-        <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
-    )?
-    ifNotExists = IfNotExists()
-    primaryKeyFields = PrimaryKey()
-    (<AUTOGENERATED> { autogenerated = true; } )?
-    (<ON> nodeGroupName = Identifier() )?
-    ( <HINTS> hints = Properties() )?
-    ( LOOKAHEAD(2) <WITH> <FILTER> <ON>  filterField = NestedField() )?
-    ( <WITH> withRecord = RecordConstructor() )?
-      {
-        if(filterField!=null && filterField.first!=0){
-          throw new SqlppParseException(getSourceLocation(startStmtToken),
-            "A filter field can only be a field in the main record of the dataset.");
-        }
-        InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
-                                                          primaryKeyFields.first,
-                                                          autogenerated,
-                                                          filterField == null? null : filterField.second);
-        try{
-        stmt = new DatasetDecl(nameComponents.first,
-                                   nameComponents.second,
-                                   typeComponents.first,
-                                   typeComponents.second,
-                                   metaTypeComponents.first,
-                                   metaTypeComponents.second,
-                                   nodeGroupName != null ? new Identifier(nodeGroupName) : null,
-                                   hints,
-                                   DatasetType.INTERNAL,
-                                   idd,
-                                   withRecord,
-                                   ifNotExists);
-        } catch (CompilationException e){
-           throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
-        }
-      }
-  )
+    { String name; }
+    <WITH>
+    name = Identifier()
     {
-      return addSourceLocation(stmt, startStmtToken);
+        if (!name.equalsIgnoreCase("meta")){
+            throw new SqlppParseException(getSourceLocation(startStmtToken),
+                "We can only support one additional associated field called \"meta\".");
+        }
     }
+    <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
+  )?
+  ifNotExists = IfNotExists()
+  primaryKeyFields = PrimaryKey()
+  (<AUTOGENERATED> { autogenerated = true; } )?
+  (<ON> nodeGroupName = Identifier() )?
+  ( <HINTS> hints = Properties() )?
+  ( LOOKAHEAD(2) <WITH> <FILTER> <ON>  filterField = NestedField() )?
+  ( <WITH> withRecord = RecordConstructor() )?
+  {
+    if(filterField!=null && filterField.first!=0){
+      throw new SqlppParseException(getSourceLocation(startStmtToken),
+        "A filter field can only be a field in the main record of the dataset.");
+    }
+    InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second, primaryKeyFields.first, autogenerated,
+      filterField == null? null : filterField.second);
+    try {
+      stmt = new DatasetDecl(nameComponents.first, nameComponents.second, typeComponents.first, typeComponents.second,
+        metaTypeComponents.first, metaTypeComponents.second,
+        nodeGroupName != null ? new Identifier(nodeGroupName) : null, hints, DatasetType.INTERNAL, idd, withRecord,
+        ifNotExists);
+      return addSourceLocation(stmt, startStmtToken);
+    } catch (CompilationException e) {
+       throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
+    }
+  }
+}
+
+DatasetDecl ExternalDatasetSpecification(Token startStmtToken) throws ParseException:
+{
+  Pair<DataverseName,Identifier> nameComponents = null;
+  boolean ifNotExists = false;
+  Pair<DataverseName,Identifier> typeComponents = null;
+  String adapterName = null;
+  Map<String,String> properties = null;
+  String nodeGroupName = null;
+  Map<String,String> hints = new HashMap<String,String>();
+  DatasetDecl stmt = null;
+  Pair<DataverseName,Identifier> metaTypeComponents = new Pair<DataverseName, Identifier>(null, null);
+  RecordConstructor withRecord = null;
+}
+{
+  nameComponents = QualifiedName()
+  <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
+  ifNotExists = IfNotExists()
+  <USING> adapterName = AdapterName() properties = Configuration()
+  ( <ON> nodeGroupName = Identifier() )?
+  ( <HINTS> hints = Properties() )?
+  ( <WITH> withRecord = RecordConstructor() )?
+  {
+    ExternalDetailsDecl edd = new ExternalDetailsDecl();
+    edd.setAdapter(adapterName);
+    edd.setProperties(properties);
+    try {
+      stmt = new DatasetDecl(nameComponents.first, nameComponents.second, typeComponents.first, typeComponents.second,
+        metaTypeComponents.first, metaTypeComponents.second,
+        nodeGroupName != null? new Identifier(nodeGroupName): null, hints, DatasetType.EXTERNAL, edd, withRecord,
+        ifNotExists);
+      return addSourceLocation(stmt, startStmtToken);
+    } catch (CompilationException e) {
+       throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
+    }
+  }
 }
 
 RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
@@ -757,13 +792,27 @@
   String datasetName = null;
 }
 {
-    <REFRESH> { startToken = token; } <EXTERNAL> Dataset() nameComponents = QualifiedName()
-    {
-      RefreshExternalDatasetStatement stmt = new RefreshExternalDatasetStatement();
-      stmt.setDataverseName(nameComponents.first);
-      stmt.setDatasetName(nameComponents.second);
-      return addSourceLocation(stmt, startToken);
-    }
+  <REFRESH> { startToken = token; } <EXTERNAL> Dataset() nameComponents = QualifiedName()
+  {
+    RefreshExternalDatasetStatement stmt = new RefreshExternalDatasetStatement();
+    stmt.setDataverseName(nameComponents.first);
+    stmt.setDatasetName(nameComponents.second);
+    return addSourceLocation(stmt, startToken);
+  }
+}
+
+CreateIndexStatement CreateIndexStatement(Token startStmtToken) throws ParseException:
+{
+  CreateIndexStatement stmt = null;
+}
+{
+  (
+    <INDEX> stmt = IndexSpecification(startStmtToken)
+    | <PRIMARY> <INDEX> stmt = PrimaryIndexSpecification(startStmtToken)
+  )
+  {
+    return stmt;
+  }
 }
 
 CreateIndexStatement IndexSpecification(Token startStmtToken) throws ParseException:
@@ -775,12 +824,10 @@
   Pair<Integer, Pair<List<String>, IndexedTypeExpression>> fieldPair = null;
   IndexParams indexType = null;
   boolean enforced = false;
-  boolean isPrimaryIdx = false;
 }
 {
   (
-    (<INDEX> indexName = Identifier()
-    ifNotExists = IfNotExists()
+    indexName = Identifier() ifNotExists = IfNotExists()
     <ON> nameComponents = QualifiedName()
     <LEFTPAREN> ( fieldPair = OpenField()
       {
@@ -792,19 +839,9 @@
         stmt.addFieldExprPair(fieldPair.second);
         stmt.addFieldIndexIndicator(fieldPair.first);
       }
-    )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?)
-    |
-    (<PRIMARY> <INDEX> {isPrimaryIdx = true;}
-      (
-        (indexName = Identifier())? ifNotExists = IfNotExists()
-      )
-      <ON> nameComponents = QualifiedName() (<TYPE> <BTREE>)?
-    )
+    )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?
   )
   {
-    if (isPrimaryIdx && indexName == null) {
-      indexName = "primary_idx_" + nameComponents.second;
-    }
     stmt.setIndexName(new Identifier(indexName));
     stmt.setIfNotExists(ifNotExists);
     stmt.setDataverseName(nameComponents.first);
@@ -818,6 +855,28 @@
   }
 }
 
+CreateIndexStatement PrimaryIndexSpecification(Token startStmtToken) throws ParseException:
+{
+  CreateIndexStatement stmt = new CreateIndexStatement();
+  String indexName = null;
+  boolean ifNotExists = false;
+  Pair<DataverseName,Identifier> nameComponents = null;
+}
+{
+  (indexName = Identifier())? ifNotExists = IfNotExists()
+  <ON> nameComponents = QualifiedName() (<TYPE> <BTREE>)?
+  {
+    if (indexName == null) {
+      indexName = "primary_idx_" + nameComponents.second;
+    }
+    stmt.setIndexName(new Identifier(indexName));
+    stmt.setIfNotExists(ifNotExists);
+    stmt.setDataverseName(nameComponents.first);
+    stmt.setDatasetName(nameComponents.second);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
 String CompactionPolicy() throws ParseException :
 {
   String compactionPolicy = null;
@@ -873,18 +932,39 @@
     }
 }
 
+CreateDataverseStatement CreateDataverseStatement(Token startStmtToken) throws ParseException :
+{
+  CreateDataverseStatement stmt = null;
+}
+{
+  <DATAVERSE> stmt = DataverseSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
 CreateDataverseStatement DataverseSpecification(Token startStmtToken) throws ParseException :
 {
   List<String> dvName = null;
   boolean ifNotExists = false;
 }
 {
-  <DATAVERSE> dvName = MultipartIdentifier()
-  ifNotExists = IfNotExists()
-    {
-      CreateDataverseStatement stmt = new CreateDataverseStatement(DataverseName.create(dvName), null, ifNotExists);
-      return addSourceLocation(stmt, startStmtToken);
-    }
+  dvName = MultipartIdentifier() ifNotExists = IfNotExists()
+  {
+    CreateDataverseStatement stmt = new CreateDataverseStatement(DataverseName.create(dvName), null, ifNotExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+CreateFunctionStatement CreateFunctionStatement(Token startStmtToken) throws ParseException:
+{
+  CreateFunctionStatement stmt = null;
+}
+{
+  <FUNCTION> stmt = FunctionSpecification(startStmtToken)
+  {
+    return stmt;
+  }
 }
 
 CreateFunctionStatement FunctionSpecification(Token startStmtToken) throws ParseException:
@@ -903,7 +983,7 @@
   createNewScope();
 }
 {
-  <FUNCTION> fctName = FunctionName()
+  fctName = FunctionName()
   {
      defaultDataverse = fctName.dataverse;
   }
@@ -915,17 +995,28 @@
   }
   (functionBodyExpr = SelectExpression(true) | functionBodyExpr = Expression())
   <RIGHTBRACE>
-    {
-      endPos = token;
-      functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
-      // TODO use fctName.library
-      signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
-      getCurrentScope().addFunctionDescriptor(signature, false);
-      removeCurrentScope();
-      defaultDataverse = currentDataverse;
-      CreateFunctionStatement stmt = new CreateFunctionStatement(signature, paramList, functionBody, functionBodyExpr, ifNotExists);
-      return addSourceLocation(stmt, startStmtToken);
-    }
+  {
+    endPos = token;
+    functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
+    // TODO use fctName.library
+    signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
+    getCurrentScope().addFunctionDescriptor(signature, false);
+    removeCurrentScope();
+    defaultDataverse = currentDataverse;
+    CreateFunctionStatement stmt = new CreateFunctionStatement(signature, paramList, functionBody, functionBodyExpr, ifNotExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+CreateFeedStatement CreateFeedStatement(Token startStmtToken) throws ParseException:
+{
+  CreateFeedStatement stmt = null;
+}
+{
+  <FEED> stmt = FeedSpecification(startStmtToken)
+  {
+    return stmt;
+  }
 }
 
 CreateFeedStatement FeedSpecification(Token startStmtToken) throws ParseException:
@@ -939,7 +1030,7 @@
   RecordConstructor withRecord = null;
 }
 {
-  <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
+  nameComponents = QualifiedName() ifNotExists = IfNotExists()
   <WITH> withRecord = RecordConstructor()
   {
     try {
@@ -951,6 +1042,17 @@
   }
 }
 
+CreateFeedPolicyStatement CreateFeedPolicyStatement(Token startStmtToken) throws ParseException:
+{
+  CreateFeedPolicyStatement stmt = null;
+}
+{
+  <INGESTION> <POLICY> stmt = FeedPolicySpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
 CreateFeedPolicyStatement FeedPolicySpecification(Token startStmtToken) throws ParseException:
 {
   String policyName = null;
@@ -962,23 +1064,20 @@
   CreateFeedPolicyStatement stmt = null;
 }
 {
-  (
-    <INGESTION> <POLICY>  policyName = Identifier() ifNotExists = IfNotExists()
-      <FROM>
-      (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = ConstantString())?
-      {
-        stmt = new CreateFeedPolicyStatement(policyName,
-                                   basePolicyName, properties, definition, ifNotExists);
-      }
-     | <PATH> sourcePolicyFile = ConstantString() (<DEFINITION> definition = ConstantString())?
-       {
-        stmt = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
-       }
-     )
-  )
+  policyName = Identifier() ifNotExists = IfNotExists()
+  <FROM>
+  (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = ConstantString())?
     {
-      return addSourceLocation(stmt, startStmtToken);
+      stmt = new CreateFeedPolicyStatement(policyName, basePolicyName, properties, definition, ifNotExists);
     }
+  | <PATH> sourcePolicyFile = ConstantString() (<DEFINITION> definition = ConstantString())?
+    {
+      stmt = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
+    }
+  )
+  {
+    return addSourceLocation(stmt, startStmtToken);
+  }
 }
 
 List<VarIdentifier> ParameterList() throws ParseException:
@@ -1024,10 +1123,10 @@
 }
 {
   <APPLY> <FUNCTION> functionName = FunctionName()
-    {
-       fqFunctionName = functionName.library == null ? functionName.function : functionName.library + "#" + functionName.function;
-       funcSigs.add(new FunctionSignature(functionName.dataverse, fqFunctionName, 1));
-    }
+  {
+     fqFunctionName = functionName.library == null ? functionName.function : functionName.library + "#" + functionName.function;
+     funcSigs.add(new FunctionSignature(functionName.dataverse, fqFunctionName, 1));
+  }
   (
       <COMMA> functionName = FunctionName()
       {
@@ -1094,52 +1193,214 @@
 Statement DropStatement() throws ParseException:
 {
   Token startToken = null;
-  String id = null;
-  List<String> multipartId = null;
-  Pair<DataverseName,Identifier> pairId = null;
-  Triple<DataverseName,Identifier,Identifier> tripleId = null;
-  FunctionSignature funcSig = null;
-  boolean ifExists = false;
-  AbstractStatement stmt = null;
+  Statement stmt = null;
 }
 {
   <DROP> { startToken = token; }
   (
-    Dataset() pairId = QualifiedName() ifExists = IfExists()
-      {
-        stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists);
-      }
-    | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists()
-      {
-        stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
-      }
-    | <NODEGROUP> id = Identifier() ifExists = IfExists()
-      {
-        stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
-      }
-    | <TYPE> pairId = TypeName() ifExists = IfExists()
-      {
-        stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
-      }
-    | <DATAVERSE> multipartId = MultipartIdentifier() ifExists = IfExists()
-      {
-        stmt = new DataverseDropStatement(DataverseName.create(multipartId), ifExists);
-      }
-    | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists()
-      {
-        stmt = new FunctionDropStatement(funcSig, ifExists);
-      }
-    | <FEED> pairId = QualifiedName() ifExists = IfExists()
-      {
-        stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
-      }
-    | <INGESTION> <POLICY> pairId = QualifiedName() ifExists = IfExists()
-      {
-        stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists);
-      }
+    stmt = DropDatasetStatement(startToken)
+    | stmt = DropIndexStatement(startToken)
+    | stmt = DropNodeGroupStatement(startToken)
+    | stmt = DropTypeStatement(startToken)
+    | stmt = DropDataverseStatement(startToken)
+    | stmt = DropFunctionStatement(startToken)
+    | stmt = DropFeedStatement(startToken)
+    | stmt = DropFeedPolicyStatement(startToken)
   )
   {
-    return addSourceLocation(stmt, startToken);
+    return stmt;
+  }
+}
+
+DropDatasetStatement DropDatasetStatement(Token startStmtToken) throws ParseException:
+{
+  DropDatasetStatement stmt = null;
+}
+{
+  Dataset() stmt = DropDatasetSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+DropDatasetStatement DropDatasetSpecification(Token startStmtToken) throws ParseException:
+{
+  Pair<DataverseName,Identifier> pairId = null;
+  boolean ifExists = false;
+}
+{
+  pairId = QualifiedName() ifExists = IfExists()
+  {
+    DropDatasetStatement stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+IndexDropStatement DropIndexStatement(Token startStmtToken) throws ParseException:
+{
+  IndexDropStatement stmt = null;
+}
+{
+  <INDEX> stmt = DropIndexSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+IndexDropStatement DropIndexSpecification(Token startStmtToken) throws ParseException:
+{
+  Triple<DataverseName,Identifier,Identifier> tripleId = null;
+  boolean ifExists = false;
+}
+{
+  tripleId = DoubleQualifiedName() ifExists = IfExists()
+  {
+    IndexDropStatement stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+NodeGroupDropStatement DropNodeGroupStatement(Token startStmtToken) throws ParseException:
+{
+  NodeGroupDropStatement stmt = null;
+}
+{
+  <NODEGROUP> stmt = DropNodeGroupSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+NodeGroupDropStatement DropNodeGroupSpecification(Token startStmtToken) throws ParseException:
+{
+  String id = null;
+  boolean ifExists = false;
+}
+{
+  id = Identifier() ifExists = IfExists()
+  {
+    NodeGroupDropStatement stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+TypeDropStatement DropTypeStatement(Token startStmtToken) throws ParseException:
+{
+  TypeDropStatement stmt = null;
+}
+{
+  <TYPE> stmt = DropTypeSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+TypeDropStatement DropTypeSpecification(Token startStmtToken) throws ParseException:
+{
+  Pair<DataverseName,Identifier> pairId = null;
+  boolean ifExists = false;
+}
+{
+  pairId = TypeName() ifExists = IfExists()
+  {
+    TypeDropStatement stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+DataverseDropStatement DropDataverseStatement(Token startStmtToken) throws ParseException:
+{
+  DataverseDropStatement stmt = null;
+}
+{
+  <DATAVERSE> stmt = DropDataverseSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+DataverseDropStatement DropDataverseSpecification(Token startStmtToken) throws ParseException:
+{
+  List<String> multipartId = null;
+  boolean ifExists = false;
+}
+{
+  multipartId = MultipartIdentifier() ifExists = IfExists()
+  {
+    DataverseDropStatement stmt = new DataverseDropStatement(DataverseName.create(multipartId), ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+FunctionDropStatement DropFunctionStatement(Token startStmtToken) throws ParseException:
+{
+  FunctionDropStatement stmt = null;
+}
+{
+  <FUNCTION> stmt = DropFunctionSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+FunctionDropStatement DropFunctionSpecification(Token startStmtToken) throws ParseException:
+{
+  FunctionSignature funcSig = null;
+  boolean ifExists = false;
+}
+{
+  funcSig = FunctionSignature() ifExists = IfExists()
+  {
+    FunctionDropStatement stmt = new FunctionDropStatement(funcSig, ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+FeedDropStatement DropFeedStatement(Token startStmtToken) throws ParseException:
+{
+  FeedDropStatement stmt = null;
+}
+{
+  <FEED> stmt = DropFeedSpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+FeedDropStatement DropFeedSpecification(Token startStmtToken) throws ParseException:
+{
+  Pair<DataverseName,Identifier> pairId = null;
+  boolean ifExists = false;
+}
+{
+  pairId = QualifiedName() ifExists = IfExists()
+  {
+    FeedDropStatement stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
+    return addSourceLocation(stmt, startStmtToken);
+  }
+}
+
+FeedPolicyDropStatement DropFeedPolicyStatement(Token startStmtToken) throws ParseException:
+{
+  FeedPolicyDropStatement stmt = null;
+}
+{
+  <INGESTION> <POLICY> stmt = DropFeedPolicySpecification(startStmtToken)
+  {
+    return stmt;
+  }
+}
+
+FeedPolicyDropStatement DropFeedPolicySpecification(Token startStmtToken) throws ParseException:
+{
+  Pair<DataverseName,Identifier> pairId = null;
+  boolean ifExists = false;
+}
+{
+  pairId = QualifiedName() ifExists = IfExists()
+  {
+    FeedPolicyDropStatement stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists);
+    return addSourceLocation(stmt, startStmtToken);
   }
 }
 
@@ -1384,7 +1645,6 @@
 Statement StartStatement(Token startStmtToken) throws ParseException:
 {
   Pair<DataverseName,Identifier> feedNameComponents = null;
-
   AbstractStatement stmt = null;
 }
 {
@@ -1398,7 +1658,6 @@
 AbstractStatement StopStatement(Token startStmtToken) throws ParseException:
 {
   Pair<DataverseName,Identifier> feedNameComponents = null;
-
   AbstractStatement stmt = null;
 }
 {
@@ -1762,13 +2021,6 @@
   )
 }
 
-void Dataset() throws ParseException:
-{
-}
-{
-    (<DATASET>|<COLLECTION>)
-}
-
 Pair<Integer, Pair<List<String>, IndexedTypeExpression>> OpenField() throws ParseException:
 {
   IndexedTypeExpression fieldType = null;

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/4365
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: Ief23b91a18cd2e3dc6015d91ced1f1f22a2aacec
Gerrit-Change-Number: 4365
Gerrit-PatchSet: 1
Gerrit-Owner: Dmitry Lychagin <dm...@couchbase.com>
Gerrit-MessageType: newchange