关于spark中DatatFrame函数操作中isin方法的使用

需求:

  1、需要从一张mysql数据表中获取并筛选数据

  

  2、通过spark将该表读进来,形成一个df:DataFrame,有一个集合

    val list = List[String]("小李", "小王", "4", "5", "7")

  3、需要从df中进行筛选出来name在list中的值    

    df.where('name.isin(list)).show()  

  结果:   

  

  然而,isin(),看源码:

  

  里面需要的是一个可边长参数,我们想当然的把它当成了一个集合,此时不能将整个list传进去,但是我又要实现包含查询,但是又不想通过for循环遍历进行union的方式(这种方式是可以实现的,也就是说根据条件匹配list中的第一个值,然后将其定义成var,然后在遍历list中的每一个值作为条件,最后将其union起来,很笨,我一开始就这么干的),此时有一个新的办法,就是讲list改为list:_*

  df.where('name.isin(list:_*)).show()

  结果:

    

 搞定!!!

记录一下。

 
 

   

 

  
 

转载于:https://www.cnblogs.com/Gxiaobai/p/10683001.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spark: Big Data Cluster Computing in Production English | 2016 | ISBN: 1119254019 | 216 pages | PDF | 5 MB Production-targeted Spark guidance with real-world use cases Spark: Big Data Cluster Computing in Production goes beyond general Spark overviews to provide targeted guidance toward using lightning-fast big-data clustering in production. Written by an expert team well-known in the big data community, this book walks you through the challenges in moving from proof-of-concept or demo Spark applications to live Spark in production. Real use cases provide deep insight into common problems, limitations, challenges, and opportunities, while expert tips and tricks help you get the most out of Spark performance. Coverage includes Spark SQL, Tachyon, Kerberos, ML Lib, YARN, and Mesos, with clear, actionable guidance on resource scheduling, db connectors, streaming, security, and much more. Spark has become the tool of choice for many Big Data problems, with more active contributors than any other Apache Software project. General introductory books abound, but this book is the first to provide deep insight and real-world advice on using Spark in production. Specific guidance, expert tips, and invaluable foresight make this guide an incredibly useful resource for real production settings. Review Spark hardware requirements and estimate cluster size Gain insight from real-world production use cases Tighten security, schedule resources, and fine-tune performance Overcome common problems encountered using Spark in production Spark works with other big data tools including MapReduce and Hadoop, and uses languages you already know like Java, Scala, Python, and R. Lightning speed makes Spark too good to pass up, but understanding limitations and challenges in advance goes a long way toward easing actual production implementation. Spark: Big Data Cluster Computing in Production tells you everything you need to know, with real-world production insight and expert guidance, tip

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值