sankarh commented on a change in pull request #664: HIVE-21762: REPL DUMP to 
support new format for replication policy input to take included tables list.
URL: https://github.com/apache/hive/pull/664#discussion_r291877895
 
 

 ##########
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/parse/ReplicationSemanticAnalyzer.java
 ##########
 @@ -134,50 +130,99 @@ private void setTxnConfigs() {
     }
   }
 
+  private boolean isValidTablesList(Tree tablesListTree) {
+    if (tablesListTree.getChildCount() <= 1) {
+      // If one or zero child, then it is valid.
+      // For single table replication, the valid format is 
<db_name>.<table_name>.
+      // To include multiple tables (t1 and t2), then valid format is 
<db_name>.[t1, t2].
+      // So, single child is always valid either it is table_name or 
tables_list.
+      return true;
+    }
+    assert(tablesListTree.getChildCount() == 2);
+
+    // We don't allow input of format <db_name>.<table_name>.<table_name> or 
<db_name>.<table_name>.[<tables_list>].
+    // To include t1* and exclude t100, then valid format is 
<db_name>.[t1*].[t100].
+    // So, if 2 children are there, then both should be table_lists.
+    return ((tablesListTree.getChild(0).getType() == TOK_REPL_TABLES_LIST)
+            && (tablesListTree.getChild(1).getType() == TOK_REPL_TABLES_LIST));
+  }
+
   private void initReplDump(ASTNode ast) throws HiveException {
     int numChildren = ast.getChildCount();
     boolean isMetaDataOnly = false;
-    dbNameOrPattern = PlanUtils.stripQuotes(ast.getChild(0).getText());
-
-    // skip the first node, which is always required
-    int currNode = 1;
-    while (currNode < numChildren) {
-      if (ast.getChild(currNode).getType() == TOK_REPL_CONFIG) {
-        Map<String, String> replConfigs
-            = DDLSemanticAnalyzer.getProps((ASTNode) 
ast.getChild(currNode).getChild(0));
-        if (null != replConfigs) {
-          for (Map.Entry<String, String> config : replConfigs.entrySet()) {
-            conf.set(config.getKey(), config.getValue());
+    String dbNameOrPattern = PlanUtils.stripQuotes(ast.getChild(0).getText());
+    replScope.setDbName(dbNameOrPattern);
+
+    // Skip the first node, which is always required
+    int childIdx = 1;
+    while (childIdx < numChildren) {
+      Tree currNode = ast.getChild(childIdx);
+      switch (currNode.getType()) {
+        case TOK_REPL_CONFIG: {
+          Map<String, String> replConfigs
+              = DDLSemanticAnalyzer.getProps((ASTNode) currNode.getChild(0));
+          if (null != replConfigs) {
+            for (Map.Entry<String, String> config : replConfigs.entrySet()) {
+              conf.set(config.getKey(), config.getValue());
+            }
+            isMetaDataOnly = HiveConf.getBoolVar(conf, 
REPL_DUMP_METADATA_ONLY);
           }
-          isMetaDataOnly = HiveConf.getBoolVar(conf, REPL_DUMP_METADATA_ONLY);
+          break;
         }
-      } else if (ast.getChild(currNode).getType() == TOK_TABNAME) {
-        // optional tblName was specified.
-        tblNameOrPattern = 
PlanUtils.stripQuotes(ast.getChild(currNode).getChild(0).getText());
-      } else {
-        // TOK_FROM subtree
-        Tree fromNode = ast.getChild(currNode);
-        eventFrom = 
Long.parseLong(PlanUtils.stripQuotes(fromNode.getChild(0).getText()));
-        // skip the first, which is always required
-        int numChild = 1;
-        while (numChild < fromNode.getChildCount()) {
-          if (fromNode.getChild(numChild).getType() == TOK_TO) {
-            eventTo =
-                
Long.parseLong(PlanUtils.stripQuotes(fromNode.getChild(numChild + 
1).getText()));
-            // skip the next child, since we already took care of it
-            numChild++;
-          } else if (fromNode.getChild(numChild).getType() == TOK_LIMIT) {
-            maxEventLimit =
-                
Integer.parseInt(PlanUtils.stripQuotes(fromNode.getChild(numChild + 
1).getText()));
-            // skip the next child, since we already took care of it
+        case TOK_REPL_TABLES: {
+          assert(currNode.getChildCount() <= 2);
+          if (!isValidTablesList(currNode)) {
+            LOG.error(ErrorMsg.REPL_INCORRECT_SYNTAX_FOR_REPL_POLICY.getMsg());
+            throw new 
SemanticException(ErrorMsg.REPL_INCORRECT_SYNTAX_FOR_REPL_POLICY.getMsg());
+          }
+
+          // Traverse the children which can be single table_name node or just 
include tables list
+          // or both include and exclude tables list.
+          for (int listIdx = 0; listIdx < currNode.getChildCount(); listIdx++) 
{
+            Tree tablesNode = currNode.getChild(listIdx);
+            if (tablesNode.getType() == TOK_TABNAME) {
 
 Review comment:
   May be I'll change to switch case without default.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to