I am new to Spark and currently use it with the R API through a vibrant package. I created a Spark data frame from a bush request. The data types are not specified correctly in the source table, and I am trying to use the reset data type using functions from the package dplyr. Below is the code I tried:
prod_dev <- sdf_load_table(...)
num_var <- c("var1", "var2"....)
cat_var <- c("var_a","var_b", ...)
pos1 <- which(colnames(prod_dev) %in% num_var)
pos2 <- which(colnames(prod_dev) %in% cat_var)
prod_model_tbl <- prod_dev %>%
mutate(age = 2016- as.numeric(substr(dob_yyyymmdd,1,4))) %>%
mutate(msa_fg = ifelse(is.na(msacode2000), 0, 1)) %>%
mutate(csa_fg = ifelse(is.na(csacode), 0, 1)) %>%
mutate_each(funs(factor), pos2) %>%
mutate_each(funs(as.numeric), pos1)
The code will work if prod_dev is an R data frame. But using it in a Spark Data frame does not seem to produce the correct result:
> head(prod_model_tbl)
Source: query [?? x 99]
Database: spark connection master=yarn-client app=sparklyr_test local=FALSE
Error: org.apache.spark.sql.AnalysisException: undefined function FACTOR; line 97 pos 2248 at org.apache.spark.sql.hive.HiveFunctionRegistry....
Can someone please advise how to make the necessary changes to the Spark Data Frame?
source
share