Skip to content

Commit

Permalink
Switch to using Session over legacy context.
Browse files Browse the repository at this point in the history
  • Loading branch information
holdenk committed Sep 20, 2023
1 parent e421619 commit 35ec4ce
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scala.util.Random

import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.Row
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.{SQLContext, SparkSession}
import org.apache.spark.sql.types._

import com.highperformancespark.examples.dataframe.HappyPandas.PandaInfo
Expand Down Expand Up @@ -68,15 +68,15 @@ class HappyPandasTest extends AnyFunSuite with DataFrameSuiteBase {
val expectedDf = createDF(expectedList, ("place", StringType),
("percentHappy", DoubleType))

val inputDF = sqlContext.createDataFrame(pandaInfoList)
val inputDF = spark.createDataFrame(pandaInfoList)
val resultDF = HappyPandas.happyPandasPercentage(inputDF)

assertDataFrameApproximateEquals(expectedDf, resultDF, 1E-5)
}
//end::approxEqualDataFrames[]

test("verify approx by hand") {
val inputDF = sqlContext.createDataFrame(pandaInfoList)
val inputDF = spark.createDataFrame(pandaInfoList)
val resultDF = HappyPandas.happyPandasPercentage(inputDF)
val resultRows = resultDF.collect()

Expand All @@ -94,7 +94,7 @@ class HappyPandasTest extends AnyFunSuite with DataFrameSuiteBase {
}

test("test encode Panda type") {
val inputDF = sqlContext.createDataFrame(rawPandaList)
val inputDF = spark.createDataFrame(rawPandaList)
val resultDF = HappyPandas.encodePandaType(inputDF)

val expectedRows = List(Row(10L, 0), Row(11L, 1))
Expand All @@ -107,7 +107,7 @@ class HappyPandasTest extends AnyFunSuite with DataFrameSuiteBase {
//tag::exactEqualDataFrames[]
test("verify exact equality") {
// test minHappyPandas
val inputDF = sqlContext.createDataFrame(pandaInfoList)
val inputDF = spark.createDataFrame(pandaInfoList)
val result = HappyPandas.minHappyPandas(inputDF, 2)
val resultRows = result.collect()

Expand All @@ -117,12 +117,12 @@ class HappyPandasTest extends AnyFunSuite with DataFrameSuiteBase {
//end::exactEqualDataFrames[]

test("test happyPandasPlaces") {
val inputDF = sqlContext.createDataFrame(pandaInfoList)
val inputDF = spark.createDataFrame(pandaInfoList)
val resultDF = HappyPandas.happyPandasPlaces(inputDF)

val expectedRows = List(PandaInfo(toronto, "giant", 1, 2),
PandaInfo(sandiego, "red", 2, 3))
val expectedDF = sqlContext.createDataFrame(expectedRows)
val expectedDF = spark.createDataFrame(expectedRows)

assertDataFrameEquals(expectedDF, resultDF)
}
Expand Down

0 comments on commit 35ec4ce

Please sign in to comment.