本文介绍了使用语言集成 SQL 的带有 schemaRDD 的 SQL 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我想使用基于 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,我遵循给定的示例 这里.
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)
Spark SQL 中没有 regexp
但它与 rlike
相同.
There is no regexp
in Spark SQL but it's same as rlike
.
这篇关于使用语言集成 SQL 的带有 schemaRDD 的 SQL 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论