aboutsummaryrefslogtreecommitdiffstats
path: root/scratch/HelloWorld.ipynb
blob: e382aa4a18a2866119a03482aeaa7639f1c4a200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "6974daac",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyspark.sql import SparkSession\n",
    "from pyspark.context import SparkContext"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "e72fbe47",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pyspark.sql.session.SparkSession"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "SparkSession"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9333e07a",
   "metadata": {},
   "outputs": [],
   "source": [
    "spark = SparkSession.builder.master(\"local\").appName(\"HelloWorld\").getOrCreate()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "adf79021",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "            <div>\n",
       "                <p><b>SparkSession - hive</b></p>\n",
       "                \n",
       "        <div>\n",
       "            <p><b>SparkContext</b></p>\n",
       "\n",
       "            <p><a href=\"http://192.168.179.73:4040\">Spark UI</a></p>\n",
       "\n",
       "            <dl>\n",
       "              <dt>Version</dt>\n",
       "                <dd><code>v3.1.1</code></dd>\n",
       "              <dt>Master</dt>\n",
       "                <dd><code>local[*]</code></dd>\n",
       "              <dt>AppName</dt>\n",
       "                <dd><code>PySparkShell</code></dd>\n",
       "            </dl>\n",
       "        </div>\n",
       "        \n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "<pyspark.sql.session.SparkSession at 0x7f63b4051650>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "spark"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "324b74ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'3.1.1'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "spark.version"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "856f2700",
   "metadata": {},
   "outputs": [],
   "source": [
    "sc = SparkContext.getOrCreate()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "7218a07f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "        <div>\n",
       "            <p><b>SparkContext</b></p>\n",
       "\n",
       "            <p><a href=\"http://192.168.179.73:4040\">Spark UI</a></p>\n",
       "\n",
       "            <dl>\n",
       "              <dt>Version</dt>\n",
       "                <dd><code>v3.1.1</code></dd>\n",
       "              <dt>Master</dt>\n",
       "                <dd><code>local[*]</code></dd>\n",
       "              <dt>AppName</dt>\n",
       "                <dd><code>PySparkShell</code></dd>\n",
       "            </dl>\n",
       "        </div>\n",
       "        "
      ],
      "text/plain": [
       "<SparkContext master=local[*] appName=PySparkShell>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "17114da3",
   "metadata": {},
   "outputs": [],
   "source": [
    "txt = sc.textFile('file:////usr/share/doc/python3/copyright')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "c1af9b77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "file:////usr/share/doc/python3/copyright MapPartitionsRDD[4] at textFile at NativeMethodAccessorImpl.java:0"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "ee37564c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pyspark.rdd.RDD"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(txt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "208ef97a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "319"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "txt.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "06f807b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "python_lines = txt.filter(lambda line: 'python' in line.lower())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "ff2835b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "52\n"
     ]
    }
   ],
   "source": [
    "print(python_lines.count())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "9c8ec8c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['This is the Debian GNU/Linux prepackaged version of the Python programming',\n",
       " 'language. Python was written by Guido van Rossum <guido@cwi.nl> and others.',\n",
       " 'sources from ftp.python.org:/pub/python, based on the Debianization by',\n",
       " 'Python was created in the early 1990s by Guido van Rossum at Stichting',\n",
       " \"as a successor of a language called ABC.  Guido remains Python's\",\n",
       " 'In 1995, Guido continued his work on Python at the Corporation for',\n",
       " 'In May 2000, Guido and the Python core development team moved to',\n",
       " 'BeOpen.com to form the BeOpen PythonLabs team.  In October of the same',\n",
       " 'year, the PythonLabs team moved to Digital Creations (now Zope',\n",
       " 'Corporation, see http://www.zope.com).  In 2001, the Python Software',\n",
       " 'Foundation (PSF, see http://www.python.org/psf/) was formed, a',\n",
       " 'non-profit organization created specifically to own Python-related',\n",
       " 'All Python releases are Open Source (see http://www.opensource.org for',\n",
       " 'the Open Source Definition).  Historically, most, but not all, Python',\n",
       " \"(1) GPL-compatible doesn't mean that we're distributing Python under\",\n",
       " '    the GPL.  All Python licenses, unlike the GPL, let you distribute',\n",
       " '    GPL-compatible licenses make it possible to combine Python with',\n",
       " 'B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON',\n",
       " 'PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2',\n",
       " '1. This LICENSE AGREEMENT is between the Python Software Foundation',\n",
       " 'otherwise using this software (\"Python\") in source or binary form and',\n",
       " 'distribute, and otherwise use Python alone or in any derivative version,',\n",
       " 'Python Software Foundation; All Rights Reserved\" are retained in Python alone or',\n",
       " 'or incorporates Python or any part thereof, and wants to make',\n",
       " 'the changes made to Python.',\n",
       " '4. PSF is making Python available to Licensee on an \"AS IS\"',\n",
       " 'FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT',\n",
       " '5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON',\n",
       " 'A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,',\n",
       " '8. By copying, installing or otherwise using Python, Licensee',\n",
       " 'BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0',\n",
       " 'BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1',\n",
       " '2. Subject to the terms and conditions of this BeOpen Python License',\n",
       " 'provided, however, that the BeOpen Python License is retained in the',\n",
       " 'third party.  As an exception, the \"BeOpen Python\" logos available at',\n",
       " 'http://www.pythonlabs.com/logos.html may be used according to the',\n",
       " 'CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1',\n",
       " '(\"Licensee\") accessing and otherwise using Python 1.6.1 software in',\n",
       " 'prepare derivative works, distribute, and otherwise use Python 1.6.1',\n",
       " 'Reserved\" are retained in Python 1.6.1 alone or in any derivative',\n",
       " 'quotes): \"Python 1.6.1 is made available subject to the terms and',\n",
       " 'Python 1.6.1 may be located on the Internet using the following',\n",
       " 'or incorporates Python 1.6.1 or any part thereof, and wants to make',\n",
       " 'the changes made to Python 1.6.1.',\n",
       " '4. CNRI is making Python 1.6.1 available to Licensee on an \"AS IS\"',\n",
       " 'FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT',\n",
       " '5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON',\n",
       " 'A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,',\n",
       " 'on Python 1.6.1 that incorporate non-separable material that was',\n",
       " 'installing or otherwise using Python 1.6.1, Licensee agrees to be',\n",
       " 'CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2',\n",
       " 'py3compile, py3clean and debpython module:']"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "python_lines.collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9c60ff17",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "cgraph",
   "language": "python",
   "name": "cgraph"
  },
  "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.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}