Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ private void start() {
.master("local")
.getOrCreate();

// Reads a CSV file with header, called books.csv, stores it in a
// dataframe
// Reads a CSV file with header, called
// Restaurants_in_Wake_County_NC.csv,
// stores it in a dataframe
Dataset<Row> df = spark.read().format("csv")
.option("header", "true")
.load("data/Restaurants_in_Wake_County_NC.csv");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ private void start() {
.withColumn("dateEnd", df.col("fields.closing_date"))
.withColumn("type",
split(df.col("fields.type_description"), " - ").getItem(1))
.withColumn("geoX", df.col("fields.geolocation").getItem(0))
.withColumn("geoY", df.col("fields.geolocation").getItem(1));
.withColumn("geoX", df.col("fields.geolocation").getItem(1))
.withColumn("geoY", df.col("fields.geolocation").getItem(0));
df = df.withColumn("id",
concat(df.col("state"), lit("_"),
df.col("county"), lit("_"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ private Dataset<Row> buildDurhamRestaurantsDataframe() {
.withColumn("dateEnd", df.col("fields.closing_date"))
.withColumn("type",
split(df.col("fields.type_description"), " - ").getItem(1))
.withColumn("geoX", df.col("fields.geolocation").getItem(0))
.withColumn("geoY", df.col("fields.geolocation").getItem(1))
.withColumn("geoX", df.col("fields.geolocation").getItem(1))
.withColumn("geoY", df.col("fields.geolocation").getItem(0))
.drop(df.col("fields"))
.drop(df.col("geometry"))
.drop(df.col("record_timestamp"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def main(spark):
.withColumn("dateStart", F.col("fields.opening_date")) \
.withColumn("dateEnd", F.col("fields.closing_date")) \
.withColumn("type", F.split(F.col("fields.type_description"), " - ").getItem(1)) \
.withColumn("geoX", F.col("fields.geolocation").getItem(0)) \
.withColumn("geoY", F.col("fields.geolocation").getItem(1))
.withColumn("geoX", F.col("fields.geolocation").getItem(1)) \
.withColumn("geoY", F.col("fields.geolocation").getItem(0))

df = df.withColumn("id", F.concat(F.col("state"), F.lit("_"),
F.col("county"), F.lit("_"),
Expand Down
4 changes: 2 additions & 2 deletions src/main/python/lab230_dataframe_union/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def build_durham_restaurants_dataframe(df):
.withColumn("dateStart", F.col("fields.opening_date")) \
.withColumn("dateEnd", F.col("fields.closing_date")) \
.withColumn("type", F.split(F.col("fields.type_description"), " - ").getItem(1)) \
.withColumn("geoX", F.col("fields.geolocation").getItem(0)) \
.withColumn("geoY", F.col("fields.geolocation").getItem(1)) \
.withColumn("geoX", F.col("fields.geolocation").getItem(1)) \
.withColumn("geoY", F.col("fields.geolocation").getItem(0)) \
.drop(*drop_cols)

df = df.withColumn("id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ object SchemaIntrospectionScalaApp {
val spark = SparkSession.builder.appName("Schema introspection for restaurants in Wake County, NC")
.master("local").getOrCreate

// Reads a CSV file with header, called books.csv, stores it in a
// dataframe
// Reads a CSV file with header, called
// Restaurants_in_Wake_County_NC.csv,
// stores it in a dataframe
var df = spark.read.format("csv").option("header", "true")
.load("data/Restaurants_in_Wake_County_NC.csv")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ object JsonIngestionSchemaManipulationScalaApp {
.withColumn("dateStart", col("fields.opening_date"))
.withColumn("dateEnd", col("fields.closing_date"))
.withColumn("type", split(col("fields.type_description"), " - ").getItem(1))
.withColumn("geoX", col("fields.geolocation").getItem(0))
.withColumn("geoY", col("fields.geolocation").getItem(1))
.withColumn("geoX", col("fields.geolocation").getItem(1))
.withColumn("geoY", col("fields.geolocation").getItem(0))

val cols_list = List(col("state"), lit("_"), col("county"), lit("_"), col("datasetId"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ object DataframeUnionScalaApp {
.withColumn("dateStart", col("fields.opening_date"))
.withColumn("dateEnd", col("fields.closing_date"))
.withColumn("type", split(col("fields.type_description"), " - ").getItem(1))
.withColumn("geoX", col("fields.geolocation").getItem(0))
.withColumn("geoY", col("fields.geolocation").getItem(1))
.withColumn("geoX", col("fields.geolocation").getItem(1))
.withColumn("geoY", col("fields.geolocation").getItem(0))
.drop(drop_cols:_*)

df1 = df1.withColumn("id",
Expand Down