I saw that a general recommendation for anyone using spark (in my case with Scala) is to avoid any action that gets all data from executers to driver (collect, count, sum etc). However, when I tried to use spark statistic library http://spark.apache.org/docs/2.2.0/ml-statistics.html I found out that the correlation matrix and ChiSquareTest methods expect array or matrix obtained of array\seq as their parameters, hence I do not see how I could avoid do collect to the dataframe (and some more manipulation I assume to make it of Vectors not Row type) if I want to use this functions. Will appreciate any help.