Skip to Content
大规模数据分析和建模:基于 Spark 与 R
book

大规模数据分析和建模:基于 Spark 与 R

by Javier Luraschi, Kevin Kuo, Edgar Ruiz
July 2020
Intermediate to advanced
262 pages
5h 34m
Chinese
China Machine Press
Content preview from 大规模数据分析和建模:基于 Spark 与 R
社区贡献
223
R 程序包
Spark 扩展
Scala 代码
13-1
:使用
Spark API
Spark
扩展,或编写
Scala
代码来扩展
Spark
我们会首先关注使用 Spark API 扩展 Spark,因为调用 Spark API 所需的技术也适用于调
Spark 扩展或自定义 Scala 代码。
13.2 Spark API
在介绍 Spark API 之前,让我们考虑一个简单而著名的问题。假设我们要计算一个分布式
的、可能很大的文本文件中的行数,例如
cars.csv
中的行数,我们将其初始化如下:
library(sparklyr)
library(dplyr)
sc <- spark_connect(master = "local")
cars <- copy_to(sc, mtcars)
spark_write_csv(cars, "cars.csv")
现在,要计算文件中有多少行,我们可以运行如下代码:
spark_read_text(sc, "cars.csv") %>% count()
# Source: spark<?> [?? x 1]
n
<dbl>
1 33
很简单:我们使用spark_read_text() 读取整个文本文件,然后使用 dplyr
count() 计数行。现在,假设 spark_read_text()dplyr 或任何其他 Spark 功能
都不可用。你会要求 Spark 如何计算
cars.csv
中的行数?
如果在 Scala 中执行此操作,可以在 Spark ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

Aurélien Géron
数字化转型:企业破局的34 个锦囊

数字化转型:企业破局的34 个锦囊

Gary O’Brien, Xiao Guo, Mike Mason

Publisher Resources

ISBN: 9787111661016