diff --git a/code/Structured_APIs-Chapter_6_Working_with_Different_Types_of_Data.py b/code/Structured_APIs-Chapter_6_Working_with_Different_Types_of_Data.py index ed4168d..6832e34 100644 --- a/code/Structured_APIs-Chapter_6_Working_with_Different_Types_of_Data.py +++ b/code/Structured_APIs-Chapter_6_Working_with_Different_Types_of_Data.py @@ -310,13 +310,13 @@ def color_locator(column, color_string): # COMMAND ---------- -df.select(map(col("Description"), col("InvoiceNo")).alias("complex_map"))\ +df.select(create_map(col("Description"), col("InvoiceNo")).alias("complex_map"))\ .selectExpr("complex_map['WHITE METAL LANTERN']").show(2) # COMMAND ---------- -df.select(map(col("Description"), col("InvoiceNo")).alias("complex_map"))\ +df.select(create_map(col("Description"), col("InvoiceNo")).alias("complex_map"))\ .selectExpr("explode(complex_map)").show(2) @@ -331,7 +331,7 @@ def color_locator(column, color_string): from pyspark.sql.functions import get_json_object, json_tuple jsonDF.select( - get_json_object(col("jsonString"), "$.myJSONKey.myJSONValue[1]") as "column", + get_json_object(col("jsonString"), "$.myJSONKey.myJSONValue[1]").alias("column"), json_tuple(col("jsonString"), "myJSONKey")).show(2) diff --git a/code/Structured_APIs-Chapter_7_Aggregations.py b/code/Structured_APIs-Chapter_7_Aggregations.py index a6155f7..daf3224 100644 --- a/code/Structured_APIs-Chapter_7_Aggregations.py +++ b/code/Structured_APIs-Chapter_7_Aggregations.py @@ -179,3 +179,6 @@ # COMMAND ---------- +pivoted.where("date > '2011-12-05'")\ + .select("date", "`USA_sum(CAST(Quantity AS BIGINT))`")\ + .show()