pvary commented on a change in pull request #1095:
URL: https://github.com/apache/hive/pull/1095#discussion_r439263970



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
##########
@@ -12308,16 +12195,98 @@ else if(ast.getChild(0).getType() == 
HiveParser.TOK_FALSE) {
       // if phase1Result false return
       return false;
     }
+
+    // 5. Set write id for HMS client
+    if (getTxnMgr().supportsAcid() && 
conf.get(ValidTxnWriteIdList.VALID_TABLES_WRITEIDS_KEY) == null) {
+
+      ValidTxnWriteIdList txnWriteIds = null;
+
+      if (conf.get(ValidTxnWriteIdList.COMPACTOR_VALID_TABLES_WRITEIDS_KEY) != 
null) {
+        txnWriteIds = new 
ValidTxnWriteIdList(conf.getLong(ValidTxnList.COMPACTOR_VALID_TXNS_ID_KEY, 0));
+        txnWriteIds.addTableValidWriteIdList(
+            new 
ValidReaderWriteIdList(conf.get(ValidTxnWriteIdList.COMPACTOR_VALID_TABLES_WRITEIDS_KEY)));
+      } else {
+        List<String> tabNames = new ArrayList<>();
+        for (String tabName : collectTables(qb)) {
+          String fullName = TableName
+              .fromString(tabName, SessionState.get().getCurrentCatalog(), 
SessionState.get().getCurrentDatabase())
+              .getDbTable();
+          tabNames.add(fullName);
+        }
+
+        if (!tabNames.isEmpty()) {
+          String txnString = conf.get(ValidTxnList.VALID_TXNS_KEY);
+
+          try {
+            if ((txnString == null) || (txnString.isEmpty())) {
+              txnString = getTxnMgr().getValidTxns().toString();
+              conf.set(ValidTxnList.VALID_TXNS_KEY, txnString);
+            }
+
+            txnWriteIds = getTxnMgr().getValidWriteIds(tabNames, txnString);
+          } catch (LockException e) {
+            throw new SemanticException("Failed to fetch write Id from 
TxnManager", e);
+          }
+        }
+      }
+
+      if (txnWriteIds != null) {
+        conf.set(ValidTxnWriteIdList.VALID_TABLES_WRITEIDS_KEY, 
txnWriteIds.toString());
+        try {
+          db.getMSC().setValidWriteIdList(txnWriteIds.toString());
+          Hive.get().getMSC().setValidWriteIdList(txnWriteIds.toString());
+        } catch (HiveException | MetaException e) {
+          throw new SemanticException("Failed to set write Id for HMS client", 
e);
+        }
+      }
+    }
+
     LOG.info("Completed phase 1 of Semantic Analysis");
 
-    // 5. Resolve Parse Tree
+    // 6. Resolve Parse Tree
     // Materialization is allowed if it is not a view definition
     getMetaData(qb, createVwDesc == null);
     LOG.info("Completed getting MetaData in Semantic Analysis");
 
     return true;
   }
 
+  private Set<String> collectTables(QBExpr qbExpr) {

Review comment:
       Are they provide different results for DDL operations?




----------------------------------------------------------------
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]



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

Reply via email to