Spark JDBC(1)MySQL Database RDD

本文详细介绍了如何使用Spark JDBC RDD从MySQL数据库中读取数据。首先客户端驱动连接到MySQL获取最小和最大ID,然后所有工作节点根据分区尝试获取数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值