Skip to content

Commit 2b6fbb5

Browse files
authored
Update HousePriceSolution.scala
1 parent 716dc0d commit 2b6fbb5

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/main/scala/com/sparkTutorial/sparkSql/HousePriceSolution.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ import org.apache.spark.sql.SparkSession
55

66
object HousePriceSolution {
77

8-
val PRICE = "Price"
98
val PRICE_SQ_FT = "Price SQ Ft"
109

1110
def main(args: Array[String]) {
1211

1312
Logger.getLogger("org").setLevel(Level.ERROR)
1413
val session = SparkSession.builder().appName("HousePriceSolution").master("local[1]").getOrCreate()
1514

16-
val realEstate = session.read.option("header", "true").csv("in/RealEstate.csv")
15+
val realEstate = session.read
16+
.option("header", "true")
17+
.option("inferSchema", value = true)
18+
.csv("in/RealEstate.csv")
1719

18-
val castedRealEstate = realEstate.withColumn(PRICE, realEstate(PRICE).cast("long"))
19-
.withColumn(PRICE_SQ_FT, realEstate(PRICE_SQ_FT).cast("long"))
20-
21-
castedRealEstate.groupBy("Location")
20+
realEstate.groupBy("Location")
2221
.avg(PRICE_SQ_FT)
2322
.orderBy("avg(Price SQ Ft)")
2423
.show()

0 commit comments

Comments
 (0)