Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/main/scala/org/graphframes/GraphFrame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ class GraphFrame private(
override def toString: String = {
// We call select on the vertices and edges to ensure that ID, SRC, DST always come first
// in the printed schema.
val v = vertices.select(ID, vertices.columns.filter(_ != ID) :_ *).toString
val e = edges.select(SRC, DST +: edges.columns.filter(c => c != SRC && c != DST) :_ *).toString
val vCols = (ID +: vertices.columns.filter(_ != ID).toIndexedSeq).map(col)
val eCols = (SRC +: DST +: edges.columns.filter(c => c != SRC && c != DST).toIndexedSeq).map(col)
val v = vertices.select(vCols.toSeq: _*).toString
val e = edges.select(eCols.toSeq: _*).toString
"GraphFrame(v:" + v + ", e:" + e + ")"
}

Expand Down Expand Up @@ -708,7 +710,7 @@ object GraphFrame extends Serializable with Logging {
def fromEdges(e: DataFrame): GraphFrame = {
val srcs = e.select(e("src").as("id"))
val dsts = e.select(e("dst").as("id"))
val v = srcs.unionAll(dsts).distinct
val v = srcs.unionAll(dsts).distinct()
v.persist(StorageLevel.MEMORY_AND_DISK)
apply(v, e)
}
Expand Down Expand Up @@ -802,7 +804,7 @@ object GraphFrame extends Serializable with Logging {
private[graphframes] def colStar(df: DataFrame, col: String): Seq[String] = {
df.schema(col).dataType match {
case s: StructType =>
s.fieldNames.map(f => col + "." + f)
s.fieldNames.map(f => col + "." + f).toIndexedSeq
case other =>
throw new RuntimeException(s"Unknown error in GraphFrame. Expected column $col to be" +
s" StructType, but found type: $other")
Expand All @@ -811,7 +813,7 @@ object GraphFrame extends Serializable with Logging {

/** Nest all columns within a single StructType column with the given name */
private[graphframes] def nestAsCol(df: DataFrame, name: String): Column = {
struct(df.columns.map(c => df(c)) :_*).as(name)
struct(df.columns.map(c => df(c)).toSeq: _*).as(name)
}

// ========== Motif finding ==========
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ object BeliefPropagation {
def runBPwithGraphX(g: GraphFrame, numIter: Int): GraphFrame = {
// Choose colors for vertices for BP scheduling.
val colorG = colorGraph(g)
val numColors: Int = colorG.vertices.select("color").distinct.count().toInt
val numColors: Int = colorG.vertices.select("color").distinct().count().toInt

// Convert GraphFrame to GraphX, and initialize beliefs.
val gx0 = colorG.toGraphX
Expand Down Expand Up @@ -206,7 +206,7 @@ object BeliefPropagation {
def runBPwithGraphFrames(g: GraphFrame, numIter: Int): GraphFrame = {
// Choose colors for vertices for BP scheduling.
val colorG = colorGraph(g)
val numColors: Int = colorG.vertices.select("color").distinct.count().toInt
val numColors: Int = colorG.vertices.select("color").distinct().count().toInt

// TODO: Handle vertices without any edges.

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/org/graphframes/examples/Graphs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ class Graphs private[graphframes] () {
*/
def ALSSyntheticData(): GraphFrame = {
val sc = spark.sparkContext
val data = sc.parallelize(als_data).map { line =>
val data = sc.parallelize(als_data.toIndexedSeq).map { line =>
val fields = line.split(",")
(fields(0).toLong * 2, fields(1).toLong * 2 + 1, fields(2).toDouble)
}
val edges = spark.createDataFrame(data).toDF("src", "dst", "weight")
val vs = data.flatMap(r => r._1 :: r._2 :: Nil).collect().distinct.map(x => Tuple1(x))
val vs = data.flatMap(r => r._1 :: r._2 :: Nil).collect().distinct.map(x => Tuple1(x)).toIndexedSeq
val vertices = spark.createDataFrame(vs).toDF("id")
GraphFrame(vertices, edges)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/graphframes/lib/BFS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private object BFS extends Logging with Serializable {
}
}
val ordered = paths.columns.sortBy(rank _)
paths.select(ordered.map(col): _*)
paths.select(ordered.map(col).toSeq: _*)
} else {
logInfo(s"GraphFrame.bfs failed to find a path of length <= $maxPathLength.")
// Return empty DataFrame
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/org/graphframes/lib/GraphXConversions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ private[graphframes] object GraphXConversions {
val otherFields = df.schema.fieldNames.filter(_ != structName).map(col)
if (renamedSubfields.isEmpty) {
// Do not attempt to add an empty structure.
df.select(otherFields : _*)
df.select(otherFields.toSeq: _*)
} else {
val renamedStruct = struct(renamedSubfields : _*).as(structName)
df.select(renamedStruct +: otherFields : _*)
val renamedStruct = struct(renamedSubfields.toSeq: _*).as(structName)
df.select((renamedStruct +: otherFields).toSeq: _*)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/org/graphframes/lib/ShortestPaths.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.graphframes.lib

import java.util

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

import org.apache.spark.graphx.{lib => graphxlib}
import org.apache.spark.sql.{Column, DataFrame, Row}
Expand Down Expand Up @@ -91,7 +91,7 @@ private object ShortestPaths {
mapToLandmark(col(DISTANCE_ID))
}
val cols = graph.vertices.columns.map(col) :+ distanceCol.as(DISTANCE_ID)
g.vertices.select(cols: _*)
g.vertices.select(cols.toSeq: _*)
}

private val DISTANCE_ID = "distances"
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/graphframes/lib/TriangleCount.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private object TriangleCount {
val v = graph.vertices
val countsCol = when(col("count").isNull, 0L).otherwise(col("count"))
val newV = v.join(triangleCounts, v(ID) === triangleCounts(ID), "left_outer")
.select(countsCol.as(COUNT_ID) +: v.columns.map(v.apply) :_ *)
.select((countsCol.as(COUNT_ID) +: v.columns.map(v.apply)).toSeq: _*)
newV
}

Expand Down