Question
I have a massive Spark Dataframe, called x. I am using databricks. x is billions of records long, too large to collect onto a single machine. What do I have to do to get this to work?:
dplyr::summarize_all(x,mean)
More Info
This is the error message I currently get:
Error in UseMethod("tbl_vars") :
no applicable method for 'tbl_vars' applied to an object of class "SparkDataFrame"
and
class(x)
returns: [1] "SparkDataFrame" attr(,"package") [1] "SparkR"
The book, Mastering Spark with R , has an example of loading up a tiny r data frame, and running summarize_all on it:
cars <- copy_to(sc, mtcars)
summarize_all(cars, mean)
Note the above code works on my databricks cluster and returns a nice block of text:
# Source: spark<?> [?? x 11]
mpg cyl disp hp drat wt qsec vs am gear carb
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 20.1 6.19 231. 147. 3.60 3.22 17.8 0.438 0.406 3.69 2.81
The same book leads me to believe I can use this and similar functions on huge spark dataframes.
and also
class(cars)
returns:
[1] "tbl_spark" "tbl_sql" "tbl_lazy" "tbl"
It seems obvious that I need to convert my spark dataframe to a tbl_spark, tbl_sql, tbl_lazy or tbl so that I can pass it to dplyr::summarize_all, but I have searched all over the place and asked experts and cannot figure out how to do this.