Skip to content

Commit

Permalink
Spark scala code change for request addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
chetkhatri committed Dec 28, 2017
1 parent 5507cad commit 79e6789
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ object Analytics extends Logging {
// TriangleCount requires the graph to be partitioned
.partitionBy(partitionStrategy.getOrElse(RandomVertexCut)).cache()
val triangles = TriangleCount.run(graph)
println(s"Triangles: ${triangles.vertices.map {
val triangleTypes = triangles.vertices.map {
case (vid, data) => data.toLong
}.reduce(_ + _) / 3}")
}.reduce(_ + _) / 3

println(s"Triangles: ${triangleTypes}")
sc.stop()

case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ object CorrelationExample {

val df = data.map(Tuple1.apply).toDF("features")
val Row(coeff1: Matrix) = Correlation.corr(df, "features").head
println(s"Pearson correlation matrix:\n ${coeff1.toString}")
println(s"Pearson correlation matrix:\n $coeff1")

val Row(coeff2: Matrix) = Correlation.corr(df, "features", "spearman").head
println(s"Spearman correlation matrix:\n ${coeff2.toString}")
println(s"Spearman correlation matrix:\n $coeff2")
// $example off$

spark.stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ object QuantileDiscretizerExample {

// $example on$
val data = Array((0, 18.0), (1, 19.0), (2, 8.0), (3, 5.0), (4, 2.2))
val df = spark.createDataFrame(data).toDF("id", "hour").repartition(1)
val df = spark.createDataFrame(data).toDF("id", "hour")
// $example off$
// Output of QuantileDiscretizer for such small datasets can depend on the number of
// partitions. Here we force a single partition to ensure consistent results.
// Note this is not necessary for normal use cases
.repartition(1)

// $example on$
val discretizer = new QuantileDiscretizer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CustomReceiver(host: String, port: Int)
var socket: Socket = null
var userInput: String = null
try {
logInfo(s"Connecting to $host $port")
logInfo(s"Connecting to $host : $port")
socket = new Socket(host, port)
logInfo(s"Connected to $host : $port")
val reader = new BufferedReader(
Expand Down

0 comments on commit 79e6789

Please sign in to comment.