The examples in this repository are support to the Spark in Action, 2nd edition book by Jean Georges Perrin and published by Manning. Find out more about the book on Manning's website.
Welcome to Spark with Java, chapter 8. This chapter covers data ingestion from databases.
This code is designed to work with Apache Spark v3.0.0.
The MySQLToDatasetApp
application does the following:
- It acquires a session (a
SparkSession
). - It connects to MySQL Database.
- Spark reads data from MySQL Database into dataframe, then perform some operations on dataframe.
Same as lab #100, but uses environment variables.
Example of building a dialect, here connect IBM Informix and Apache Spark.
Advanced queries.
Ingestion from SQL joins.
Similar to lab #310.
Repartitionning after ingestion.
Ingestion from Elasticsearch.
Note that, as of now, Elasticsearch does not support Apache Spark v3.x, as the connector is limited to Scala v2.11. To run this example, use pom-elastic-scale2.11.xml
instead of the default pom.xml
.
For information on running the Java lab, see chapter 1 in Spark in Action, 2nd edition.
Prerequisites:
You will need:
git
.- Apache Spark (please refer Appendix P - 'Spark in production: installation and a few tips').
- Clone this project
git clone https://github.com/jgperrin/net.jgp.books.spark.ch08
- Go to the lab in the Python directory
cd net.jgp.books.spark.ch08/src/main/python/lab100_mysql_ingestion/
- Execute the following spark-submit command to run any MySQL database related application
spark-submit --driver-class-path /temp/jars/mysql_mysql-connector-java-8.0.12.jar --packages mysql:mysql-connector-java:8.0.12 mySQLToDatasetApp.py
NOTE:- Here we assume that user have MySQL jar file at '/tmp/jars' folder (Please use any folder you like based on your OS.). You can also use maven or ivy repository path.
- Execute the following spark-submit command to run any ElasticSearch related application
cd net.jgp.books.spark.ch08/src/main/python/lab400_elasticsearch_Ingestion/
spark-submit --driver-class-path /tmp/jars/org.elasticsearch_elasticsearch-hadoop-6.2.3.jar --packages org.elasticsearch:elasticsearch-hadoop:6.2.3 elasticsearchToDatasetApp.py
NOTE:- Here we assume that user have ElasticSearch jar file at '/tmp/jars' folder (Please use any folder you like based on your OS.). You can also use maven or ivy repository path.
Prerequisites:
You will need:
git
.- Apache Spark (please refer Appendix P - 'Spark in production: installation and a few tips').
- Clone this project
git clone https://github.com/jgperrin/net.jgp.books.spark.ch08
-
cd net.jgp.books.spark.ch08
-
Package application using sbt command
sbt clean assembly
- Run Spark/Scala application using spark-submit command as shown below:
spark-submit --class net.jgp.books.spark.ch08.lab100_mysql_ingestion.MySQLToDatasetScalaApp target/scala-2.12/SparkInAction2-Chapter08-assembly-1.0.0.jar
- [Java] Due to renaming the packages to match more closely Java standards, this project is not in sync with the book's MEAP prior to v10 (published in April 2019).
- [Scala, Python] As of MEAP v14, we have introduced Scala and Python examples (published in October 2019).
Follow me on Twitter to get updates about the book and Apache Spark: @jgperrin. Join the book's community on Facebook or in Manning's live site.