apache-spark - 有没有办法使用 spark-cassandra 连接器访问 Cassandra 模式信息?
问题描述
较新的 spark-cassandra 连接器已弃用/删除了允许执行 CQL 的 CassandraSQLContext。而且,现在,我找不到一种方法来查找目录信息,例如:键空间列表、键空间内的表或列元数据。
具体来说,我希望能够运行类似select keyspace_name, table_name, column_name, type from system_schema.columns where keyspace_name = 'test'
可能我错过了运行 CQL 的 API?(我使用的是 2.0 连接器)
解决方案
Spark Cassandra 连接器具有withSessionDo
您可以使用的方法,与在 Java 驱动程序中使用的方法相同,如下所示(从文档中采用):
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...)
PS 另外,请注意,Metadata
通过 Session->Cluster 可以获得的类访问是更便携的方式。
推荐阅读
- linux - 我需要在 bash 中的用户输入上从一个日期读取文件名到另一个日期
- flutter - 如何提升下拉列表,因为它的某些项目被键盘隐藏?
- c# - EF Core Postgres Update-Database 正在尝试创建已经存在的数据库
- filter - 通过矩阵中的多个维度表过滤事实表(Power BI / Power Pivot)
- django - ImportError:无法从“geodjango”导入名称“docker_config”
- python - 我怎样才能矢量化这个操作?
- azure - Azure 数据工厂中的 Jira 链接服务错误
- mysql - 如何使用 codeigniter 选择和显示存储在数据库表中的“印地语”语言
- python - 添加字符串
- pandas - 在需要特定操作顺序时创建辅助变量