QuestionQ161

VerifiedTroubleshooting and Tuning Apache Spark DataFrame API Applications.

A data engineer is addressing complaints that a feature-engineering job has been declining in performance over time. After discussing the feature table with the data science team, it was decided that replacing the percentile() Spark function with approx_percentile() Spark function is acceptable to trade some accuracy for performance.

features_df = raw_df \  
.select(F.approx_percentile("price", percentage=[0.25, 0.5, 0.75], accuracy=1000).alias("price_perc"))  

The initial code change provides a greater-than-expected improvement in job runtime; however, the data scientists find that the returned percentiles are now drifting too far from the correct values.

Which change should the data engineer make to resolve the issue?

Explanation

For Spark approx_percentile, the accuracy parameter controls the precision-memory trade-off: a higher value improves approximation accuracy and lowers relative error, while using more memory. The percentage values only select the requested percentile positions (0.25, 0.5, and 0.75); they do not improve approximation accuracy.

Learn more

Community Discussion

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