Skip to Main Content
PySpark Cookbook
book

PySpark Cookbook

by Denny Lee, Tomasz Drabas
June 2018
Intermediate to advanced content levelIntermediate to advanced
330 pages
9h 47m
English
Packt Publishing
Content preview from PySpark Cookbook

How to do it...

We will be leveraging our Python Databricks notebook, but we will include the following Scala cell. At the top level here's the flow of the code:

%scalapackage d3aimport org.apache.spark.sql._import com.databricks.backend.daemon.driver.EnhancedRDDFunctions.displayHTMLcase class Edge(src: String, dest: String, count: Long)case class Node(name: String)case class Link(source: Int, target: Int, value: Long)case class Graph(nodes: Seq[Node], links: Seq[Link])object graphs {val sqlContext = SQLContext.getOrCreate(org.apache.spark.SparkContext.getOrCreate())import sqlContext.implicits._def force(clicks: Dataset[Edge], height: Int = 100, width: Int = 960): Unit = {  val data = clicks.collect() val nodes = (data.map(_.src) ++ data.map(_.dest)).map(_.replaceAll("_", ...
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.
Start your free trial

You might also like

Spark: The Definitive Guide

Spark: The Definitive Guide

Bill Chambers, Matei Zaharia
Learning PySpark

Learning PySpark

Tomasz Drabas, Denny Lee
Python Cookbook, 3rd Edition

Python Cookbook, 3rd Edition

David Beazley, Brian K. Jones
Kafka: The Definitive Guide

Kafka: The Definitive Guide

Neha Narkhede, Gwen Shapira, Todd Palino

Publisher Resources

ISBN: 9781788835367Supplemental Content