Filtering multiple values in multiple columns:

In the case where you're pulling data from a database (Hive or SQL type db for this example) and need to filter on multiple columns, it might just be easier to load the table with the first filter, then iterate your filters through the RDD (multiple small iterations is the encouraged way of Spark programming):

{
import org.apache.spark.sql.hive.HiveContext
val hc = new HiveContext(sc) val first_data_filter = hc.sql("SELECT col1,col2,col2 FROM tableName WHERE col3 IN ('value_1', 'value_2', 'value_3)")
val second_data_filter = first_data_filter.filter(rdd => rdd(1) == "50" || rdd(1) == "20")
val final_filtered_data = second_data_filter.filter(rdd => rdd(0) == "1500") }

https://segmentfault.com/a/1190000002614456

spark记录的更多相关文章

  1. Spark记录-Spark性能优化解决方案

    Spark性能优化的10大问题及其解决方案 问题1:reduce task数目不合适解决方式:需根据实际情况调节默认配置,调整方式是修改参数spark.default.parallelism.通常,r ...

  2. Spark记录-SparkSQL相关学习

    $spark-sql  --help  查看帮助命令 $设置任务个数,在这里修改为20个 spark-sql>SET spark.sql.shuffle.partitions=20; $选择数据 ...

  3. Spark记录-实例和运行在Yarn

    #运行实例 #./bin/run-example SparkPi 10   #./bin/spark-shell --master local[2] #./bin/pyspark --master l ...

  4. Spark记录-官网学习配置篇(二)

    ### Spark SQL Running the SET -v command will show the entire list of the SQL configuration. #scala/ ...

  5. Spark记录-官网学习配置篇(一)

    参考http://spark.apache.org/docs/latest/configuration.html Spark提供三个位置来配置系统: Spark属性控制大多数应用程序参数,可以使用Sp ...

  6. Spark记录-spark编程介绍

    Spark核心编程 Spark 核心是整个项目的基础.它提供了分布式任务调度,调度和基本的 I/O 功能.Spark 使用一种称为RDD(弹性分布式数据集)一个专门的基础数据结构,是整个机器分区数据的 ...

  7. Spark记录-spark介绍

    Apache Spark是一个集群计算设计的快速计算.它是建立在Hadoop MapReduce之上,它扩展了 MapReduce 模式,有效地使用更多类型的计算,其中包括交互式查询和流处理.这是一个 ...

  8. Spark记录-大数据简介

    什么是大数据 大数据(big data),指无法在一定时间范围内用常规软件工具进行捕捉.管理和处理的数据集合,是需要新处理模式才能具有更强的决策力.洞察发现力和流程优化能力的海量.高增长率和多样化的信 ...

  9. Spark记录-spark-env.sh配置

    环境变量 含义 SPARK_MASTER_IP master实例绑定的IP地址,例如,绑定到一个公网IP SPARK_MASTER_PORT mater实例绑定的端口(默认7077) SPARK_MA ...

随机推荐

  1. 建立一个Hello World级别的Spring项目

    package com.sevenhu.domain; import org.springframework.context.ApplicationContext; import org.spring ...

  2. 从一个小项目看return 引用 重载运算符

    #ifndef _ARRAY_H_ #define _ARRAY_H_ class Array { private: int mLength; int* mSpace; public: Array(i ...

  3. URAL 1001 Reverse Root(水题?)

    The problem is so easy, that the authors were lazy to write a statement for it! Input The input stre ...

  4. 使用sysprep克隆虚拟机

    1.虚拟机安装windows2008 x64 r2 2.安装完毕后,运行”c:\windows\system32\sysprep\sysprep.exe” 3.选择”进入系统全新体验(OOBE),勾选 ...

  5. 使用Node.js的socket.io模块开发实时web程序

    首发:个人博客,更新&纠错&回复 今天的思维漫游如下:从.net的windows程序开发,摸到nodejs的桌面程序开发,又熟悉了一下nodejs,对“异步”的理解有了上上周对操作系统 ...

  6. :not(selector)

    描述: 用于筛选的选择器 查找所有未选中的 input 元素 HTML 代码: <input name="apple" /> <input name=" ...

  7. windbg定位WEB性能瓶颈案例一则

    测试环境 服务器:II服务器 网站:门户网站 条件 并发: 2000 LoadRunner思考时间:1s 表现 CPU:100% 对应w3wp进程 WebService–>Current con ...

  8. scala构建类似java的pojo

    主要看以下代码: package com.test.scalaw.test.demo import scala.beans.BeanProperty /** * scala构建类似java 的pojo ...

  9. Android 常用工具类之DeviceInfoUtil

    public class DeviceInfoUtil { private static WifiManager wifiManager = null; // wifi是否已连接 public sta ...

  10. C# 探索c#之Async、Await剖析

    探索c#之Async.Await剖析 作者:蘑菇先生 出处:http://mushroom.cnblogs.com/