Skip to content

Commit

Permalink
Update Spark4Physicists.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
abualia4 authored Aug 8, 2019
1 parent 6b9b67a commit 8ca4a1c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Spark4Physicists.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,27 @@ start = System.nanoTime()
gal.describe( ).show()
finish = System.nanoTime()
elapsedTime(start,finish)

// Minimum and Maximum spark functions
start = System.nanoTime()
val minMax= gal.select(min("z"),max("z") ).first()
val zMax =minMax(1).asInstanceOf[Float]
val zMin =minMax(0).asInstanceOf[Float]
println("Minimum Value:"+ zMin+ "\t"+ "Maximum Value:"+ zMax)
finish = System.nanoTime()
elapsedTime(start,finish)

//Adding the zbin number column (labelled “bin”)
start = System.nanoTime()
val Nbins=100
var dz=(zMax-zMin)/Nbins
val zBin=gal.select("Z").withColumn("bin", ((col("Z")-zMin-dz/2)/dz).cast(IntegerType) )

//Grouping by the bin column, counting its membersand sorting in ascending order
var h=zBin.groupBy("bin").count.orderBy("bin")
//add the bin locations and drop the bin numer
h=h.withColumn("loc", col("bin")*dz+zMin+dz/2 ).drop("bin")
h=h.select("loc","count")
h.show()
finish = System.nanoTime()
elapsedTime(start,finish)

0 comments on commit 8ca4a1c

Please sign in to comment.