【发布时间】:2020-12-14 16:20:20
【问题描述】:
我必须在 spark 中过滤 Cassandra 表,通过 spark 从表中获取数据后,在返回的 rdd 上应用过滤函数,我们不想在 cassandra api 中使用 where 子句可以过滤但需要自定义 sasi 索引filter 列,由于 cassandra 中的多次 ss 表扫描而存在磁盘开销问题。 例如:
val ct = sc.cassandraTable("keyspace1", "table1")
val fltr = ct.filter(x=x.contains "zz")
table1 字段是:
- dirid uuid
- 文件名文本
- 事件解释
- eventtimestamp bigint
- fileid int
- 文件类型 int
基本上我们需要使用任意字符串根据文件名过滤数据。因为返回的 rdd 是类型
com.datastax.spark.connector.rdd.CassandraTableScanRDD[com.datastax.spark.connector.CassandraRow] = CassandraTableScanRDD
而过滤操作仅限于CassandraRow类型的方法,即enter image description here
val ct = sc.cassandraTable("keyspace1", "table1")
scala> ct
res140: com.datastax.spark.connector.rdd.CassandraTableScanRDD[com.datastax.spark.connector.CassandraRow] = CassandraTableScanRDD[171] at RDD at CassandraRDD.scala:19
当我在“x”之后点击制表符时。在下面的过滤器函数中,它显示了CassandraRow类的以下方法`在此处输入代码
scala> ct.filter(x=>x.
columnValues getBooleanOption getDateTime getFloatOption getLongOption getString getUUIDOption length
contains getByte getDateTimeOption getInet getMap getStringOption getVarInt metaData
copy getByteOption getDecimal getInetOption getRaw getTupleValue getVarIntOption nameOf
dataAsString getBytes getDecimalOption getInt getRawCql getTupleValueOption hashCode size
equals getBytesOption getDouble getIntOption getSet getUDTValue indexOf toMap
get getDate getDoubleOption getList getShort getUDTValueOption isNullAt toString
getBoolean getDateOption getFloat getLong getShortOption getUUID iterator
【问题讨论】:
标签: scala apache-spark cassandra rdd spark-cassandra-connector