使用SparkR 1.6.0,我可以使用以下代码从JDBC源读取
jdbc_url <- "jdbc:mysql://localhost:3306/dashboard?user=<username>&password=<password>"
df <- sqlContext %>%
loadDF(source = "jdbc",
url = jdbc_url,
driver = "com.mysql.jdbc.Driver",
dbtable = "db.table_name")
但是在执行计算之后,当我尝试将数据写回数据库时,我尝试了一个障碍...
write.df(df = df,
path = "NULL",
source = "jdbc",
url = jdbc_url,
driver = "com.mysql.jdbc.Driver",
dbtable = "db.table_name",
mode = "append")
...返回......
ERROR RBackendHandler: save on 55 failed
Error in invokeJava(isStatic = FALSE, objId$id, methodName, ...) :
java.lang.RuntimeException: org.apache.spark.sql.execution.datasources.jdbc.DefaultSource does not allow create table as select.
at scala.sys.package$.error(package.scala:27)
at org.apache.spark.sql.execution.datasources.ResolvedDataSource$.apply(ResolvedDataSource.scala:259)
at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:148)
at org.apache.spark.sql.DataFrame.save(DataFrame.scala:2066)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.spark.api.r.RBackendHandler.handleMethodCall(RBackendHandler.scala:141)
at org.apache.spark.api.r.RBackendHandler.channelRead0(RBackendHandler.scala:86)
at org.apache.spark.api.r.RBackendHandler.channelRead0(RBackendHandler.scala:38)
at io.netty.channel.SimpleChannelIn
环顾网页,我发现this告诉我,自2.0.0版本开始,包含了此错误的补丁。我们还获得了read.jdbc
和write.jdbc
函数。
但是,对于这个问题,假设我坚持使用SparkR v1.6.0。有没有办法写入JDBC源(即是否有一种解决方法可以让我使用SparkR中的DataFrameWriter.jdbc()
)?
答案 0 :(得分:0)
简短的回答是,不,在版本2.0.0之前,SparkR不支持JDBC写入方法。