how to use Cassandra Context in spark 2.0

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 03:42:57

Short Answer: You don't. It has been deprecated and removed.

Long Answer: You don't want to. The HiveContext provides everything except for the catalogue and supports a much wider range of SQL(HQL~). In Spark 2.0 this just means you will need to manually register Cassandra tables use createOrReplaceTempView until an ExternalCatalogue is implemented.

In Sql this looks like

spark.sql("""CREATE TEMPORARY TABLE words
     |USING org.apache.spark.sql.cassandra
     |OPTIONS (
     |  table "words",
     |  keyspace "test")""".stripMargin)

In the raw DF api it looks like

spark
 .read
 .format("org.apache.spark.sql.cassandra")
 .options(Map("keyspace" -> "test", "table" -> "words"))
 .load
 .createOrReplaceTempView("words")

Both of these commands will register the table "words" for SQL queries.

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