scala - 使用 apache Spark 为 cassandra 插入创建 timeuuid

标签 scala cassandra apache-spark

我正在使用 apache Spark 和 apache cassandra 进行数据分析,并且我正在努力使用 timeuuid 字段插入回 cassandra。

我有下表

CREATE TABLE leech_seed_report.daily_sessions (
    id timeuuid PRIMARY KEY,
    app int,
    count int,
    date bigint,
    offline boolean,
    vendor text,
    version text
) WITH bloom_filter_fp_chance = 0.01
    AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'}
    AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99.0PERCENTILE';
CREATE INDEX daily_sessions_app_idx ON leech_seed_report.daily_sessions (app);
CREATE INDEX daily_sessions_date_idx ON leech_seed_report.daily_sessions (date);
CREATE INDEX daily_sessions_offline_idx ON leech_seed_report.daily_sessions (offline);
CREATE INDEX daily_sessions_vendor_idx ON leech_seed_report.daily_sessions (vendor);
CREATE INDEX daily_sessions_version_idx ON leech_seed_report.daily_sessions (version);

我正在使用

插入行
rows.saveToCassandra("leech_seed_report", "daily_sessions", SomeColumns("id", "date", "app", "vendor", "version", "offline", "count"))

我的行由格式的元组组成

([timmuuid_will_be_here], BigInt, Int, String, String, Boolean, Int)

我尝试过在没有 timeuuid 字段的情况下插入到同一个表中,一切正常,但我一生都无法弄清楚如何为每一行创建 timeuuid

任何帮助将不胜感激,我是 Spark、cassandra 和 scala 的新手,感觉就像我的头撞在砖墙上

谢谢 马特。

最佳答案

最后我尝试使用UUIDGen根据zero323的建议但我收到了一个错误,我认为这是由于缺少依赖项造成的,但我是一个 Scala 新手,无法确定。经过一番研究后,这看起来像是我应该走的路,但当我有更多的时间/经验时,我会再回来考虑它。

我使用 gfc-timeuuid 开始运行 Spark 作业并生成 timeuuid ,就像将以下内容添加到我的 build.sbt 文件中一样简单

libraryDependencies += "com.gilt" %% "gfc-timeuuid" % "0.0.5"

然后在我的 scala 脚本中执行以下操作

import com.gilt.timeuuid._

val tuuid = TimeUuid()

关于scala - 使用 apache Spark 为 cassandra 插入创建 timeuuid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32905698/

相关文章:

scala - 如何在 SBT .scala 项目配置中从多个非托管目录添加 jar

go - 连接到 Cassandra 时获取 "gocql: no response to connection startup within timeout"

scala - spark mllib 将函数应用于 rowMatrix 的所有元素

apache-spark - Spark HashingTF 的工作原理

java - scala.collection.Seq 不适用于 Java

scala - 在 Scala 中使列表像元组一样解构,或使元组像列表一样迭代

scala - 在 Scala 中与齐柏林飞艇一起使用 plotly

cassandra - Cassandra 行缓存和分区键缓存的区别

java - 在 cassandra 中管理多个数据中心集群

apache-spark - worker如何使用standalone Master的资源?