使用语言集成SQL与schemaRDD SQL函数(SQL-Functions with schem

2019-10-21 09:03发布

我想使用基于SQL语言的功能集成SQL来筛选schemaRDD。 例如,我想运行

SELECT name FROM people WHERE name LIKE '%AHSAN%' AND name regexp '^[A-Z]{20}$'

我怎样才能在people.where使用这些SQL函数()?

参考:

对于语言集成SQL,我下面给出的例子在这里 。

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)

提前致谢!

Answer 1:

您可以使用SQL功能,如数字运算符。 例如,

people.where('name like "%AHSAN%").where('name rlike "^[A-Z]{20}$").select('name)

没有regexp中的星火SQL,但它一样rlike



文章来源: SQL-Functions with schemaRDD using language integrated SQL