Created
June 27, 2017 13:44
-
-
Save alexarchambault/0f8c21d71d0eb03677b44528260cdb9f to your computer and use it in GitHub Desktop.
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
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "\u001b[32mimport \u001b[39m\u001b[36m$exclude.$ , $ivy.$ \n", | |
| "\u001b[39m\n", | |
| "\u001b[32mimport \u001b[39m\u001b[36m$profile.$ \n", | |
| "\u001b[39m\n", | |
| "\u001b[32mimport \u001b[39m\u001b[36m$ivy.$ \n", | |
| "\u001b[39m\n", | |
| "\u001b[32mimport \u001b[39m\u001b[36m$ivy.$ \n", | |
| "\u001b[39m\n", | |
| "\u001b[32mimport \u001b[39m\u001b[36m$ivy.$ \n", | |
| "\n", | |
| "\u001b[39m\n", | |
| "\u001b[32mimport \u001b[39m\u001b[36morg.apache.spark._\n", | |
| "\u001b[39m\n", | |
| "\u001b[32mimport \u001b[39m\u001b[36morg.apache.spark.sql._\n", | |
| "\u001b[39m\n", | |
| "\u001b[32mimport \u001b[39m\u001b[36mjupyter.spark.session._\u001b[39m" | |
| ] | |
| }, | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "import $exclude.`org.slf4j:slf4j-log4j12`, $ivy.`org.slf4j:slf4j-nop:1.7.21`\n", | |
| "import $profile.`hadoop-2.6`\n", | |
| "import $ivy.`org.apache.spark::spark-sql:2.1.0`\n", | |
| "import $ivy.`org.apache.hadoop:hadoop-aws:2.6.4`\n", | |
| "import $ivy.`org.jupyter-scala::spark:0.4.2`\n", | |
| "\n", | |
| "import org.apache.spark._\n", | |
| "import org.apache.spark.sql._\n", | |
| "import jupyter.spark.session._" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).\n", | |
| "log4j:WARN Please initialize the log4j system properly.\n", | |
| "log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.\n" | |
| ] | |
| }, | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "\u001b[36msparkSession\u001b[39m: \u001b[32mSparkSession\u001b[39m = org.apache.spark.sql.SparkSession@44523f03" | |
| ] | |
| }, | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "val sparkSession = JupyterSparkSession.builder()\n", | |
| " .jupyter()\n", | |
| " .master(\"local\")\n", | |
| " .appName(\"notebook\")\n", | |
| " .getOrCreate()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "defined \u001b[32mclass\u001b[39m \u001b[36mP\u001b[39m" | |
| ] | |
| }, | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "case class P(name: String)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "\u001b[36mps\u001b[39m: \u001b[32mArray\u001b[39m[\u001b[32mP\u001b[39m] = \u001b[33mArray\u001b[39m(\u001b[33mP\u001b[39m(\u001b[32m\"alice\"\u001b[39m), \u001b[33mP\u001b[39m(\u001b[32m\"bob\"\u001b[39m), \u001b[33mP\u001b[39m(\u001b[32m\"charly\"\u001b[39m), \u001b[33mP\u001b[39m(\u001b[32m\"bob\"\u001b[39m))\n", | |
| "\u001b[36mres3_1\u001b[39m: \u001b[32mArray\u001b[39m[(\u001b[32mP\u001b[39m, \u001b[32mInt\u001b[39m)] = \u001b[33mArray\u001b[39m((\u001b[33mP\u001b[39m(\u001b[32m\"alice\"\u001b[39m), \u001b[32m1\u001b[39m), (\u001b[33mP\u001b[39m(\u001b[32m\"charly\"\u001b[39m), \u001b[32m1\u001b[39m), (\u001b[33mP\u001b[39m(\u001b[32m\"bob\"\u001b[39m), \u001b[32m2\u001b[39m))" | |
| ] | |
| }, | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "val ps = Array(P(\"alice\"), P(\"bob\"), P(\"charly\"), P(\"bob\"))\n", | |
| "\n", | |
| "sparkSession\n", | |
| " .sparkContext\n", | |
| " .parallelize(ps)\n", | |
| " .map(x => (x,1))\n", | |
| " .reduceByKey((x,y) => x + y)\n", | |
| " .collect()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Scala (staged)", | |
| "language": "scala", | |
| "name": "scala-staged" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": "text/x-scala", | |
| "file_extension": ".scala", | |
| "mimetype": "text/x-scala", | |
| "name": "scala211", | |
| "nbconvert_exporter": "script", | |
| "pygments_lexer": "scala", | |
| "version": "2.11.11" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment