【问题标题】:Is there a way to get access to the Cassandra schema info using the spark-cassandra connector?有没有办法使用 spark-cassandra 连接器访问 Cassandra 模式信息?
【发布时间】:2018-04-27 04:30:46
【问题描述】:
较新的 spark-cassandra 连接器已弃用/删除允许执行 CQL 的 CassandraSQLContext。而且,现在,我找不到一种方法来查找目录信息,例如:键空间列表、键空间内的表或列元数据。
具体来说,我希望能够运行类似select keyspace_name, table_name, column_name, type from system_schema.columns where keyspace_name = 'test' 的东西
也许我错过了运行 CQL 的 API? (我使用的是 2.0 连接器)
【问题讨论】:
标签:
apache-spark
cassandra
spark-cassandra-connector
【解决方案1】:
Spark Cassandra 连接器有 withSessionDo 可以使用的方法,就像在 Java 驱动程序中一样,像这样(采用自 documentation):
import com.datastax.spark.connector.cql.CassandraConnector
CassandraConnector(conf).withSessionDo { session =>
session.execute("select keyspace_name, table_name, column_name,
type from system_schema.columns where keyspace_name = 'test';")
}
但您可以使用更简单的 RDD 操作,如下所示:
sc.cassandraTable("system_schema", "columns").select("keyspace_name","table_name",
...other columns...)
附:另外,请注意通过 Session->Cluster 获得的Metadata 类访问是更便携的方式。