kasakrisz commented on code in PR #4672:
URL: https://github.com/apache/hive/pull/4672#discussion_r1327249429


##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/misc/truncate/TruncateTableAnalyzer.java:
##########
@@ -338,4 +373,42 @@ private void addStatTask(ASTNode root, Table table, Path 
oldPartitionLocation, P
       moveTask.addDependentTask(statTask);
     }
   }
+
+  public StringBuilder constructDeleteQuery(Table table, Map<String, String> 
partitionSpec) throws SemanticException {
+    StringBuilder sb = new StringBuilder().append("delete from 
").append(table.getTableName())
+            .append(" where ");
+    List<String> keyList = new ArrayList<String>(partitionSpec.keySet());
+    Deserializer deserializer = table.getDeserializer();
+    Map<String, PrimitiveObjectInspector.PrimitiveCategory> stringTypeInfoMap 
= new HashMap<>();
+    try {
+      ObjectInspector objectInspector = deserializer.getObjectInspector();
+      if (objectInspector.getCategory() == ObjectInspector.Category.STRUCT) {
+        StructObjectInspector structObjectInspector = (StructObjectInspector) 
objectInspector;
+        List<? extends StructField> structFields =  
structObjectInspector.getAllStructFieldRefs();
+        for (int index = 0;index < structFields.size();index++) {
+          StructField structField = structFields.get(index);
+          if (structField.getFieldObjectInspector().getCategory() == 
ObjectInspector.Category.PRIMITIVE) {
+            PrimitiveObjectInspector primitiveObjectInspector = 
(PrimitiveObjectInspector) structField.getFieldObjectInspector();
+            stringTypeInfoMap.put(structField.getFieldName(),
+                primitiveObjectInspector.getTypeInfo().getPrimitiveCategory());
+          }
+        }
+      }
+    } catch (SerDeException e) {
+      throw new SemanticException(String.format("Unable to get object 
inspector due to: %s", e));
+    }
+    for (int index = 0;index < keyList.size();index++) {
+      String key = keyList.get(index);

Review Comment:
   I'm asking because it seems to be an overkill to create a new collection 
just for iterating through the keys.  It can be done on the keySet() collection 
itself.
   How about?
   ```
   boolean first = true;
   for (String key : partitionSpec.keySet()) {
     if (first) {
       first = false;
       ...
     } else {
      addAndClause();
       ...
     }
   }
   ```



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