使用语言集成SQL与schemaRDD SQL函数 [英] SQL-Functions with schemaRDD using language integrated SQL
本文介绍了使用语言集成SQL与schemaRDD SQL函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用基于SQL语言的功能集成SQL来筛选schemaRDD。例如,我想运行
I want to filter a schemaRDD using language integrated SQL based on SQL functions. For example I want to run
SELECT name FROM people WHERE name LIKE '%AHSAN%' AND name regexp '^[A-Z]{20}$'
如何在people.where使用这些SQL函数()?
参考:
有关语言集成的SQL,我下面给出的示例<一个href=\"http://spark.apache.org/docs/latest/sql-programming-guide.html#writing-language-integrated-relational-queries\"相对=nofollow>这里。
For language integrated SQL, I am following the example given 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)
在此先感谢!
推荐答案
您可以用这样的数字运算符的SQL函数。如,
You can use SQL functions like numeric operators. E.g.,
people.where('name like "%AHSAN%").where('name rlike "^[A-Z]{20}$").select('name)
有在星火SQL没有正则表达式
,但它一样 RLIKE
。
There is no regexp
in Spark SQL but it's same as rlike
.
这篇关于使用语言集成SQL与schemaRDD SQL函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文