The formula of the precision @ k for measuring the quality of the recommendations:
says that j goes from 0 to min(|D|, k) , but according to the code,
The notation of Spark documentation defines
D_i as the set of ground truth relevant documents for user i
R_i as the set of recommended documents (i.e. predictions) given for user i .
According to the code, the documentation should say j goes from 0 to min( | R_i |, k )