diff --git a/src/main/java/com/highperformancespark/examples/dataframe/JavaHappyPandas.java b/src/main/java/com/highperformancespark/examples/dataframe/JavaHappyPandas.java index 09b5e2f..bc93163 100644 --- a/src/main/java/com/highperformancespark/examples/dataframe/JavaHappyPandas.java +++ b/src/main/java/com/highperformancespark/examples/dataframe/JavaHappyPandas.java @@ -62,7 +62,7 @@ public static DataFrame jsonLoadFromRDD(SQLContext sqlContext, JavaRDD i */ public static DataFrame happyPandasPercentage(DataFrame pandaInfo) { DataFrame happyPercentage = pandaInfo.select(pandaInfo.col("place"), - pandaInfo.col("happyPandas").divide(pandaInfo.col("totalPandas")).as("percentHappy")); + (pandaInfo.col("happyPandas").divide(pandaInfo.col("totalPandas"))).as("percentHappy")); return happyPercentage; } @@ -204,7 +204,7 @@ public static void joins(DataFrame df1, DataFrame df2) { } public static DataFrame selfJoin(DataFrame df) { - return df.as("a").join(df.as("b")).where(df.col("name").equalTo(df.col("name"))); + return (df.as("a")).join(df.as("b")).where("a.name = b.name"); } } diff --git a/src/test/scala/com/high-performance-spark-examples/dataframe/HappyPandasTest.scala b/src/test/scala/com/high-performance-spark-examples/dataframe/HappyPandasTest.scala index f46a2f3..c6d64fe 100644 --- a/src/test/scala/com/high-performance-spark-examples/dataframe/HappyPandasTest.scala +++ b/src/test/scala/com/high-performance-spark-examples/dataframe/HappyPandasTest.scala @@ -54,14 +54,14 @@ class HappyPandasTest extends DataFrameSuiteBase { //tag::approxEqualDataFrames[] test("verify simple happy pandas Percentage") { - val expectedResult = List(Row(toronto, 0.5), Row(sandiego, 2/3.0), Row(virginia, 1/10.0)) - val expectedDf = createDF(expectedResult, ("place", StringType), + val expectedList = List(Row(toronto, 0.5), Row(sandiego, 2/3.0), Row(virginia, 1/10.0)) + val expectedDf = createDF(expectedList, ("place", StringType), ("percentHappy", DoubleType)) val inputDF = sqlContext.createDataFrame(pandaInfoList) - val result = HappyPandas.happyPandasPercentage(inputDF) + val resultDF = HappyPandas.happyPandasPercentage(inputDF) - assertDataFrameApproximateEquals(expectedDf, result, 1E-5) + assertDataFrameApproximateEquals(expectedDf, resultDF, 1E-5) } //end::approxEqualDataFrames[]