kuczoram commented on code in PR #5192:
URL: https://github.com/apache/hive/pull/5192#discussion_r1601515867


##########
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CompactionQueryBuilder.java:
##########
@@ -275,137 +250,105 @@ String build() {
     case DROP:
     default:
     }
-
     return query.toString();
   }
 
+  protected void getDdlForCreate(StringBuilder query) {
+    defineColumns(query);
+
+    // PARTITIONED BY. Used for parts of minor compaction.
+    if (isPartitioned) {
+      query.append(" PARTITIONED BY (`file_name` STRING) ");
+    }
+
+    // STORED AS / ROW FORMAT SERDE + INPUTFORMAT + OUTPUTFORMAT
+    query.append(" stored as orc");
+
+    // LOCATION
+    if (location != null) {
+      query.append(" LOCATION 
'").append(HiveStringUtils.escapeHiveCommand(location)).append("'");
+    }
+
+    addTblProperties(query, false, 0);
+  }
+
+  /**
+   * Part of Create operation. All tmp tables are not transactional and are 
marked as
+   * compaction tables. Additionally...
+   * - Crud compaction temp tables need tblproperty, "compactiontable."
+   * - Minor crud compaction temp tables need bucketing version tblproperty, 
if table is bucketed.
+   */
+  protected void addTblProperties(StringBuilder query, boolean 
addBucketingVersion, int bucketingVersion) {
+    Map<String, String> tblProperties = new HashMap<>();
+    tblProperties.put("transactional", "false");
+    tblProperties.put(AcidUtils.COMPACTOR_TABLE_PROPERTY, 
compactionType.name());
+    if (addBucketingVersion) {
+      tblProperties.put("bucketing_version", String.valueOf(bucketingVersion));
+    }
+    if (sourceTab != null) { // to avoid NPEs, skip this part if sourceTab is 
null
+      for (Map.Entry<String, String> e : sourceTab.getParameters().entrySet()) 
{
+        if (e.getKey().startsWith("orc.")) {
+          tblProperties.put(e.getKey(), 
HiveStringUtils.escapeHiveCommand(e.getValue()));
+        }
+      }
+    }
+    addTblProperties(query, tblProperties);
+  }
+
+  protected void addTblProperties(StringBuilder query, Map<String, String> 
tblProperties) {
+    // add TBLPROPERTIES clause to query
+    boolean isFirst;
+    query.append(" TBLPROPERTIES (");

Review Comment:
   In practice, it should never happen that the tblProperties are empty, 
because the 'transactional=false' property is always added. But you are right, 
we should have a check here and not to add anything if the properties are empty.



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