zhengruifeng commented on code in PR #58302:
URL: https://github.com/apache/spark/pull/58302#discussion_r4281533956


##########
graphframes/src/main/scala/org/apache/spark/graphframes/lib/RandomizedContraction.scala:
##########
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.graphframes.lib
+
+import java.io.IOException
+import java.util.UUID
+
+import scala.collection.mutable.Stack
+import scala.util.Random
+
+import org.apache.hadoop.fs.Path
+
+import org.apache.spark.graphframes.GraphFrame
+import org.apache.spark.graphframes.GraphFrame.{DST, ID, LONG_DST, LONG_ID, 
LONG_SRC, SRC}
+import org.apache.spark.graphframes.Logging
+import org.apache.spark.sql.Column
+import org.apache.spark.sql.DataFrame
+import org.apache.spark.sql.catalyst.FunctionIdentifier
+import org.apache.spark.sql.catalyst.expressions.Expression
+import org.apache.spark.sql.functions._
+import org.apache.spark.sql.graphframes.expressions.FiniteAXPlusB
+import org.apache.spark.storage.StorageLevel
+
+/**
+ * Implementation of parallel connected components algorithm using randomized 
contraction, based
+ * on Boegeholz, Harald, Michael Brand, and Radu-Alexandru Todor. "In-database 
connected component
+ * analysis." 2020 IEEE 36th International Conference on Data Engineering 
(ICDE). IEEE, 2020.
+ *
+ * The algorithm contracts the graph iteratively using random linear 
functions, until no edges
+ * remain, then reconstructs the component identifiers.
+ */
+private[graphframes] object RandomizedContraction extends Logging with 
Serializable {
+  private val CHECKPOINT_NAME_PREFIX = "randomized-contraction"
+
+  private def prepare(graph: GraphFrame): GraphFrame = {
+    val vertices = graph.indexedVertices
+      .select(col(LONG_ID).as(ID))
+
+    val edges = graph.indexedEdges
+      .select(col(LONG_SRC).as(SRC), col(LONG_DST).as(DST))
+    val symmetricEdges = edges
+      .union(edges.select(col(DST).alias(SRC), col(SRC).alias(DST)))
+      .distinct()
+    GraphFrame(vertices, symmetricEdges)
+
+  }
+
+  def run(
+      inputGraph: GraphFrame,
+      useLabelsAsComponents: Boolean,
+      intermediateStorageLevel: StorageLevel,
+      useLocalCheckpoints: Boolean,
+      checkpointInterval: Int,
+      isGraphPrepared: Boolean): DataFrame = {
+    val spark = inputGraph.vertices.sparkSession
+    val sc = spark.sparkContext
+    val runId = UUID.randomUUID().toString.takeRight(8)
+    val logPrefix = s"[CC $runId]"
+
+    val checkpointDir = sc.getCheckpointDir
+      .map { d =>
+        new Path(d, s"$CHECKPOINT_NAME_PREFIX-$runId").toString
+      }
+      .getOrElse {
+        // Spark-Connect workaround
+        spark.conf.getOption("spark.checkpoint.dir") match {

Review Comment:
   may I ask why not directly use df.checkpoint in this algorithm?



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