saihemanth-cloudera commented on code in PR #4517:
URL: https://github.com/apache/hive/pull/4517#discussion_r1316203471


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java:
##########
@@ -532,6 +535,66 @@ public void addPartitions(List<MPartition> parts, 
List<List<MPartitionPrivilege>
     directSqlInsertPart.addPartitions(parts, partPrivilegesList, 
partColPrivilegesList);
   }
 
+  /**
+   * Alter partitions in batch using direct SQL
+   * @param table the target table
+   * @param partNames list of partition names
+   * @param newParts list of new partitions
+   * @param queryWriteIdList valid write id list
+   * @return
+   * @throws MetaException
+   */
+  public List<Partition> alterPartitions(Table table, List<String> partNames,
+      List<Partition> newParts, String queryWriteIdList) throws MetaException {
+    String filter = "" + PARTITIONS + ".\"PART_NAME\" in (" + 
makeParams(partNames.size()) + ")";
+    List<String> columns = Arrays.asList("\"PART_ID\"", "\"PART_NAME\"", 
"\"SD_ID\"", "\"WRITE_ID\"");
+    List<Object[]> rows = getPartitionFieldsViaSqlFilter(table.getCatName(), 
table.getDbName(),
+        table.getTableName(), columns, filter, partNames, 
Collections.emptyList(), null);
+    Map<List<String>, Long> partValuesToId = new HashMap<>();
+    Map<Long, Long> partIdToSdId = new HashMap<>();
+    Map<Long, Long> partIdToWriteId = new HashMap<>();
+    for (Object[] row : rows) {
+      Long partId = MetastoreDirectSqlUtils.extractSqlLong(row[0]);
+      Long sdId = MetastoreDirectSqlUtils.extractSqlLong(row[2]);
+      Long writeId = MetastoreDirectSqlUtils.extractSqlLong(row[3]);
+      partIdToSdId.put(partId, sdId);
+      partIdToWriteId.put(partId, writeId);
+      List<String> partValues = Warehouse.getPartValuesFromPartName((String) 
row[1]);
+      partValuesToId.put(partValues, partId);
+    }
+
+    boolean isTxn = TxnUtils.isTransactionalTable(table.getParameters());
+    for (Partition newPart : newParts) {
+      Long partId = partValuesToId.get(newPart.getValues());
+      boolean useOldWriteId = true;
+      // If transactional, add/update the MUPdaterTransaction
+      // for the current updater query.
+      if (isTxn) {
+        if (!areTxnStatsSupported) {
+          StatsSetupConst.setBasicStatsState(newPart.getParameters(), 
StatsSetupConst.FALSE);
+        } else if (queryWriteIdList != null && newPart.getWriteId() > 0) {
+          // Check concurrent INSERT case and set false to the flag.
+          if 
(!ObjectStore.isCurrentStatsValidForTheQuery(newPart.getParameters(),
+              partIdToWriteId.get(partId), queryWriteIdList, true)) {
+            StatsSetupConst.setBasicStatsState(newPart.getParameters(), 
StatsSetupConst.FALSE);
+            LOG.info("Removed COLUMN_STATS_ACCURATE from the parameters of the 
partition " +
+                Warehouse.getQualifiedName(newPart) + " will be made 
persistent.");
+          }
+          useOldWriteId = false;
+        }
+      }
+
+      if (useOldWriteId) {
+        newPart.setWriteId(partIdToWriteId.get(partId));
+      }
+    }
+
+    directSqlUpdate.alterPartitions(partValuesToId, partIdToSdId, newParts);
+    // The returned result were not utilized, so return an empty list in 
direct sql for performance.
+    // TODO: Change the API signature of RawStore#alterPartitions to return 
void instead.
+    return Collections.emptyList();

Review Comment:
   It would be nice to return the updated altered partitioned result set. It 
would be used by clients immediately after the alter operation. 



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

To unsubscribe, e-mail: [email protected]

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