`
sillycat
  • 浏览: 2579516 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Spark JDBC(1)MySQL Database RDD

 
阅读更多
Spark JDBC(1)MySQL Database RDD

Try to understand how the JDBCRDD work on Spark.
First of all, the master did not connect to the database.

First step,
The client driver class will connect to the MySQL and get the minId and maxId.
150612 17:21:55   58 Connect cluster@192.168.56.1 on lmm
select coalesce(min(d.id), 0) from device d where d.last_updated >= '2014-06-12 00:00:00.0000' and d.last_updated < '2014-06-13 00:00:00.0000'
select coalesce(max(d.id), 0) from device d

Second step, All the workers will try to fetch the data based on partitions
150612 17:22:13   59 Connect cluster@ubuntu-dev2 on lmm
select id, tenant_id, date_created, last_updated, device_id, os_type, os_version,
          search_radius, sdk_major_version, last_time_zone, sendable
         from
          device d
         where
          375001 <= d.id and
          d.id <= 750001

select id, tenant_id, date_created, last_updated, device_id, os_type, os_version,
          search_radius, sdk_major_version, last_time_zone, sendable
         from
          device d
         where
          750002 <= d.id and
          d.id <= 1125002


62 Connect cluster@ubuntu-dev1 on lmm
62 Query select id, tenant_id, date_created, last_updated, device_id, os_type, os_version,
          search_radius, sdk_major_version, last_time_zone, sendable
         from
          device d
         where
          0 <= d.id and
          d.id <= 375000
63 Query select id, tenant_id, date_created, last_updated, device_id, os_type, os_version,
          search_radius, sdk_major_version, last_time_zone, sendable
         from
          device d
         where
          1500004 <= d.id and
          d.id <= 1875004

The sample JDBCRDD is in code
https://github.com/luohuazju/sillycat-spark/tree/streaming

References:
http://spark.apache.org/docs/1.4.0/tuning.html
http://stackoverflow.com/questions/27619230/how-to-split-the-input-file-in-apache-spark




分享到:
评论

相关推荐

    spark jdbc 读取并发优化

    然而,在使用Spark与数据库交互时,尤其是使用JDBC(Java Database Connectivity)读取数据时,如果不优化并发度,很容易造成性能瓶颈。特别是在面对大规模数据集时,单线程任务过重会导致任务执行缓慢甚至挂起,...

    RDD编程初级实践Tom,DataBase,80 Tom,Algorithm,50 Tom,DataStructure,60 Jim,DataBas

    在Spark与数据库的交互中,我们可以使用`spark.read.jdbc()`方法来加载数据库中的数据到RDD,例如连接到MySQL或Hive等。这涉及到JDBC接口、DataFrame API以及SQL查询语言的应用,将数据库表转换为Spark DataFrame,...

    SparkSQL的jdbc操作及java的api操作

    首先,JDBC(Java Database Connectivity)是Java编程语言中用于与各种数据库进行交互的一种标准接口。SparkSQL通过JDBC可以连接到各种关系型数据库,如MySQL、Oracle、PostgreSQL等,读取或写入数据。这为大数据...

    基于scala语言的spark操作,包含连接操作mysql,连接hdfs.zip

    为了在 Spark 中读取和写入 MySQL 数据,我们需要使用 JDBC(Java Database Connectivity)。Spark 提供了 `spark.read.format("jdbc")` 方法来加载 MySQL 表,通过配置 URL、用户名、密码等参数。同样,可以使用 `...

    学科、姓名、分数。 分别计算每门学科分数最高的前三名,并显示名次。写入MySQL中。

    这通常通过使用JDBC(Java Database Connectivity)实现,但代码中并未展示这部分内容。在Spark中,可以使用`DataFrameWriter.jdbc()`方法将DataFrame写入数据库。你需要配置数据库的URL、用户名、密码以及表名,...

    Topics_in_Data_Analysis:数据分析中的主题-小型项目

    2. 数据导入与导出:Java提供了多种库,如JDBC(Java Database Connectivity)用于连接数据库,读写CSV、JSON、XML文件的库如Apache POI和Jackson。了解如何有效地导入和导出数据对于数据科学家来说至关重要。 3. ...

    Data-Engineering-Homework-lg

    Java通过JDBC(Java Database Connectivity)接口可以连接和操作各种类型的数据库,如MySQL、Oracle、PostgreSQL等。在项目中,可能会看到SQL语句用于数据的读写操作,或者使用ORM(对象关系映射)框架如Hibernate...

Global site tag (gtag.js) - Google Analytics