Is there any way to Load Spark SQL resultset (data

2019-09-14 20:05发布

问题:

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