QuestionQ157

VerifiedTroubleshooting and Tuning Apache Spark DataFrame API Applications.

A data scientist is using a large Apache Spark dataset and has written the following code:

df = spark.read.csv(“large_dataset.csv”)  
filtered_df = df.filter(col(“error_column”).contains(“error”))  
mapped_df = filtered_df.select(split(col(“timestamp”), “ “).getItem(0).alias(“date”), lit(1).alias(“count”))  
reduced_df = mapped_df.groupBy(“date”).sum(“count”)  
reduced_df.count()  
reduced_df.show()  

At what point in this code does Spark actually start processing the data?

Explanation

Spark Dataset/DataFrame transformations are lazy: operations such as filter, select, and groupBy create a logical plan but do not execute it. count() is an action that triggers computation and returns a result, so it is the first statement that starts processing the data. show() is also an action, but it occurs afterward.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!