Skip to Content
SPARK學習手冊
book

SPARK學習手冊

by Holden Karau, Andy Konwinski, Patrick We
September 2016
Intermediate to advanced
288 pages
6h 6m
Chinese
GoTop Information, Inc.
Content preview from SPARK學習手冊
RDD 操作 |
27
轉換(Transformations)操作
轉換操作是對 RDD 進行某種已定義的操作,並回傳一個新的 RDD 結果。如 29 頁討論
的「慵懶評估」,一個被轉換的 RDD 只有在某個 action 使用到它時,才確定執行相關轉
換操作。許多轉換操作是
元素感知的
element-wise
,也就是說,一次處理一個元素;
但是並非全部的轉換操作皆是如此。
舉例來說,假設有一個內含數筆訊息日誌檔案
log.txt
。若想要從中篩選出錯誤訊息
error message),我們可以使用先前看過的
filter()
轉換操作。範例 3-11 3-13 示範
了在三種不同的語言中使用
filter()
的方式
範例
3-11 Python
filter()
轉換操作
inputRDD = sc.textFile("log.txt")
errorsRDD = inputRDD.filter(lambda x: "error" in x)
範例
3-12 Scala
filter()
轉換操作
val inputRDD = sc.textFile("log.txt")
val errorsRDD = inputRDD.filter(line => line.contains("error"))
範例
3-13 Java
filter()
轉換操作
JavaRDD<String> inputRDD = sc.textFile("log.txt");
JavaRDD<String> errorsRDD = inputRDD.filter( ...
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

成為卓越程式設計師的38項必修法則

成為卓越程式設計師的38項必修法則

Pete Goodliffe
高性能Spark

高性能Spark

Holden Karau, Rachel Warren
持續交付|使用Java

持續交付|使用Java

Daniel Bryant, Abraham Marín-Pérez

Publisher Resources

ISBN: 9789864760466