我正在嘗試使用我的 Spark Scala 應用程式將資料系結到 Cassandra 中的映射型別列。
val updateTemplate = s"""UPDATE test_ks.test_table_ttl USING TTL 5
|SET ttl_col = ttl_col {:mapKey : (':value1', ':value2')}
|WHERE consumer_id=:consumer_id""".stripMargin
val prep_statement: PreparedStatement = cqlSession.prepare(updateTemplate)
這是拋出一個錯誤。
Invalid map literal for ttl_col: bind variables are not supported inside collection literals
我的 Cassandra 表的 DDL 是這樣的。
CREATE KEYSPACE test_ks
WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 3};
CREATE TABLE test_ks.test_table_ttl (
consumer_id TEXT PRIMARY KEY,
ttl_col map<text, frozen<tuple<text, text>>>
);
uj5u.com熱心網友回復:
正如錯誤本身所提到的,集合文字中不支持系結變數。
因此我們必須改變它updateTemplate本身。
val updateTemplate = s"""UPDATE $keySpace.$tableName USING TTL 30
|SET one_time_pa = one_time_pa :mapData
|WHERE id=:id""".stripMargin
val tupleType: TupleType = DataTypes.tupleOf(DataTypes.TEXT, DataTypes.TEXT)
val rowKey = // some row key value
val mapKey = // some map key value
val mapValue = mapValueTupleType.newValue(tuple)
val mapData = ImmutableMap.builder().put(mapKey, mapValue).build()
prep_statement.bind(mapData, rowKey)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/424395.html
上一篇:加入或合并在sparkscala中有兩個唯一列的兩個csv檔案
下一篇:根據值減少迭代器
