vamsikarnika commented on code in PR #17460:
URL: https://github.com/apache/hudi/pull/17460#discussion_r2601962514
##########
hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/procedures/ShowCompactionProcedure.scala:
##########
@@ -57,24 +130,185 @@ class ShowCompactionProcedure extends BaseProcedure with
ProcedureBuilder with S
val tableName = getArgValueOrDefault(args, PARAMETERS(0))
val tablePath = getArgValueOrDefault(args, PARAMETERS(1))
val limit = getArgValueOrDefault(args, PARAMETERS(2)).get.asInstanceOf[Int]
+ val showArchived = getArgValueOrDefault(args,
PARAMETERS(3)).get.asInstanceOf[Boolean]
+ val filter = getArgValueOrDefault(args,
PARAMETERS(4)).get.asInstanceOf[String]
+ val startTime = getArgValueOrDefault(args,
PARAMETERS(5)).get.asInstanceOf[String]
+ val endTime = getArgValueOrDefault(args,
PARAMETERS(6)).get.asInstanceOf[String]
+ validateFilter(filter, outputType)
val basePath: String = getBasePath(tableName, tablePath)
val metaClient = createMetaClient(jsc, basePath)
- assert(metaClient.getTableType == HoodieTableType.MERGE_ON_READ,
- s"Cannot show compaction on a Non Merge On Read table.")
- val compactionInstants =
metaClient.getActiveTimeline.getInstants.iterator().asScala
+ if (metaClient.getTableType != HoodieTableType.MERGE_ON_READ) {
+ throw new IllegalArgumentException("Cannot show compaction on a Non
Merge On Read table.")
+ }
+
+ val activeResults =
getCombinedCompactionsWithPartitionMetadata(metaClient.getActiveTimeline,
limit, metaClient, startTime, endTime, "ACTIVE")
+ val finalResults = if (showArchived) {
+ val archivedResults =
getCombinedCompactionsWithPartitionMetadata(metaClient.getArchivedTimeline,
limit, metaClient, startTime, endTime, "ARCHIVED")
+ val combinedResults = (activeResults ++ archivedResults)
+ .sortWith((a, b) => a.getString(0) > b.getString(0))
+ if (startTime.trim.nonEmpty && endTime.trim.nonEmpty) {
+ combinedResults
+ } else {
+ combinedResults.take(limit)
+ }
+ } else {
+ if (startTime.trim.nonEmpty && endTime.trim.nonEmpty) {
+ activeResults
+ } else {
+ activeResults.take(limit)
+ }
+ }
+ applyFilter(finalResults, filter, outputType)
+ }
+
+ private def getCombinedCompactionsWithPartitionMetadata(timeline:
HoodieTimeline,
+ limit: Int,
+ metaClient:
HoodieTableMetaClient,
+ startTime: String,
+ endTime: String,
+ timelineType:
String): Seq[Row] = {
Review Comment:
Can we fetch timeline within the method based on the timelineType?
timelineType seems redundant, and it avoid calling this method inconsistently
i.e with timeline set to active timeline and timelineType set to "ARCHIVED"
--
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]