使用语言集成 SQL 的带有 schemaRDD 的 SQL 函数

编程入门 行业动态 更新时间:2024-10-17 04:55:04
本文介绍了使用语言集成 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:关键词]

本文发布于:2023-04-18 20:22:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/947177.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   语言   SQL   schemaRDD

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!