zabetak commented on code in PR #4859: URL: https://github.com/apache/hive/pull/4859#discussion_r1420474418
########## ql/src/java/org/apache/hadoop/hive/ql/ddl/table/storage/compact/AlterTableCompactOperation.java: ########## @@ -69,40 +79,48 @@ public AlterTableCompactOperation(DDLOperationContext context, AlterTableCompact compactionRequest.setNumberOfBuckets(desc.getNumberOfBuckets()); } - InitiatorBase initiatorBase = new InitiatorBase(); - initiatorBase.setConf(context.getConf()); - initiatorBase.init(new AtomicBoolean()); - - Map<String, org.apache.hadoop.hive.metastore.api.Partition> partitionMap = - convertPartitionsFromThriftToDB(getPartitions(table, desc, context)); - - if(desc.getPartitionSpec() != null){ - Optional<String> partitionName = partitionMap.keySet().stream().findFirst(); - partitionName.ifPresent(compactionRequest::setPartitionname); - } - List<CompactionResponse> compactionResponses = - initiatorBase.initiateCompactionForTable(compactionRequest, table.getTTable(), partitionMap); - for (CompactionResponse compactionResponse : compactionResponses) { - if (!compactionResponse.isAccepted()) { - String message; - if (compactionResponse.isSetErrormessage()) { - message = compactionResponse.getErrormessage(); - throw new HiveException(ErrorMsg.COMPACTION_REFUSED, table.getDbName(), table.getTableName(), - "CompactionId: " + compactionResponse.getId(), message); - } - context.getConsole().printInfo( - "Compaction already enqueued with id " + compactionResponse.getId() + "; State is " - + compactionResponse.getState()); - continue; + //Will directly initiate compaction if an un-partitioned table/a partition is specified in the request + if (desc.getPartitionSpec() != null || !table.isPartitioned()) { + if (desc.getPartitionSpec() != null) { + Optional<String> partitionName = partitionMap.keySet().stream().findFirst(); + partitionName.ifPresent(compactionRequest::setPartitionname); } - context.getConsole().printInfo("Compaction enqueued with id " + compactionResponse.getId()); - if (desc.isBlocking() && compactionResponse.isAccepted()) { - waitForCompactionToFinish(compactionResponse, context); + CompactionResponse compactionResponse = initiatorBase.initiateCompactionForTable(compactionRequest); Review Comment: The `CompactionRequest` provides ways to select a specific partition using its name. The method here `initiateCompactionForTable` seems capable of launching a compaction request targeting a specific table + partition. Why do we need to have an additional method (`initiateCompactionForPartition`) to do more or less the same thing? Why can't we use `initiateCompactionForTable` ? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org