![](/img/trans.png)
[英]Spark JoinWithCassandraTable on TimeStamp partition key STUCK
[英]Spark joinWithCassandraTable() on map multiple partition key ERROR
我試圖通過使用以下方法過濾大型Cassandra表的一小部分:
val snapshotsFiltered = sc.parallelize(startDate to endDate).map(TableKey(_2)).joinWithCassandraTable("listener","snapshots_test_b")
我想映射cassandra表中作為分區鍵的一部分的'created'列中的行。
我的表鍵(表的分區鍵)定義為:
case class TableKey(imei: String, created: Long, when: Long)
結果是錯誤:
[error] /home/ubuntu/scala/test/test.scala:61:沒有足夠的方法適用於方法:( imei:String,created:Long)test.TableKey in object TableKey。 [error]已創建未指定的值參數。 [error] val snapshotsFiltered = sc.parallelize(startDate to endDate).map(TableKey(_2))。joinWithCassandraTable(“listener”,“snapshots_test_b”)[error] ^ [error]發現一個錯誤[error](編譯:編譯) )編譯失敗
它只與文檔中的分區鍵中的一個對象一起使用。
為什么多分區密鑰有問題? - 已回答。
編輯:我試圖以正確的形式使用joinWithCassandraTable:
val snapshotsFiltered = sc.parallelize(startDate to endDate).map(TableKey("*",_,startDate)).joinWithCassandraTable("listener","snapshots_test_c")
當我試圖在Spark上運行它沒有錯誤,但它永遠停留在“[階段0:>(0 + 2)/ 2]”
出了什么問題?
該錯誤告訴您類TableKey
需要3個組件進行初始化,但只傳遞了一個參數。 這是Scala編譯錯誤,與C *或Spark無關。
val snapshotsFiltered = sc.parallelize(startDate to endDate)
.map(TableKey(_2)) /// Table Key does not have a single element constructor so this will fail
.joinWithCassandraTable("listener","snapshots_test_b")
通常,C *使用整個partition key
確定特定行的位置。 因此,如果您知道整個partition key
,則只能有效地提取數據,因此只傳遞一部分partition key
沒有任何價值。
joinWithCassandraTable需要完整的partition key
因此它可以有效地完成它的工作。 如果您只有部分parition key
,則需要執行全表掃描並使用Spark進行過濾。
如果您只想基於clustering column
進行篩選,可以通過將where
子句下推到C *來實現,例如
sc.cassandraTable("ks","test").where("clustering_key > someValue")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.