deniskuzZ commented on code in PR #5123:
URL: https://github.com/apache/hive/pull/5123#discussion_r1525212033
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergMajorQueryCompactor.java:
##########
@@ -44,22 +52,68 @@ public boolean run(CompactorContext context) throws
IOException, HiveException,
Map<String, String> tblProperties = context.getTable().getParameters();
LOG.debug("Initiating compaction for the {} table", compactTableName);
- String compactionQuery = String.format("insert overwrite table %s select *
from %<s",
- compactTableName);
+ String partSpec = context.getCompactionInfo().partName;
+ String compactionQuery;
+ RewritePolicy rewritePolicy;
+
+ if (partSpec == null) {
+ compactionQuery = String.format("insert overwrite table %s select * from
%<s",
+ compactTableName);
+ rewritePolicy = RewritePolicy.ALL_PARTITIONS;
+ } else {
+ Table table = IcebergTableUtil.getTable(context.getConf(),
context.getTable());
+ PartitionData partitionData = DataFiles.data(table.spec(), partSpec);
+ HiveConf.setVar(context.getConf(),
ConfVars.HIVE_ICEBERG_COMPACTION_PARTITION, partSpec);
+ compactionQuery = String.format("insert overwrite table %1$s
partition(%2$s) select * from %1$s where %3$s",
+ compactTableName, partDataToSQL(partitionData, partSpec, ","),
+ partDataToSQL(partitionData, partSpec, " and "));
+ rewritePolicy = RewritePolicy.SINGLE_PARTITION;
+ }
SessionState sessionState = setupQueryCompactionSession(context.getConf(),
context.getCompactionInfo(), tblProperties);
- HiveConf.setVar(context.getConf(), ConfVars.REWRITE_POLICY,
RewritePolicy.ALL_PARTITIONS.name());
+ HiveConf.setVar(context.getConf(), ConfVars.REWRITE_POLICY,
rewritePolicy.name());
try {
DriverUtils.runOnDriver(context.getConf(), sessionState,
compactionQuery);
LOG.info("Completed compaction for table {}", compactTableName);
} catch (HiveException e) {
- LOG.error("Error doing query based {} compaction",
RewritePolicy.ALL_PARTITIONS.name(), e);
+ LOG.error("Error doing query based {} compaction", rewritePolicy.name(),
e);
throw new RuntimeException(e);
} finally {
sessionState.setCompaction(false);
}
return true;
}
+
+ public String partDataToSQL(PartitionData partitionData, String partSpec,
String delimiter) {
Review Comment:
should it be public?
--
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]