Skip to content

Commit

Permalink
all code files updated
Browse files Browse the repository at this point in the history
  • Loading branch information
packt-pradeeps committed Jun 4, 2020
1 parent c364faa commit b61704d
Show file tree
Hide file tree
Showing 1,132 changed files with 197,378 additions and 66,870 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
File renamed without changes.
139 changes: 139 additions & 0 deletions Chapter04/CHAPTER_4_Divide_and_conquer.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import findspark\n",
"findspark.init()\n",
"from pyspark.sql import SparkSession\n",
"spark = SparkSession.builder.master(\"local[*]\").getOrCreate()\n",
"sc = spark.sparkContext"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <p><b>SparkContext</b></p>\n",
"\n",
" <p><a href=\"http://07c60a334272:4040\">Spark UI</a></p>\n",
"\n",
" <dl>\n",
" <dt>Version</dt>\n",
" <dd><code>v2.4.4</code></dd>\n",
" <dt>Master</dt>\n",
" <dd><code>local[*]</code></dd>\n",
" <dt>AppName</dt>\n",
" <dd><code>pyspark-shell</code></dd>\n",
" </dl>\n",
" </div>\n",
" "
],
"text/plain": [
"<SparkContext master=local[*] appName=pyspark-shell>"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sc"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['python', 'java', 'ottawa', 'ottawa', 'java', 'news']\n"
]
}
],
"source": [
"wordsList = ['python', 'java', 'ottawa', 'ottawa', 'java','news']\n",
"wordsRDD = sc.parallelize(wordsList, 4)\n",
"# Print out the type of wordsRDD\n",
"print (wordsRDD.collect())"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[('python', 1), ('java', 1), ('ottawa', 1), ('ottawa', 1), ('java', 1), ('news', 1)]\n"
]
}
],
"source": [
"wordPairs = wordsRDD.map(lambda w: (w, 1))\n",
"print (wordPairs.collect())"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[('python', 1), ('java', 2), ('ottawa', 2), ('news', 1)]\n"
]
}
],
"source": [
"wordCountsCollected = wordPairs.reduceByKey(lambda x,y: x+y)\n",
"print(wordCountsCollected.collect())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit b61704d

Please sign in to comment.