我想使用基于SQL函数的语言集成SQL过滤schemaRDD。例如,我想运行
SELECT name FROM people WHERE name LIKE '%AHSAN%' AND name regexp '^[A-Z]{20}$'
如何在people.where()中使用此类SQL函数?
参考:
对于语言集成SQL,我遵循给定here的示例。
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
import sqlContext._
val people: RDD[Person] = ... // An RDD of case class objects, from the first example.
// The following is the same as 'SELECT name FROM people WHERE age >= 10 AND age <= 19'
val teenagers = people.where('age >= 10).where('age <= 19).select('name)
teenagers.map(t => "Name: " + t(0)).collect().foreach(println)
提前致谢!
答案 0 :(得分:0)
您可以使用SQL函数,如数字运算符。如,
people.where('name like "%AHSAN%").where('name rlike "^[A-Z]{20}$").select('name)
Spark SQL中没有regexp
,但它与rlike
相同。