vamshikrishnakyatham commented on code in PR #13793:
URL: https://github.com/apache/hudi/pull/13793#discussion_r2316905920


##########
hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/procedures/ShowClusteringProcedure.scala:
##########
@@ -53,32 +133,219 @@ class ShowClusteringProcedure 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 showInvolvedPartitions = getArgValueOrDefault(args, 
PARAMETERS(3)).get.asInstanceOf[Boolean]
+    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)
-    val clusteringInstants = 
metaClient.getActiveTimeline.getInstants.iterator().asScala
+
+    val activeResults = 
getCombinedClusteringsWithPartitionMetadata(metaClient.getActiveTimeline, 
limit, metaClient, startTime, endTime, "ACTIVE")
+    val finalResults = if (showArchived) {
+      val archivedResults = 
getCombinedClusteringsWithPartitionMetadata(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 getCombinedClusteringsWithPartitionMetadata(timeline: 
HoodieTimeline,
+                                                          limit: Int,
+                                                          metaClient: 
HoodieTableMetaClient,
+                                                          startTime: String,
+                                                          endTime: String,
+                                                          timelineType: 
String): Seq[Row] = {
+    val allRows = scala.collection.mutable.ListBuffer[Row]()
+
+    val filteredClusteringInstants = timeline.getInstants.iterator().asScala
       .filter(p => 
ClusteringUtils.isClusteringOrReplaceCommitAction(p.getAction))

Review Comment:
   Okay



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

Reply via email to