4
我有以下数据结构:Seq.contains在SQL中的星火据帧
id: int
records: Seq[String]
other: boolean
在一个JSON文件,为了便于测试:
var data = sc.makeRDD(Seq[String](
"{\"id\":1, \"records\": [\"one\", \"two\", \"three\"], \"other\": true}",
"{\"id\": 2, \"records\": [\"two\"], \"other\": true}",
"{\"id\": 3, \"records\": [\"one\"], \"other\": false }"))
sqlContext.jsonRDD(data).registerTempTable("temp")
而且我想与在records
领域one
和other
只使用SQL等于true
下过滤出记录。
我可以通过做一个filter
(见下文),但它可以被使用SQL只是做了什么?
sqlContext
.sql("select id, records from temp where other = true")
.rdd.filter(t => t.getAs[Seq[String]]("records").contains("one"))
.collect()
太棒了。谢谢。 –