Spark RDD地图如何到Cassandra桌子?

发布于 2025-01-26 11:20:08 字数 427 浏览 9 评论 0原文

我是Spark的新手,最近我看到一个代码将RDD格式的数据保存到Cassandra Table。但是我无法弄清楚它如何进行列映射。它都不使用案例类,也指定了以下代码中的任何列名称:

rdd
.map(x => (x._1, x._2, x_3)) // x is a List here
.repartitionByCassandraReplica(keyspace, tableName)
.saveToCassandra(keyspace, tableName)

因为x内部只是list [(int,string,int)],这不是案例类,没有名字映射到卡桑德拉桌子上。因此,在Cassandra表中,是否有任何确定的顺序可以匹配我们在代码中指定的列的顺序?

I am new to Spark, and recently I saw a code is saving data in RDD format to Cassandra table. But I am not able to figure it out how it is doing the column mapping. It neither uses case class, also specifies any column names in the code like below:

rdd
.map(x => (x._1, x._2, x_3)) // x is a List here
.repartitionByCassandraReplica(keyspace, tableName)
.saveToCassandra(keyspace, tableName)

Since x inside is simply a List[(Int, String, Int)], which is not a case class, there is no name mapping to Cassandra table. So is there any definite order in Cassandra table that can match the order of columns we specify in the code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有你 2025-02-02 11:20:08

该映射依赖于Cassandra表定义中的列的顺序,如以下内容:

  • 在指定顺序群集列中的分区键列中指定的
  • 顺序列中的指定顺序
  • 按字母顺序排序的其余列的名称

Spark Cassandra Connector依赖于表定义的这些列来自表将与Scala元组中的字段顺序匹配。您可以看到,在源代码

This mapping relies on the order of columns in the Cassandra table definition that is as following:

  • Partition key columns in the specified order
  • Clustering columns in the specified order
  • Alphabetically sorted by name for rest of the columns

Spark Cassandra Connector relies that these columns from table definition will be matched to the order of fields in the Scala tuple. You can see that in the source code of TupleColumnMapper class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文