File tree 1 file changed +5
-6
lines changed
src/main/scala/com/sparkTutorial/sparkSql
1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -5,20 +5,19 @@ import org.apache.spark.sql.SparkSession
5
5
6
6
object HousePriceSolution {
7
7
8
- val PRICE = " Price"
9
8
val PRICE_SQ_FT = " Price SQ Ft"
10
9
11
10
def main (args : Array [String ]) {
12
11
13
12
Logger .getLogger(" org" ).setLevel(Level .ERROR )
14
13
val session = SparkSession .builder().appName(" HousePriceSolution" ).master(" local[1]" ).getOrCreate()
15
14
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" )
17
19
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" )
22
21
.avg(PRICE_SQ_FT )
23
22
.orderBy(" avg(Price SQ Ft)" )
24
23
.show()
You can’t perform that action at this time.
0 commit comments