-
Notifications
You must be signed in to change notification settings - Fork 11
[DE-111] IMDB demo #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
75a0736
updated test coverage settings
rashtao 42fbb25
imdb demo
rashtao d7ebadd
imdb demo
rashtao 816346f
imdb demo
rashtao ddc8e5b
fixed import path
rashtao c851ec9
added console logs as code comments
rashtao dba7c68
added oasis configuration
rashtao cd00403
fixed Spark 2.4 compatibility
rashtao c2e337a
demo doc: overview and requirements
rashtao 96d1b7f
used schema names in WriteDemo
rashtao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,134 +1,71 @@ | ||
| # ArangoDB Spark Datasource Demo | ||
|
|
||
| Set ArangoDB Spark Datasource version environment variable: | ||
| This demo is composed of 3 parts: | ||
|
|
||
| ```shell | ||
| export ARANGO_SPARK_VERSION=1.0.0 | ||
| ``` | ||
|
|
||
| Set Scala version: | ||
|
|
||
| ```shell | ||
| # Scala 2.11 is only supported by Spark 2.4 | ||
| export SCALA_VERSION=2.11 | ||
|
|
||
| # Scala 2.12 is supported by both Spark 2.4 and 3.1 | ||
| export SCALA_VERSION=2.12 | ||
| ``` | ||
| - `WriteDemo`: reads the input json files as Spark Dataframes, applies conversions to map the data to Spark data types | ||
| and writes the records into ArangoDB collections | ||
| - `ReadDemo`: reads the ArangoDB collections created above as Spark Dataframes, specifying columns selection and records | ||
| filters predicates or custom AQL queries | ||
| - `ReadWriteDemo`: reads the ArangoDB collections created above as Spark Dataframes, applies projections and filtering, | ||
| writes to a new ArangoDB collection | ||
|
|
||
| Start ArangoDB cluster: | ||
|
|
||
| ```shell | ||
| STARTER_MODE=cluster ./docker/start_db.sh | ||
| ``` | ||
| ## Requirements | ||
|
|
||
| Import users sample data: | ||
| This demo requires: | ||
| - JDK 1.8 or 11 | ||
| - `maven` | ||
| - `docker` | ||
|
|
||
| ```shell | ||
| ./docker/import.sh | ||
| ``` | ||
|
|
||
| ## Spark 2.4 | ||
| ## Prepare the environment | ||
|
|
||
| Start Spark cluster: | ||
| Set environment variables: | ||
|
|
||
| ```shell | ||
| ./docker/start_spark_2.4.sh | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be good to list the requirements for this demo (e.g. Maven, Docker, etc.) with links to their pages? (So that a user who wants to run this demo can get started from scratch) |
||
| ``` | ||
|
|
||
| Test the Spark application in embedded mode: | ||
| ```shell | ||
| mvn -Pspark-2.4 -Pscala-$SCALA_VERSION test | ||
| ``` | ||
|
|
||
| Package the application: | ||
| ```shell | ||
| mvn -Pspark-2.4 -Pscala-$SCALA_VERSION -DskipTests=true package | ||
| ``` | ||
|
|
||
| Run Spark Shell: | ||
|
|
||
| ```shell | ||
| docker run -it --rm \ | ||
| -v $(pwd)/docker/.ivy2:/opt/bitnami/spark/.ivy2 \ | ||
| --network arangodb \ | ||
| docker.io/bitnami/spark:2.4.6 \ | ||
| ./bin/spark-shell --master spark://spark-master:7077 \ | ||
| --packages="com.arangodb:arangodb-spark-datasource-2.4_$SCALA_VERSION:$ARANGO_SPARK_VERSION" | ||
| ``` | ||
|
|
||
| Run sample code: | ||
|
|
||
| ```scala | ||
| val options = Map("user" -> "root", "password" -> "test", "endpoints" -> "172.17.0.1:8529,172.17.0.1:8539,172.17.0.1:8549") | ||
| val usersDF = spark.read.format("com.arangodb.spark").options(options + ("table" -> "users")).load() | ||
| usersDF.show() | ||
| usersDF.printSchema() | ||
| usersDF.filter(col("name.first") === "Prudence").filter(col("birthday") === "1944-06-19").show() | ||
|
|
||
| // Spark SQL | ||
| usersDF.createOrReplaceTempView("users") | ||
| val californians = spark.sql("SELECT * FROM users WHERE contact.address.state = 'CA'") | ||
| californians.show() | ||
| californians.write.format("com.arangodb.spark").mode(org.apache.spark.sql.SaveMode.Overwrite).options(options + ("table" -> "californians", "confirm.truncate" -> "true")).save() | ||
| export ARANGO_SPARK_VERSION=1.0.0 | ||
| ``` | ||
|
|
||
| Submit demo program: | ||
| Start ArangoDB cluster with docker: | ||
|
|
||
| ```shell | ||
| docker run -it --rm \ | ||
| -v $(pwd):/demo \ | ||
| -v $(pwd)/docker/.ivy2:/opt/bitnami/spark/.ivy2 \ | ||
| --network arangodb \ | ||
| docker.io/bitnami/spark:2.4.6 \ | ||
| ./bin/spark-submit --master spark://spark-master:7077 \ | ||
| --packages="com.arangodb:arangodb-spark-datasource-2.4_$SCALA_VERSION:$ARANGO_SPARK_VERSION" \ | ||
| --class Demo /demo/target/demo-$ARANGO_SPARK_VERSION.jar | ||
| STARTER_MODE=cluster ./docker/start_db.sh | ||
| ``` | ||
|
|
||
| ## Spark 3.1 | ||
| The deployed cluster will be accessible at [http://172.17.0.1:8529](http://172.17.0.1:8529) with username `root` and | ||
| password `test`. | ||
|
|
||
| Start Spark cluster: | ||
|
|
||
| ```shell | ||
| ./docker/start_spark_3.1.sh | ||
| ``` | ||
|
|
||
| Test the Spark application in embedded mode: | ||
| ```shell | ||
| mvn -Pspark-3.1 -Pscala-$SCALA_VERSION test | ||
| ``` | ||
|
|
||
| Package the application: | ||
| ## Run embedded | ||
|
|
||
| Test the Spark application in embedded mode: | ||
| ```shell | ||
| mvn -Pspark-3.1 -Pscala-$SCALA_VERSION -DskipTests=true package | ||
| mvn -Pspark-3.1 -Pscala-2.12 -DimportPath=docker/import test | ||
| ``` | ||
|
|
||
| Run Spark Shell: | ||
|
|
||
| Test the Spark application against ArangoDB Oasis deployment: | ||
| ```shell | ||
| docker run -it --rm \ | ||
| -v $(pwd)/docker/.ivy2:/opt/bitnami/spark/.ivy2 \ | ||
| --network arangodb \ | ||
| docker.io/bitnami/spark:3.1.2 \ | ||
| ./bin/spark-shell --master spark://spark-master:7077 \ | ||
| --packages="com.arangodb:arangodb-spark-datasource-3.1_$SCALA_VERSION:$ARANGO_SPARK_VERSION" | ||
| mvn -Pspark-3.1 -Pscala-2.12 \ | ||
| -DimportPath=docker/import \ | ||
| -Dpassword=<root-password> \ | ||
| -Dendpoints=<endpoint> \ | ||
| -Dssl.enabled=true \ | ||
| -Dssl.cert.value=<base64-encoded-cert> \ | ||
| test | ||
| ``` | ||
|
|
||
| Run sample code: | ||
|
|
||
| ```scala | ||
| val options = Map("user" -> "root", "password" -> "test", "endpoints" -> "172.17.0.1:8529,172.17.0.1:8539,172.17.0.1:8549") | ||
| val usersDF = spark.read.format("com.arangodb.spark").options(options + ("table" -> "users")).load() | ||
| usersDF.show() | ||
| usersDF.printSchema() | ||
| usersDF.filter(col("name.first") === "Prudence").filter(col("birthday") === "1944-06-19").show() | ||
| ## Submit to Spark cluster | ||
|
|
||
| // Spark SQL | ||
| usersDF.createOrReplaceTempView("users") | ||
| val californians = spark.sql("SELECT * FROM users WHERE contact.address.state = 'CA'") | ||
| californians.show() | ||
| californians.write.format("com.arangodb.spark").mode(org.apache.spark.sql.SaveMode.Overwrite).options(options + ("table" -> "californians", "confirmTruncate" -> "true")).save() | ||
| Package the application: | ||
| ```shell | ||
| mvn -Pspark-3.1 -Pscala-2.12 -DskipTests=true package | ||
| ``` | ||
|
|
||
| Submit demo program: | ||
|
|
@@ -140,6 +77,6 @@ docker run -it --rm \ | |
| --network arangodb \ | ||
| docker.io/bitnami/spark:3.1.2 \ | ||
| ./bin/spark-submit --master spark://spark-master:7077 \ | ||
| --packages="com.arangodb:arangodb-spark-datasource-3.1_$SCALA_VERSION:$ARANGO_SPARK_VERSION" \ | ||
| --packages="com.arangodb:arangodb-spark-datasource-3.1_2.12:$ARANGO_SPARK_VERSION" \ | ||
| --class Demo /demo/target/demo-$ARANGO_SPARK_VERSION.jar | ||
| ``` | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it might be helpful to list or give an overview of what each of the demos is doing (Read, Write, ReadWrite)?