Is there any way to Load Spark SQL resultset (data frames ) back to cassandra?

点点圈 提交于 2020-01-07 07:50:51

问题


I have queried Cassandra using spark in Scala. Below is the result:

Is there any way to write this result back to Cassandra tables ?


回答1:


df.write
  .format("org.apache.spark.sql.cassandra")
  .options(Map( "table" -> "t_payu_df", "keyspace" -> "ks_payu"))
  .save()

This will work.

You can also specify SaveMode (overwrite,append,ErrorIfExists).

Example with SaveMode:

df.write
  .format("org.apache.spark.sql.cassandra")
  .mode(SaveMode.Overwrite)
  .options(Map( "table" -> "t_payu_df", "keyspace" -> "ks_payu"))
  .save()

For more details visit Dataframe



来源:https://stackoverflow.com/questions/42994053/is-there-any-way-to-load-spark-sql-resultset-data-frames-back-to-cassandra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!