├── Dockerfile
├── LICENSE
├── README.md
├── example
├── DFML_demo_local.ipynb
├── example_basic.ipynb
└── sparksql_basic.ipynb
├── hive-bootstrap.sh
└── hive-site.xml
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM prasanthj/docker-hive-on-tez
2 |
3 | ## install spark
4 | RUN curl -s http://apache.stu.edu.tw/spark/spark-1.4.1/spark-1.4.1-bin-hadoop2.4.tgz | tar -xz -C /usr/local/
5 | RUN cd /usr/local \
6 | && ln -s spark-1.4.1-bin-hadoop2.4 spark
7 |
8 | ENV SPARK_JAR hdfs:///spark/spark-assembly-1.4.1-hadoop2.4.0.jar \
9 | SPARK_HOME /usr/local/spark \
10 | PATH $PATH:$SPARK_HOME/bin:$HADOOP_PREFIX/bin \
11 | PYTHONPATH $SPARK_HOME/python/:$PYTHONPATH \
12 | PYTHONPATH $SPARK_HOME/python/lib/py4j-0.8.2.1-src.zip:$PYTHONPATH
13 |
14 | ADD hive-site.xml $SPARK_HOME/conf/hive-site.xml
15 | ADD hive-bootstrap.sh /etc/hive-bootstrap.sh
16 | RUN chown root:root /etc/hive-bootstrap.sh && chmod 700 /etc/hive-bootstrap.sh
17 |
18 | ## install ipython
19 | RUN apt-get update && apt-get -y install python-pip python-dev build-essential python-tk libpng-dev liblapack-dev libatlas-base-dev gfortran libfreetype6-dev wget pkg-config python-matplotlib\
20 | && pip install pip --upgrade \
21 | && pip install -U jupyter \
22 | && pip install pandas scipy scikit-learn
23 |
24 |
25 | CMD /etc/hive-bootstrap.sh && /usr/local/spark/sbin/start-master.sh && IPYTHON_OPTS="notebook --no-browser --ip=0.0.0.0 --port 8888 --notebook-dir=/home/" /usr/local/spark/bin/pyspark
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
676 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # docker-spark-hive-ipython
2 | # 前言
3 |
4 | 感謝各位參加Hadoop Conference 2015
5 | 為了方便各位實作,將協助各位使用docker在本機上建立spark教學環境.
6 | 熟悉Docker的朋友可以直接跳過這段.
7 |
8 | # Docker安裝教學
9 |
10 | - Linux環境餐請參考:https://docs.docker.com/linux/step_one/
11 | - Mac環境請參考:https://docs.docker.com/installation/mac/
12 | - 可以安裝boot2docker
13 | - **推薦先用VMWARE建立純linux環境後再安裝docker**
14 |
15 | # 使用boot2docker特別注意
16 | 因為預設的記憶體只有2G,本包可能需要至少**4G**的記憶體,若執行時遇到記憶體不足的問題,請按照下列步驟修改.
17 | - `vim ~/.boot2docker/profile`
18 | - 在檔案中加入 Memory = 4096
19 | *!!以下步驟將會重置您的boot2docker,亦即所有的images都會刪除,請謹慎使用!!*
20 | - boot2docker stop
21 | - boot2docker destroy
22 | - boot2docker init
23 | - boot2docker start
24 |
25 | # 系統需求
26 | - CPU 4core
27 | - RAM 4G以上
28 | - HDD 10G以上(Docker images檔約4G)
29 |
30 | # 方法一:直接拉取Docker Images
31 |
32 | - `docker pull bryanyang0528/docker-spark-hive-ipython`
33 | (拉取成功後就不用再自行Build Images,直接跳執行)
34 |
35 | # 方法二:建立Docker Images
36 |
37 | - 請確認您的電腦上已經安裝git
38 | - 進入任意合適的目錄
39 | - `git clone https://github.com/bryanyang0528/docker-spark-hive-ipython.git`
40 | - `cd docker-spark-hive-ipython`
41 | - `docker build .` 此步驟將會開始建立docker images
42 | - `docker images` 確認新建立的images id (一個英數組合)
43 | - `docker tag docker-spark-hive-ipython:latest`
44 |
45 | # 執行Docker Images
46 |
47 | - `docker run -d -p 8888:8888 -p 4040:4040 --name pyspark bryanyang0528/docker-spark-hive-ipython`
48 |
49 | # 進入ipython
50 |
51 | - linux: 直接在瀏覽器輸入`http://localhost:8888` , Spark的UI在`http://localhost:4040`
52 | - Mac: 請先在terminal中輸入 `boot2docker ip` 確認ip位置,再到瀏覽器中輸入`http://:8888`
53 |
54 | #### SparkContext(as sc) and SqlContext(as sqlContext) will launch automatically when you open a notebook.
55 |
--------------------------------------------------------------------------------
/example/DFML_demo_local.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {
7 | "collapsed": false
8 | },
9 | "outputs": [],
10 | "source": [
11 | "# 設定Spark\n",
12 | "import os\n",
13 | "import sys\n",
14 | "# SPARK_HOME=\"/opt/spark-1.4.1-bin-hadoop2.6\"\n",
15 | "# os.environ[\"SPARK_HOME\"] = SPARK_HOME\n",
16 | "# sys.path.append(os.path.join(SPARK_HOME, 'python'))\n",
17 | "# sys.path.append(os.path.join(SPARK_HOME, 'python/lib/py4j-0.8.2.1-src.zip'))\n",
18 | "#----\n",
19 | "import numpy as np\n",
20 | "import pandas as pd\n",
21 | "import matplotlib.pyplot as plt\n",
22 | "%matplotlib inline\n",
23 | "# import seaborn as sns\n",
24 | "# sns.set(rc={\"figure.figsize\": (14, 5)},palette=sns.color_palette(\"Set1\", 2))\n",
25 | "from pyspark.sql.types import *\n",
26 | "from pyspark.sql.functions import *\n",
27 | "from pyspark.ml.feature import *\n",
28 | "from pyspark.ml.classification import *\n",
29 | "from pyspark.ml.param import *\n",
30 | "from pyspark.ml import *\n",
31 | "# from pyspark import HiveContext\n",
32 | "# ctx = HiveContext(sc)\n",
33 | "ctx=sqlContext "
34 | ]
35 | },
36 | {
37 | "cell_type": "markdown",
38 | "metadata": {},
39 | "source": [
40 | "#DataFrame與Pipeline使用範例\n",
41 | "\n",
42 | "1. 使用 DataFrame 探索資料,觀察時間與spam的關係。\n",
43 | "2. 使用ML Pipeline進行spam預測。"
44 | ]
45 | },
46 | {
47 | "cell_type": "markdown",
48 | "metadata": {},
49 | "source": [
50 | "#資料說明\n",
51 | "\n",
52 | "資料來源是 2015痞客邦 PIXNET HACKATHON 活動中開放的[資料集](https://pixnethackathon2015.events.pixnet.net/dataset/readfirst.html)\n",
53 | "[痞客邦](https://www.pixnet.net/)
\n",
54 | "痞客邦目前華文世界最大部落格服務網站,當中蘊含大量的優質文章,但也不乏惡意灌水的廣告文章,目前站方已經設計多種演算法來偵測劣質文章,也希望多方好手及駭客高手腦力激盪來找出更好的方法揪出網路流氓。身為台灣社群龍頭,以每天2800萬次瀏覽到訪網站的流量,痞客邦開放海量數據資料,讓參賽者可以看見台灣網友更豐富多元的面向與使用行為。 \n",
55 | "\n",
56 | "---\n",
57 | "文章資料集蘊含正常使用者所發佈的優質文章,及spam使用者所發佈的劣質廣告文章,資料收集時間為2015/4。\n",
58 | "因為data使用規定,本demo無法直接提供資料,請於資料連結內下載。\n",
59 | "資料欄位說明:\n",
60 | "```\n",
61 | "\"post_at\": 文章發佈時間 (Unix Timestamp),\n",
62 | "\"author\": 作者 ID ,\n",
63 | "\"tags\": [文章歸屬的標籤列表],\n",
64 | "\"title\": 文章的標題,\n",
65 | "\"hits\": 文章總人氣,\n",
66 | "\"content\": 部落格本文\n",
67 | "\"comment_count\": 多少人 comment 過,\n",
68 | "\"comment_ids\": [留言者ID] ,\n",
69 | "\"category\": 文章的分類,\n",
70 | "\"spam\": 是否為 Spam 文章,1為spam,0為正常。\n",
71 | "```"
72 | ]
73 | },
74 | {
75 | "cell_type": "markdown",
76 | "metadata": {},
77 | "source": [
78 | "#讀取資料集"
79 | ]
80 | },
81 | {
82 | "cell_type": "code",
83 | "execution_count": 12,
84 | "metadata": {
85 | "collapsed": false
86 | },
87 | "outputs": [
88 | {
89 | "name": "stdout",
90 | "output_type": "stream",
91 | "text": [
92 | "root\n",
93 | " |-- category: string (nullable = true)\n",
94 | " |-- comment_count: long (nullable = true)\n",
95 | " |-- comment_ids: array (nullable = true)\n",
96 | " | |-- element: string (containsNull = true)\n",
97 | " |-- hits: long (nullable = true)\n",
98 | " |-- tags: array (nullable = true)\n",
99 | " | |-- element: string (containsNull = true)\n",
100 | " |-- title: string (nullable = true)\n",
101 | " |-- spam: double (nullable = true)\n",
102 | " |-- post_at: long (nullable = true)\n",
103 | "\n"
104 | ]
105 | }
106 | ],
107 | "source": [
108 | "path = <> # the path of file: articles-half-a.json.\n",
109 | "panda_df = pd.read_json(path) #如果無法讀入,可以試試python的json套件\n",
110 | "df=ctx.createDataFrame(panda_df)\n",
111 | "df=df.withColumn('spam2',df['spam'].astype(DoubleType())).drop('spam').withColumnRenamed('spam2','spam') # 1.4 bug\n",
112 | "df=df.withColumn('post_at2',(df['post_at']/1000000000).astype(LongType())).drop('post_at').withColumnRenamed('post_at2','post_at') # 1.4 bug\n",
113 | "df.printSchema()"
114 | ]
115 | },
116 | {
117 | "cell_type": "code",
118 | "execution_count": 13,
119 | "metadata": {
120 | "collapsed": false
121 | },
122 | "outputs": [
123 | {
124 | "name": "stdout",
125 | "output_type": "stream",
126 | "text": [
127 | "+--------+-------------+----+----------+--------------------+----+\n",
128 | "|category|comment_count|hits| post_at| title|spam|\n",
129 | "+--------+-------------+----+----------+--------------------+----+\n",
130 | "| 時尚流行| 0| 0|1427897290|LACOSTE 2013 春夏新品預覽會| 1.0|\n",
131 | "| 汽機車| 0| 445|1428297431| VIRAGE 引擎抖動、不順!| 0.0|\n",
132 | "+--------+-------------+----+----------+--------------------+----+\n",
133 | "\n"
134 | ]
135 | }
136 | ],
137 | "source": [
138 | "# 觀察table內的數值\n",
139 | "df.select('category','comment_count','hits','post_at','title','spam').show(2) "
140 | ]
141 | },
142 | {
143 | "cell_type": "markdown",
144 | "metadata": {},
145 | "source": [
146 | "---"
147 | ]
148 | },
149 | {
150 | "cell_type": "markdown",
151 | "metadata": {},
152 | "source": [
153 | "#使用 DataFrame 探索資料,觀察時間與spam的關係\n",
154 | "我們想要知道spam和時間的關係,是否spam大部份發生在晚上或白天,非spam是否有分布上的差異。 \n",
155 | "原始資料是巨大的表格形式,不利於觀察,我們利用Spark處理大資料的能力將大資料聚集成小資料,再利用Pandas將它視覺化。 \n",
156 | "\n",
157 | "步驟:\n",
158 | "1. 觀察原始時間資料。\n",
159 | "2. 定義解析時間用的UDF ,用udf將utc數字轉成時間類型。\n",
160 | "2. 計算每一小時的spam和非sapm數量,也就是聚集時間和spam成group並進行count。\n",
161 | "3. 視覺化,轉成pandas畫圖。"
162 | ]
163 | },
164 | {
165 | "cell_type": "markdown",
166 | "metadata": {},
167 | "source": [
168 | "###觀察原始時間資料\n",
169 | "原始時間在欄位'post_at',格式是UTC second."
170 | ]
171 | },
172 | {
173 | "cell_type": "code",
174 | "execution_count": 14,
175 | "metadata": {
176 | "collapsed": false,
177 | "scrolled": true
178 | },
179 | "outputs": [
180 | {
181 | "name": "stdout",
182 | "output_type": "stream",
183 | "text": [
184 | "+----------+----+\n",
185 | "| post_at|spam|\n",
186 | "+----------+----+\n",
187 | "|1427897290| 1.0|\n",
188 | "|1428297431| 0.0|\n",
189 | "|1428749080| 1.0|\n",
190 | "+----------+----+\n",
191 | "\n"
192 | ]
193 | }
194 | ],
195 | "source": [
196 | "df.select('post_at','spam').show(3)"
197 | ]
198 | },
199 | {
200 | "cell_type": "markdown",
201 | "metadata": {},
202 | "source": [
203 | "###定義解析時間用的UDF \n",
204 | "1. 設定台灣時差\n",
205 | "2. 定義把utc時間轉成當天小時時間的function\n",
206 | "3. 定義SQL UDF"
207 | ]
208 | },
209 | {
210 | "cell_type": "code",
211 | "execution_count": 15,
212 | "metadata": {
213 | "collapsed": false
214 | },
215 | "outputs": [],
216 | "source": [
217 | "from datetime import datetime,tzinfo,timedelta\n",
218 | "# 定義把utc時間轉成當天小時時間的function\n",
219 | "get_hour = lambda x: (datetime.utcfromtimestamp(float(x)) + timedelta(hours=8)).hour \n",
220 | "# 定義SQL UDF\n",
221 | "hourOfDay = udf(get_hour, IntegerType()) "
222 | ]
223 | },
224 | {
225 | "cell_type": "markdown",
226 | "metadata": {},
227 | "source": [
228 | "###計算每一小時的spam和非sapm數量\n",
229 | "1. 使用udf,增加hour 欄位 \n",
230 | "2. group by (spam , hour) \n",
231 | "3. 計算每個group內的數量並且命名為 'count' \n",
232 | "4. 照時間順序排序結果"
233 | ]
234 | },
235 | {
236 | "cell_type": "code",
237 | "execution_count": 16,
238 | "metadata": {
239 | "collapsed": false
240 | },
241 | "outputs": [
242 | {
243 | "name": "stdout",
244 | "output_type": "stream",
245 | "text": [
246 | "root\n",
247 | " |-- spam: double (nullable = true)\n",
248 | " |-- hour: integer (nullable = true)\n",
249 | " |-- count: long (nullable = false)\n",
250 | "\n"
251 | ]
252 | }
253 | ],
254 | "source": [
255 | "df_hour=(df.withColumn('hour',hourOfDay(df['post_at'])) # 使用上述定義的UDF,增加hour欄位\n",
256 | " .groupBy('spam','hour') # group by (spam , hour) \n",
257 | " .agg(count('*').alias('count')) # 計算每個group內的數量並且命名為 'count' \n",
258 | " .orderBy(asc('hour'))) # 照時間順序排序結果\n",
259 | " \n",
260 | "df_hour.printSchema()"
261 | ]
262 | },
263 | {
264 | "cell_type": "markdown",
265 | "metadata": {},
266 | "source": [
267 | "###視覺化\n",
268 | "圖片藍色是spam文章,紅色是正常文章。 \n",
269 | "經由視覺化更有效地觀察資料,我們可以發現,發文數量呈現日多夜少的情形。\n",
270 | "非spam的發文數量於晚間12點達到最高峰,晚餐和睡眠時間最低。\n",
271 | "spam方面與非spam的發文數量相比,spam半夜特別多,且變化較大。 \n",
272 | "\n",
273 | "步驟:\n",
274 | "1. spark dataframe轉成pandas dataframe\n",
275 | "2. 使用pandas畫圖"
276 | ]
277 | },
278 | {
279 | "cell_type": "code",
280 | "execution_count": 17,
281 | "metadata": {
282 | "collapsed": false
283 | },
284 | "outputs": [
285 | {
286 | "data": {
287 | "text/plain": [
288 | ""
289 | ]
290 | },
291 | "execution_count": 17,
292 | "metadata": {},
293 | "output_type": "execute_result"
294 | },
295 | {
296 | "data": {
297 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAz0AAAFVCAYAAADFUIFrAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XucHXV5+PHPkrABTMQEIkEItxgeqVbkWtpiQUsVirdq\nQamXKN5+tkVrlQreoFoFBFTAilINCcjVqogXLBQVpSIFRbSKTxQhBEhCMBsgBBMS9vfHTMIS9gZ7\n5sxk9vN+vfLKOTOz8zzn7Dln9jnfW09/fz+SJEmS1Fab1Z2AJEmSJFXJokeSJElSq1n0SJIkSWo1\nix5JkiRJrWbRI0mSJKnVLHokSZIktZpFjySp8SLi4IhY1KFzzYuIj3biXJKkTYNFjySpdhFxe0S8\nsEvh+st/kqRxwqJHktQE/UBP3Ul0UkRMrDsHSVLBD2RJ0mNExEzgDOBAii/HLsrMYyJiM+D9wFuA\nLYHvAMdk5v0RcTBwfmbOHHCe24GjM/O7EXEi8EfAQ8DfAHcAczLzJxFxPrAT8I2IWAf8a2aeNkRu\nxwP/DKwEPpCZF0bEfsA3gO0zs7887pXAhzPzeUM8zGkR8U3gL4BfAX+Xmb8rf/bPysc/G1gAvCsz\nrxvwmN6cmVeX908EZmXm6yNiF+B35fNzAnAbcPCwT7YkqSts6ZEkbRARE4BvUvzBvjOwA3BRufuN\nwByKP+R3AyYDnxnmdBt3IXtpea6tgcvX/2xmvp6iCHpJZk4ZquABZgDbAM8o8zgnImZn5g3A74EX\nDzj29cD8Ic7TA7wGOBGYCvwW+BhAREwDvgV8GpgGfBL4VkRMHfCYBj6uwbrJ/QXwrI3ykSTVyKJH\nkjTQ/sD2wLGZ+VBmr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VPWdQs\niojdy2lFDwF+Wf6bA5xS/n/ZcOfp61s1pjymT5/CsmUPjOkcY1V3DnXHb0IOdcdvQg51x29CDnXH\nN4dmxG9CDnXHb0IOdcdvQg51x29CDnXHN4dmxO9EDtOnTxlyX9UtPVCs4XBBRPQCt1JMWT0BuDQi\n3kw5ZXUX8pAkSZI0DlVe9GTmzcB+g+w6pOrYkiRJktSNdXokSZIkqTYWPZIkSZJazaJHkiRJUqtZ\n9EiSJElqNYseSZIkSa3WjSmrJUmSJG1kzZo1LFq0EIC+vsksX75yzOecOXNnent7x3yega644pvs\nt98BbLvtth09bzdZ9EiSJEk1WLRoIbce/mJ2mjiBpR043x1r18G3/otZs2Z34GyP+va3v8Guu86y\n6JEkSZL0xO00cQK7Tdy8a/EWL76b9773nTz3uXvxf/93M9OnP52TTjodmMJvfpOceupJrF69mh12\n2JHjj/8wN954Pb/+9S185CMfZIsttuDss+cyadKkDef78pcv5utf/yoTJkxg111348QTP8YXv/h5\n7r77Tu666y5WrFjBa1/7Bl760lewatUqjj/+vTzwwP2sW7eWt771HRx44EEsXnw373nPMey77z7c\ncMONPOtZf8Rhh72Ec889h76+FZxwwkfZY49nj+lxO6ZHkiRJGkfuvHMRr3rVkZx//qVMnjyFa675\nLgD/9m8n8A//8C7mz7+IWbOeybnnnsMLXnAIz3rWHpxwwseYO/eCxxQ8ABdcMJ958y5k/vyLOPbY\n4zds/93vbuXMMz/H5z8/l3PP/Q/uvfdeJk2axEknncrcuV/ijDM+x2c+8+kNx991150cffTRXHjh\nV7jjjoVcffWVnH32XP7xH9/FeeedO+bHbNEjSZIkjSPbb78Dz3xm0QUu4lksXnw3K1euZOXKley5\n514AHHro4fzsZzdt+Jn+/v5BzzVr1mxOPPEDXHnlFWy22QQAenp6OPDAg+jt7WXrrZ/G3nvvyy23\n/B/9/f187nOfYc6co3j3u/+ee+9dRl/f8g05zZ49m56eHnbddTf23Xd/AHbddRZLltw95sds0SNJ\nkiSNI729j3an22yzCTzyyCMj/kx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A92V0d5bboWbaPWx9a1yb49eRg0WPJI1T0YUZJUeIv37c\nWW3qzqGu+FFMZT8rM3/h66AR74Va4zchh269DqIZs9zWmkPd8evKwcVJJWn8+kjN8f+15vhQfw61\nxM/MVZm5fuIdXwf1Pwd1x4f6c+jW62D9LLevAA4CPhQR/9Sl2EPl8MEu51B3/FpyaNWYHknSY8Xw\nM0pW3rWp7vhNyKHu+KPIofKZRX0O6o8/ihzGxXuBx89yexDdn+W27pl2645fSw4WPZLUbnXPKFl3\n/CbkUHf8JuRQd/wm5FB3/CbkUHd8aMYst3XnUHf8WnKw6JGkdqt7Rsm64zchh7rjNyGHuuM3IYe6\n4zchh7rjQzNmua07h7rj15KDExlIkiRJajUnMpAkSZLUahY9kiRJklrNokeSJElSq1n0SJJqFxGP\nlAtmSpLUcRY9kqSmqGx9iIjweidJ45hTVkuSmuKdEfE3wDbAsZn5VYCIOBT4ODABWAa8PTNvjYg3\nAodn5hHlcRvul7dfB9wPzAZeC/y8uw9HktQUfvMlSWqK+zJzf+D1wJkAEfF04Dzg7zJzT+BC4IJR\nnu9PgPdk5h9npgWPJI1jFj2SpKa4uPz/euAZEdFLUbjcnJm/LvfNA54XEU8ZxfmuzczbOp+mJGlT\nY9EjSWqKPwBk5rry/khdsNfy2OvYFhvtX9mhvCRJmziLHklSk/0Y2DMiorw/B/hpZj4I/BZ4bkT0\nlq1Cf1tXkpKkZrPokSQ1Qf9g9zNzGcUYnwsj4mbg7ygmKCAzfwz8N/BL4CrgVwPO0z/IOSVJ41RP\nf7/XBEmSJEntZUuPJEmSpFaz6JEkSZLUahY9kiRJklrNokeSJElSq1n0SJIkSWo1ix5JkiRJrWbR\nI0mSJKnVLHokSZIktdr/B0hLtjUQfVBxAAAAAElFTkSuQmCC\n",
298 | "text/plain": [
299 | ""
300 | ]
301 | },
302 | "metadata": {},
303 | "output_type": "display_data"
304 | }
305 | ],
306 | "source": [
307 | "# spark dataframe轉成pandas dataframe\n",
308 | "pandas_df = df_hour.toPandas() \n",
309 | "# 轉一下格式方便畫圖\n",
310 | "pandas_df = pandas_df.pivot_table(index='hour',columns='spam',values='count') \n",
311 | "pandas_df.set_axis(1,['not spam','spam'])\n",
312 | "# 使用pandas畫圖\n",
313 | "ax=pandas_df.plot(kind='bar') \n",
314 | "ax.set_title('count by hour')\n",
315 | "ax.set_ylabel('count')\n",
316 | "ax.set_xlabel('hour')"
317 | ]
318 | },
319 | {
320 | "cell_type": "markdown",
321 | "metadata": {},
322 | "source": [
323 | "----"
324 | ]
325 | },
326 | {
327 | "cell_type": "markdown",
328 | "metadata": {},
329 | "source": [
330 | "#使用ML Pipeline進行spam預測\n",
331 | "步驟:\n",
332 | "1. 前處理。 \n",
333 | "3. 建立pipeline。\n",
334 | "4. 分成訓練和測試資料。\n",
335 | "5. 使用訓練資料訓練pipeline。\n",
336 | "7. 使用測試資料評估性能。"
337 | ]
338 | },
339 | {
340 | "cell_type": "markdown",
341 | "metadata": {},
342 | "source": [
343 | "###前處理 \n",
344 | "特徵抽取,加入時間特徵,利用上述dataframe udf加入hour特徵。"
345 | ]
346 | },
347 | {
348 | "cell_type": "code",
349 | "execution_count": 18,
350 | "metadata": {
351 | "collapsed": false
352 | },
353 | "outputs": [],
354 | "source": [
355 | "# 加入時間特徵\n",
356 | "df_ml = df.withColumn('hour',hourOfDay(df['post_at']).astype(DoubleType())) "
357 | ]
358 | },
359 | {
360 | "cell_type": "markdown",
361 | "metadata": {},
362 | "source": [
363 | "###建立 Pipeline\n",
364 | "本demo目的為Pipeline的使用,為了簡單起見,本demo只挑選幾個簡單的特徵:\n",
365 | "- 時間\"hour\", 時間特徵使用上述的發文小時時間, 在前處理步驟已經加入。\n",
366 | "- 點擊數\"hits\",\n",
367 | "- 留言數量'comment_count'。 \n",
368 | "\n",
369 | "我們使用線性分類器logistic regression,這種分類器只接受數值特徵,類別特徵必須先經過編碼轉換才能通過分類器。留言數和點擊數本身是數值特徵, 小時時間類別是類別特徵需要經過編碼轉成數值特徵。\n",
370 | "\n",
371 | "Pipeline流程圖:\n",
372 | "```\n",
373 | "發文時間 ---- 類別數值化 ------------\\ \n",
374 | " \\ \n",
375 | "點擊數量 -------------------------- 結合 ---> 分類器 \n",
376 | " / \n",
377 | "留言數量 --------------------------/ \n",
378 | "```"
379 | ]
380 | },
381 | {
382 | "cell_type": "code",
383 | "execution_count": 19,
384 | "metadata": {
385 | "collapsed": false
386 | },
387 | "outputs": [],
388 | "source": [
389 | "# 發文時間編碼\n",
390 | "hour_encoder = OneHotEncoder(inputCol=\"hour\", outputCol=\"hour_code\") \n",
391 | "\n",
392 | "# 結合所有特徵\n",
393 | "assembler = VectorAssembler(inputCols=[\"hour_code\",\"hits\",'comment_count'], outputCol=\"features\")\n",
394 | "\n",
395 | "# 分類器\n",
396 | "log_regressor = LogisticRegression(featuresCol=\"features\",labelCol=\"spam\")\n",
397 | "\n",
398 | "#機器學習管線\n",
399 | "pipeline = Pipeline(stages=[hour_encoder,assembler,log_regressor])"
400 | ]
401 | },
402 | {
403 | "cell_type": "markdown",
404 | "metadata": {},
405 | "source": [
406 | "###把資料分成訓練和測試資料\n",
407 | "在比例上,訓練資料佔七成,測試資料佔三成"
408 | ]
409 | },
410 | {
411 | "cell_type": "code",
412 | "execution_count": 20,
413 | "metadata": {
414 | "collapsed": true
415 | },
416 | "outputs": [],
417 | "source": [
418 | "df_train,df_test=df_ml.randomSplit([7.,3.],123)"
419 | ]
420 | },
421 | {
422 | "cell_type": "markdown",
423 | "metadata": {},
424 | "source": [
425 | "###訓練pipeline\n",
426 | "pipeline是Estimator所以有fit方法。"
427 | ]
428 | },
429 | {
430 | "cell_type": "code",
431 | "execution_count": 21,
432 | "metadata": {
433 | "collapsed": true
434 | },
435 | "outputs": [],
436 | "source": [
437 | "model = pipeline.fit(df_train)"
438 | ]
439 | },
440 | {
441 | "cell_type": "markdown",
442 | "metadata": {},
443 | "source": [
444 | "###評估pipeline\n",
445 | "1. 用訓練好的pipeline進行預測操是資料集。\n",
446 | "3. 使用DataFrame計算預測精準度。\n",
447 | "3. 利用dataframe觀察資料以利檢討模型。"
448 | ]
449 | },
450 | {
451 | "cell_type": "code",
452 | "execution_count": 22,
453 | "metadata": {
454 | "collapsed": true
455 | },
456 | "outputs": [],
457 | "source": [
458 | "# 用訓練好的pipeline進行預測測試資料集。\n",
459 | "# 訓練好的pipeline是Transformer所以有transform方法。\n",
460 | "df_pred = model.transform(df_test)"
461 | ]
462 | },
463 | {
464 | "cell_type": "code",
465 | "execution_count": 23,
466 | "metadata": {
467 | "collapsed": false
468 | },
469 | "outputs": [
470 | {
471 | "name": "stdout",
472 | "output_type": "stream",
473 | "text": [
474 | "root\n",
475 | " |-- category: string (nullable = true)\n",
476 | " |-- comment_count: long (nullable = true)\n",
477 | " |-- comment_ids: array (nullable = true)\n",
478 | " | |-- element: string (containsNull = true)\n",
479 | " |-- hits: long (nullable = true)\n",
480 | " |-- tags: array (nullable = true)\n",
481 | " | |-- element: string (containsNull = true)\n",
482 | " |-- title: string (nullable = true)\n",
483 | " |-- spam: double (nullable = true)\n",
484 | " |-- post_at: long (nullable = true)\n",
485 | " |-- hour: double (nullable = true)\n",
486 | " |-- hour_code: vector (nullable = true)\n",
487 | " |-- features: vector (nullable = true)\n",
488 | " |-- rawPrediction: vector (nullable = true)\n",
489 | " |-- probability: vector (nullable = true)\n",
490 | " |-- prediction: double (nullable = true)\n",
491 | "\n"
492 | ]
493 | }
494 | ],
495 | "source": [
496 | "# 觀察transofrm對dataframe做了什麼事,所有pipeline設定的特徵和預測都加入dataframe了。\n",
497 | "df_pred.printSchema()"
498 | ]
499 | },
500 | {
501 | "cell_type": "code",
502 | "execution_count": 24,
503 | "metadata": {
504 | "collapsed": false
505 | },
506 | "outputs": [
507 | {
508 | "name": "stdout",
509 | "output_type": "stream",
510 | "text": [
511 | "+------------------+\n",
512 | "| accuracy|\n",
513 | "+------------------+\n",
514 | "|0.7128378378378378|\n",
515 | "+------------------+\n",
516 | "\n"
517 | ]
518 | }
519 | ],
520 | "source": [
521 | "pred_label = df_pred.select(\"prediction\", \"spam\")\n",
522 | "# 建立accuracy function,使用內建dataframe functions達成UDAF\n",
523 | "accuracy = avg((pred_label.prediction==pred_label['spam']).astype(IntegerType())).alias(\"accuracy\") \n",
524 | "# 需要groupBy才能使用此function, 所以就group所有data吧\n",
525 | "pred_label.groupBy().agg(accuracy).show()"
526 | ]
527 | },
528 | {
529 | "cell_type": "code",
530 | "execution_count": 25,
531 | "metadata": {
532 | "collapsed": false
533 | },
534 | "outputs": [
535 | {
536 | "name": "stdout",
537 | "output_type": "stream",
538 | "text": [
539 | "+----+----+-------------+----+----------+\n",
540 | "|hour|hits|comment_count|spam|prediction|\n",
541 | "+----+----+-------------+----+----------+\n",
542 | "|13.0| 189| 0| 0.0| 1.0|\n",
543 | "|12.0| 34| 0| 0.0| 1.0|\n",
544 | "|20.0| 0| 0| 1.0| 0.0|\n",
545 | "|20.0| 0| 0| 1.0| 0.0|\n",
546 | "|20.0| 0| 0| 1.0| 0.0|\n",
547 | "|20.0| 0| 0| 1.0| 0.0|\n",
548 | "|15.0| 0| 0| 0.0| 1.0|\n",
549 | "|10.0|2012| 0| 0.0| 1.0|\n",
550 | "|15.0|3652| 4| 0.0| 1.0|\n",
551 | "|13.0| 0| 0| 0.0| 1.0|\n",
552 | "+----+----+-------------+----+----------+\n",
553 | "\n"
554 | ]
555 | }
556 | ],
557 | "source": [
558 | "# 檢討模型效能,觀察什麼樣的特徵導致錯誤預測。\n",
559 | "df_pred.filter(df_pred['spam']!=df_pred['prediction'])\\\n",
560 | " .select('hour','hits','comment_count','spam','prediction')\\\n",
561 | " .show(10)"
562 | ]
563 | },
564 | {
565 | "cell_type": "markdown",
566 | "metadata": {},
567 | "source": [
568 | "author: Wayne-Lin \n",
569 | "#=====使用完請隨手關燈sc.stop(),感謝您======"
570 | ]
571 | },
572 | {
573 | "cell_type": "code",
574 | "execution_count": 7,
575 | "metadata": {
576 | "collapsed": false
577 | },
578 | "outputs": [],
579 | "source": [
580 | "sc.stop()"
581 | ]
582 | },
583 | {
584 | "cell_type": "code",
585 | "execution_count": null,
586 | "metadata": {
587 | "collapsed": false
588 | },
589 | "outputs": [],
590 | "source": []
591 | }
592 | ],
593 | "metadata": {
594 | "kernelspec": {
595 | "display_name": "Python 2",
596 | "language": "python",
597 | "name": "python2"
598 | },
599 | "language_info": {
600 | "codemirror_mode": {
601 | "name": "ipython",
602 | "version": 2
603 | },
604 | "file_extension": ".py",
605 | "mimetype": "text/x-python",
606 | "name": "python",
607 | "nbconvert_exporter": "python",
608 | "pygments_lexer": "ipython2",
609 | "version": "2.7.10"
610 | }
611 | },
612 | "nbformat": 4,
613 | "nbformat_minor": 0
614 | }
615 |
--------------------------------------------------------------------------------
/example/example_basic.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "## Basic RDD Operation Example"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 1,
13 | "metadata": {
14 | "collapsed": true
15 | },
16 | "outputs": [],
17 | "source": [
18 | "list_a = [x for x in range(10)]"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 2,
24 | "metadata": {
25 | "collapsed": false
26 | },
27 | "outputs": [
28 | {
29 | "data": {
30 | "text/plain": [
31 | "55"
32 | ]
33 | },
34 | "execution_count": 2,
35 | "metadata": {},
36 | "output_type": "execute_result"
37 | }
38 | ],
39 | "source": [
40 | "sc.parallelize(list_a).map(lambda x: x+1).reduce(lambda x , y :x+y)"
41 | ]
42 | },
43 | {
44 | "cell_type": "markdown",
45 | "metadata": {},
46 | "source": [
47 | "## SparkSQL Example"
48 | ]
49 | },
50 | {
51 | "cell_type": "code",
52 | "execution_count": 3,
53 | "metadata": {
54 | "collapsed": true
55 | },
56 | "outputs": [],
57 | "source": [
58 | "from pyspark.sql import HiveContext, Row\n",
59 | "sqlContext= HiveContext(sc)"
60 | ]
61 | },
62 | {
63 | "cell_type": "code",
64 | "execution_count": 4,
65 | "metadata": {
66 | "collapsed": false
67 | },
68 | "outputs": [
69 | {
70 | "data": {
71 | "text/plain": [
72 | "DataFrame[tableName: string, isTemporary: boolean]"
73 | ]
74 | },
75 | "execution_count": 4,
76 | "metadata": {},
77 | "output_type": "execute_result"
78 | }
79 | ],
80 | "source": [
81 | "sqlContext.sql(\"show tables\")"
82 | ]
83 | },
84 | {
85 | "cell_type": "code",
86 | "execution_count": 5,
87 | "metadata": {
88 | "collapsed": false
89 | },
90 | "outputs": [
91 | {
92 | "name": "stdout",
93 | "output_type": "stream",
94 | "text": [
95 | "+---------+----------+----+\n",
96 | "| category| product| rev|\n",
97 | "+---------+----------+----+\n",
98 | "|cellphone| thin|6000|\n",
99 | "| tablet| normal|1500|\n",
100 | "| tablet| mini|5500|\n",
101 | "|cellphone|ultra thin|5000|\n",
102 | "|cellphone|very thing|6000|\n",
103 | "| tablet| big|2500|\n",
104 | "|cellphone| bendable|3000|\n",
105 | "|cellphone| foldable|3000|\n",
106 | "| tablet| pro|4500|\n",
107 | "| tablet| pro2|6500|\n",
108 | "+---------+----------+----+\n",
109 | "\n"
110 | ]
111 | }
112 | ],
113 | "source": [
114 | "df = sc.parallelize([Row(product=\"thin\",category=\"cellphone\",rev=\"6000\"),Row(product=\"normal\",category=\"tablet\",rev=\"1500\"), Row(product=\"mini\",category=\"tablet\",rev=\"5500\"),Row(product=\"ultra thin\",category=\"cellphone\",rev=\"5000\"),Row(product=\"very thing\",category=\"cellphone\",rev=\"6000\"),Row(product=\"big\",category=\"tablet\",rev=\"2500\"),Row(product=\"bendable\",category=\"cellphone\",rev=\"3000\"),Row(product=\"foldable\",category=\"cellphone\",rev=\"3000\"),Row(product=\"pro\",category=\"tablet\",rev=\"4500\"),Row(product=\"pro2\",category=\"tablet\",rev=\"6500\")])\n",
115 | "productRevenue_df = sqlContext.createDataFrame(df)\n",
116 | "productRevenue_df.show()"
117 | ]
118 | },
119 | {
120 | "cell_type": "markdown",
121 | "metadata": {},
122 | "source": [
123 | "## Shell Script Example"
124 | ]
125 | },
126 | {
127 | "cell_type": "code",
128 | "execution_count": 16,
129 | "metadata": {
130 | "collapsed": false
131 | },
132 | "outputs": [
133 | {
134 | "name": "stdout",
135 | "output_type": "stream",
136 | "text": [
137 | "/home\r\n"
138 | ]
139 | }
140 | ],
141 | "source": [
142 | "!pwd"
143 | ]
144 | },
145 | {
146 | "cell_type": "code",
147 | "execution_count": 17,
148 | "metadata": {
149 | "collapsed": false
150 | },
151 | "outputs": [
152 | {
153 | "name": "stdout",
154 | "output_type": "stream",
155 | "text": [
156 | "Untitled.ipynb\tderby.log metastore_db\r\n"
157 | ]
158 | }
159 | ],
160 | "source": [
161 | "!ls"
162 | ]
163 | },
164 | {
165 | "cell_type": "markdown",
166 | "metadata": {},
167 | "source": [
168 | "## Spark Mllib Example"
169 | ]
170 | },
171 | {
172 | "cell_type": "code",
173 | "execution_count": 8,
174 | "metadata": {
175 | "collapsed": true
176 | },
177 | "outputs": [],
178 | "source": [
179 | "from sklearn.datasets import make_blobs\n",
180 | "from pyspark.mllib.clustering import KMeans"
181 | ]
182 | },
183 | {
184 | "cell_type": "code",
185 | "execution_count": 9,
186 | "metadata": {
187 | "collapsed": true
188 | },
189 | "outputs": [],
190 | "source": [
191 | "X, y = make_blobs(50,20, 5)"
192 | ]
193 | },
194 | {
195 | "cell_type": "code",
196 | "execution_count": 10,
197 | "metadata": {
198 | "collapsed": false
199 | },
200 | "outputs": [
201 | {
202 | "name": "stdout",
203 | "output_type": "stream",
204 | "text": [
205 | "[[ 8.79265169 8.69813553 7.26584523 -0.95237571 7.66482599\n",
206 | " -1.84022236 4.62125024 2.5017508 -10.41165513 2.09050148\n",
207 | " 3.17796425 7.85348358 10.24431579 -1.88136637 4.73685396\n",
208 | " -4.22206454 1.3553198 8.96417314 0.96634182 -0.1082746 ]\n",
209 | " [ -0.57021603 -2.95011861 2.8014989 -3.77173248 2.4647076\n",
210 | " 5.81325698 1.42435662 -7.04384883 -3.05966505 1.6740405\n",
211 | " -9.84026239 8.24840516 -5.1131863 -2.22311618 0.95482552\n",
212 | " -3.38819958 -2.10016993 2.59753474 1.76189002 9.40326368]\n",
213 | " [ -2.28491968 4.78324522 8.63483306 -4.35186232 -4.60251651\n",
214 | " -7.03618689 -8.32221764 0.66676661 7.53789095 -0.7162713\n",
215 | " -10.19716729 -11.58301531 -9.63346717 1.21774221 -3.09186347\n",
216 | " -1.61226172 -3.38826404 -5.90932636 -0.85335682 -8.50578432]\n",
217 | " [ -1.46765634 -6.44533401 3.57919445 -5.77122572 1.09529359\n",
218 | " 6.27581505 0.95850395 -4.09758186 -4.37011787 0.27320859\n",
219 | " -9.57875777 8.62468737 -5.50143944 -1.92456555 -0.96637844\n",
220 | " -1.17558067 -0.5957673 2.87336084 0.24401986 8.87688196]\n",
221 | " [ -9.49650876 -1.0219336 5.35451856 -7.49414541 -9.12113299\n",
222 | " -3.84506743 -2.52210559 -8.34878782 -5.95092744 8.55325433\n",
223 | " -6.49382995 9.91160201 -8.59122399 -1.56711779 4.7464535\n",
224 | " 0.10183576 -2.61129868 -8.5574042 -1.65643489 3.69093277]\n",
225 | " [ -9.16767611 -0.60074617 8.46580961 -7.68791995 -9.51274125\n",
226 | " -4.04907457 -3.95295082 -8.44538501 -5.80830824 7.51824738\n",
227 | " -4.31701729 10.25830408 -9.66835164 -2.20636504 4.80645569\n",
228 | " -0.28075858 -2.46094482 -9.83542093 -3.39974554 2.6094632 ]\n",
229 | " [ -5.90885199 -5.54495586 3.82752788 5.47445191 -7.56901466\n",
230 | " 6.17678723 -1.67866919 -8.18495808 4.4351337 3.01243834\n",
231 | " -9.64523205 6.18695345 6.18979228 5.44298096 -6.51295969\n",
232 | " -3.63470336 -8.37506596 -8.80310855 -5.08267496 -10.22274691]\n",
233 | " [-10.09062298 -0.35889548 8.32643481 -6.77082798 -8.61285419\n",
234 | " -2.11910124 -3.17342421 -6.94638579 -5.53397978 7.97891402\n",
235 | " -3.80749304 8.75537255 -9.07804589 -4.44827072 5.16998281\n",
236 | " -0.23544812 -3.15845139 -10.1293545 -3.40367996 2.75186944]\n",
237 | " [-10.41115107 -0.07056801 6.86882724 -8.71377695 -8.32764693\n",
238 | " -3.4462044 -3.98585553 -8.88198806 -5.91159088 7.21272186\n",
239 | " -3.70045788 10.61664859 -8.02765378 -3.49693279 4.83534002\n",
240 | " 1.23359632 -2.74023638 -9.27244076 -2.15486888 3.4196431 ]\n",
241 | " [ -8.44966524 0.15222009 5.96130028 -6.23397972 -7.9689413\n",
242 | " -2.85649827 -3.14723019 -9.74077064 -8.66686057 7.3979211\n",
243 | " -3.58851647 8.53668524 -9.38493373 -3.42164842 4.92968908\n",
244 | " 1.02644333 -1.18034366 -9.59222518 -1.65042312 1.98760466]\n",
245 | " [ -1.26695207 -5.1749955 2.25787902 -5.70478069 2.88745823\n",
246 | " 5.13921971 1.58049331 -2.88741482 -2.19152852 -0.57132348\n",
247 | " -8.52296615 10.57857894 -4.72710729 -4.52792417 -0.93353762\n",
248 | " -1.67313032 -3.61894688 3.93832621 0.97728128 9.79862303]\n",
249 | " [ -1.73310782 3.12935171 8.869709 -2.16530809 -5.27978313\n",
250 | " -8.22934144 -7.05111819 3.08486652 6.54123198 -1.14497731\n",
251 | " -9.58165071 -8.69839638 -8.93336014 4.45107776 -1.79777995\n",
252 | " -4.88620719 -3.80454933 -5.04569698 -3.04731689 -8.22577033]\n",
253 | " [ -2.09816579 -3.94974648 3.84203159 -4.67855983 1.66200019\n",
254 | " 5.62767407 0.98819188 -3.35296529 -5.24095731 1.23629149\n",
255 | " -6.2691853 9.91397356 -4.09764593 -1.68827378 2.09885207\n",
256 | " -1.13690589 -3.42814462 3.34322359 0.59152802 9.48704993]\n",
257 | " [ -5.71423354 -4.90467266 5.23284865 6.56889188 -7.31557488\n",
258 | " 3.77010156 1.62994422 -8.20567917 3.71870688 3.33084662\n",
259 | " -8.82169167 6.38913688 6.5786957 8.47159069 -4.07719953\n",
260 | " -2.44813625 -8.95443938 -9.83878637 -4.08999396 -7.91651951]\n",
261 | " [ -5.13309635 -5.61619555 4.56368682 5.69148863 -6.62759493\n",
262 | " 4.81955263 0.49868692 -7.71699533 5.03595666 3.37882384\n",
263 | " -10.88285834 7.28788877 7.34980894 7.5980248 -3.53495948\n",
264 | " -0.94232066 -9.42382332 -8.04659729 -4.38500482 -9.30833585]\n",
265 | " [ -8.89091579 0.0235643 6.34667684 -9.5793069 -8.87082747\n",
266 | " -2.40385377 -1.69359962 -6.92598514 -7.17032059 7.58525584\n",
267 | " -3.59895184 10.49636941 -10.05270864 -2.02568144 5.48475718\n",
268 | " 3.71408799 -1.96145255 -7.50221358 -1.528048 3.93092539]\n",
269 | " [-11.01809206 0.65005831 6.14247758 -7.78617531 -8.85514435\n",
270 | " -2.7158194 -2.93945877 -9.03006019 -9.42412677 5.42537483\n",
271 | " -5.38538841 10.42461165 -9.02806649 -3.12767159 4.89396746\n",
272 | " 1.58902233 -2.07727558 -10.35575586 -1.4446981 2.77487666]\n",
273 | " [ -0.74485868 -6.18602552 3.16073056 -5.98478001 2.03001923\n",
274 | " 5.41605093 2.78935152 -5.26648786 -3.27973435 -0.75328004\n",
275 | " -10.11021545 8.59663771 -4.33138411 -0.47283699 0.46859837\n",
276 | " -3.64985693 -1.84531066 4.7089873 3.06787167 6.90065742]\n",
277 | " [ -3.06584439 4.53349698 10.1336167 -3.74905318 -6.95655664\n",
278 | " -9.81691591 -7.2474322 1.42385697 9.08973736 0.77069211\n",
279 | " -10.19619408 -9.07902001 -9.55303383 2.67772765 -1.12306886\n",
280 | " -3.06078111 -3.54054204 -5.29597035 -0.92304292 -9.83068289]\n",
281 | " [ -2.05880127 2.99862419 7.57745671 -3.70846263 -5.84651158\n",
282 | " -8.50470297 -8.05605841 1.52883426 5.36114513 -1.41274885\n",
283 | " -9.19053076 -7.95406859 -8.18249091 4.64107126 -2.57381654\n",
284 | " -6.32837147 -4.20825263 -4.93159923 -0.61012825 -10.25227777]\n",
285 | " [ -3.22909228 -6.05472756 2.24222264 7.14861504 -6.90604733\n",
286 | " 7.02793092 0.64583093 -10.41601241 6.74792737 3.19870211\n",
287 | " -9.37468184 7.1796093 7.76001188 8.42036659 -4.67752832\n",
288 | " -2.72478464 -11.57321487 -9.90822188 -4.63559988 -9.14452738]\n",
289 | " [ -0.32848453 3.21469104 8.30582211 -3.40132156 -5.61302158\n",
290 | " -8.28486755 -6.43325172 2.7060666 8.84514569 -0.78917256\n",
291 | " -10.17674458 -9.10960257 -7.3373645 3.53777927 -0.21122767\n",
292 | " -4.66223103 -4.3170636 -6.74353318 -2.01765468 -9.05915 ]\n",
293 | " [ 8.87659059 10.02315524 7.63348384 -0.78999537 6.15004821\n",
294 | " -0.80182809 3.69219647 4.51633778 -11.05425249 0.65739829\n",
295 | " 3.29974463 7.66390667 8.03632908 -2.13364756 7.30530683\n",
296 | " -3.06916852 2.77256792 9.55910139 2.95371809 0.17630935]\n",
297 | " [ -1.55958542 -5.58975913 3.16365453 -7.36712016 1.24880887\n",
298 | " 7.17323695 1.15015381 -5.6185459 -4.6739325 -0.75362846\n",
299 | " -8.38835195 9.18339151 -3.20357234 -3.57954536 0.89379494\n",
300 | " -2.88340696 -1.11358099 4.07314025 0.92948887 10.99266101]\n",
301 | " [ -8.9643237 -0.75453883 8.50413004 -7.02518689 -9.98634559\n",
302 | " -0.82849811 -4.53274002 -9.09084082 -6.6357981 6.83042158\n",
303 | " -4.42255934 9.00979303 -9.3140614 -4.14881835 5.6429822\n",
304 | " 0.09036695 -1.23564314 -9.11116981 -2.82218242 3.26987051]\n",
305 | " [ 6.12513995 8.99674188 9.65724553 -1.21327036 5.97868271\n",
306 | " 0.58261886 3.23666666 3.45474845 -10.39400999 1.72747319\n",
307 | " 1.04407464 8.52157082 8.3749836 -1.49563235 5.21648981\n",
308 | " -5.11484133 1.59931938 9.36096256 2.02000206 -0.25519271]\n",
309 | " [ 0.42800271 -4.75157392 0.67068223 -6.63799638 2.30012038\n",
310 | " 5.88094233 0.17829208 -4.89444755 -3.98047312 0.14807241\n",
311 | " -8.49625553 9.03629778 -4.19923372 -2.32524137 0.24132932\n",
312 | " 1.32375501 -3.56663785 3.5635277 0.47411429 8.68253044]\n",
313 | " [ -1.97170984 4.73907768 8.5960669 -2.47929819 -5.67235034\n",
314 | " -8.39811441 -5.6700071 2.95260447 6.45600225 -0.64717907\n",
315 | " -7.93264074 -9.06398649 -7.22674135 2.16432398 -2.51049852\n",
316 | " -5.49224367 -3.72170812 -5.5418101 -3.11545286 -9.43508282]\n",
317 | " [ 5.5404227 10.63362173 6.15231789 -0.07974176 5.93787708\n",
318 | " -0.73781044 5.14992505 3.48997197 -8.93728186 2.32245306\n",
319 | " 3.69498089 8.35523137 10.30829502 -2.70288028 7.24147297\n",
320 | " -3.36114892 1.9437317 9.31858424 0.94674363 -0.44561825]\n",
321 | " [-10.63279579 -0.66113613 5.69772772 -8.40089973 -7.59638738\n",
322 | " -2.373329 -5.18061728 -8.07305814 -7.20407407 7.14676877\n",
323 | " -3.29742097 8.01483303 -8.96479687 -2.44997393 6.16384879\n",
324 | " 2.30791879 -2.31465654 -9.68337043 -2.88746672 4.2631566 ]\n",
325 | " [ -3.69508504 3.82906398 9.07353261 -3.33653134 -6.01945723\n",
326 | " -8.65407873 -6.55893289 1.23018717 7.34892996 0.0579159\n",
327 | " -9.03702647 -7.44114238 -9.73628371 2.89247218 -0.89702567\n",
328 | " -3.58736906 -3.86314433 -5.30858454 0.7791437 -9.24063714]\n",
329 | " [ 8.08644222 8.87941365 9.55340897 -1.30607678 4.9260196\n",
330 | " -3.6240853 5.15678805 2.82427402 -9.32367323 1.47574584\n",
331 | " 2.14141527 8.08307953 9.40738853 -3.88530459 5.98481482\n",
332 | " -4.53187247 0.45451155 10.25104408 0.25276069 -1.06347681]\n",
333 | " [ -2.74628449 3.31815634 8.14577466 -2.06380547 -7.28394\n",
334 | " -8.83086112 -7.16667963 3.31967965 6.82192358 0.16597437\n",
335 | " -11.24025004 -9.41793648 -9.04037246 4.14180995 0.84967642\n",
336 | " -6.27998076 -2.75612904 -6.74960893 0.89383426 -10.0398925 ]\n",
337 | " [ -5.42344655 -5.32197792 4.24357795 6.08716412 -8.04891978\n",
338 | " 7.03299931 -0.16837288 -8.42380817 5.71020325 3.93160216\n",
339 | " -8.68375605 7.9532002 6.29923985 6.1721293 -2.40228886\n",
340 | " -1.17646738 -9.20062379 -9.05222142 -4.14841751 -9.44238908]\n",
341 | " [ -9.69575602 -1.26165659 7.17574298 -7.44571536 -9.20489898\n",
342 | " -1.05552674 -2.24857561 -5.77235264 -4.90003167 7.35809601\n",
343 | " -4.37268835 7.73192904 -9.91806323 -0.95139636 5.61510012\n",
344 | " 0.04955683 -2.37936598 -9.32269386 -1.228146 4.60322034]\n",
345 | " [ -7.06918785 -4.53619792 3.49272374 7.30552997 -8.42555883\n",
346 | " 7.61654036 -0.41245482 -8.375508 5.04293329 3.47474554\n",
347 | " -9.71920488 6.42720035 5.97988831 7.16019699 -1.76321135\n",
348 | " -1.68806574 -8.29167598 -10.0597838 -5.23408344 -9.84310148]\n",
349 | " [ -2.05858916 -5.93886336 3.59727058 -5.48880491 1.75878514\n",
350 | " 6.3795424 -0.16205924 -5.66474524 -4.29749796 1.45742668\n",
351 | " -9.18978875 8.31342714 -4.39611176 -2.36679532 -0.17316643\n",
352 | " -1.29472262 -2.03622453 3.16314402 -0.03492922 9.23281076]\n",
353 | " [ 7.92722089 8.04099126 5.82785243 0.20723055 5.22372309\n",
354 | " -1.29561513 4.43317771 1.40867907 -8.20111531 1.80932808\n",
355 | " 1.89302643 10.23653117 9.35520272 -3.79136589 6.94000326\n",
356 | " -5.19072538 0.82532701 9.37551211 2.82581378 -0.31815209]\n",
357 | " [ 7.28484896 9.83327378 7.97406688 -2.15559887 6.72369761\n",
358 | " -2.07408644 4.64012786 2.81919429 -9.79647173 1.282567\n",
359 | " 2.67484452 9.44119935 8.62662785 -2.42891041 7.10834997\n",
360 | " -4.36657481 4.29044979 8.4482797 3.54488407 1.36132838]\n",
361 | " [ -2.98063191 4.074572 8.98369123 -5.03446163 -6.15695148\n",
362 | " -9.32677563 -7.07704334 3.45671378 7.75018594 -0.24121346\n",
363 | " -12.86203222 -11.01295 -7.74739849 3.5447667 -0.40269482\n",
364 | " -5.35323143 -4.33959903 -5.31024094 0.93685153 -10.66204779]\n",
365 | " [ -5.32426187 -5.79372405 4.39744709 5.20303173 -8.83290436\n",
366 | " 5.01711329 -0.56582087 -10.00838395 3.94702946 1.99261785\n",
367 | " -10.42930071 6.23734522 7.1082643 6.75586154 -4.02747233\n",
368 | " -1.89817641 -9.73914688 -10.88380192 -6.32326931 -8.66369578]\n",
369 | " [ -0.80088647 -6.59404667 4.96584639 -6.5966571 2.4049069\n",
370 | " 4.51482955 3.66068208 -3.98320439 -4.61739624 -0.913527 -7.262703\n",
371 | " 7.93022824 -3.92490351 -3.82614015 0.231209 0.22197534\n",
372 | " -2.53968922 3.95178895 2.23285485 8.38337081]\n",
373 | " [ -5.20347485 -4.76200642 4.78065089 7.80650627 -6.99190434\n",
374 | " 6.60218947 -0.75750626 -9.93655922 3.55925751 0.18589963\n",
375 | " -10.99735713 5.62395171 9.54326579 7.56091331 -5.92309349\n",
376 | " -2.0497414 -8.24049052 -10.24857496 -4.82350147 -8.9755812 ]\n",
377 | " [ 6.35284627 9.36685896 7.14045089 -2.95191837 4.50853949\n",
378 | " -3.85719013 4.67085388 2.95068103 -7.33265801 0.41501278\n",
379 | " 2.21337601 9.89184692 10.20355969 -2.09113752 5.75919196\n",
380 | " -3.96184032 0.56571767 8.68900251 0.8324208 -0.94634905]\n",
381 | " [ 7.00613987 9.63080174 9.39265305 -0.99138488 6.53977301\n",
382 | " -1.86539383 5.08117662 1.57432817 -9.66341266 1.57295707\n",
383 | " 3.40884724 9.07733361 7.79035121 -0.32150351 6.94189509\n",
384 | " -3.94901528 2.36947411 11.08678972 2.27115378 1.08629576]\n",
385 | " [ -3.67115226 2.94766368 8.70206218 -4.21991573 -6.60319089\n",
386 | " -7.05401522 -7.47685667 2.03894497 8.76000929 -1.76306672\n",
387 | " -10.59755549 -8.02661475 -6.56361209 0.81500712 -2.06300179\n",
388 | " -5.29620904 -2.62132026 -3.72818738 0.13529043 -8.75662355]\n",
389 | " [ -4.4385462 -5.86517207 4.22034216 6.81720356 -6.3163222\n",
390 | " 7.47084369 0.69087844 -9.51944839 5.68193768 3.74646092\n",
391 | " -10.13513082 6.69211503 6.30429168 7.98231544 -4.01880065\n",
392 | " -1.54689604 -8.92889236 -10.49976794 -5.70977596 -10.91617866]\n",
393 | " [ 7.40529978 9.21222707 6.76048215 -2.18044132 5.33469714\n",
394 | " -2.35195585 5.1215056 3.6254503 -10.23488585 2.88027529\n",
395 | " 2.76962641 10.17128967 8.91038073 -1.99085837 7.11521375\n",
396 | " -5.0265937 0.78647388 10.48042086 0.65197898 -1.77420073]\n",
397 | " [ 0.10021932 -6.33457931 3.6229593 -4.29785852 2.4271323\n",
398 | " 6.50368944 3.11400521 -2.10474759 -2.7370379 -1.24326915\n",
399 | " -9.33573515 10.00896148 -4.64442439 -1.40697846 -1.0308081\n",
400 | " -2.6851808 -1.39260628 4.2399263 1.30515791 9.58972213]\n",
401 | " [ -4.65253395 -4.56866878 4.41349972 7.88223699 -7.51775694\n",
402 | " 5.32978152 0.44765337 -7.92145155 3.86751537 0.94237832\n",
403 | " -9.32159783 8.06150206 5.93296409 7.07037184 -4.13101316\n",
404 | " -1.56841113 -11.65892599 -10.66518394 -6.00710412 -11.42686344]]\n"
405 | ]
406 | }
407 | ],
408 | "source": [
409 | "print X"
410 | ]
411 | },
412 | {
413 | "cell_type": "code",
414 | "execution_count": 11,
415 | "metadata": {
416 | "collapsed": true
417 | },
418 | "outputs": [],
419 | "source": [
420 | "data=sc.parallelize(X[1:10])"
421 | ]
422 | },
423 | {
424 | "cell_type": "code",
425 | "execution_count": 12,
426 | "metadata": {
427 | "collapsed": true
428 | },
429 | "outputs": [],
430 | "source": [
431 | "model = KMeans.train(data, k = 5)"
432 | ]
433 | },
434 | {
435 | "cell_type": "code",
436 | "execution_count": 14,
437 | "metadata": {
438 | "collapsed": false
439 | },
440 | "outputs": [
441 | {
442 | "data": {
443 | "text/plain": [
444 | "[array([-9.52977885, -0.21949739, 7.40559298, -7.35162615, -8.60554592,\n",
445 | " -3.11771962, -3.56486519, -8.50363237, -6.48018487, 7.52695109,\n",
446 | " -3.85337117, 9.54175262, -9.03974626, -3.39330424, 4.9353669 ,\n",
447 | " 0.43595824, -2.38499406, -9.70736034, -2.65217937, 2.6921451 ]),\n",
448 | " array([ -2.28491968, 4.78324522, 8.63483306, -4.35186232,\n",
449 | " -4.60251651, -7.03618689, -8.32221764, 0.66676661,\n",
450 | " 7.53789095, -0.7162713 , -10.19716729, -11.58301531,\n",
451 | " -9.63346717, 1.21774221, -3.09186347, -1.61226172,\n",
452 | " -3.38826404, -5.90932636, -0.85335682, -8.50578432]),\n",
453 | " array([ -5.90885199, -5.54495586, 3.82752788, 5.47445191,\n",
454 | " -7.56901466, 6.17678723, -1.67866919, -8.18495808,\n",
455 | " 4.4351337 , 3.01243834, -9.64523205, 6.18695345,\n",
456 | " 6.18979228, 5.44298096, -6.51295969, -3.63470336,\n",
457 | " -8.37506596, -8.80310855, -5.08267496, -10.22274691]),\n",
458 | " array([ -1.01893618e+00, -4.69772631e+00, 3.19034668e+00,\n",
459 | " -4.77147910e+00, 1.78000059e+00, 6.04453602e+00,\n",
460 | " 1.19143029e+00, -5.57071535e+00, -3.71489146e+00,\n",
461 | " 9.73624545e-01, -9.70951008e+00, 8.43654627e+00,\n",
462 | " -5.30731287e+00, -2.07384086e+00, -5.77645726e-03,\n",
463 | " -2.28189013e+00, -1.34796861e+00, 2.73544779e+00,\n",
464 | " 1.00295494e+00, 9.14007282e+00]),\n",
465 | " array([-9.49650876, -1.0219336 , 5.35451856, -7.49414541, -9.12113299,\n",
466 | " -3.84506743, -2.52210559, -8.34878782, -5.95092744, 8.55325433,\n",
467 | " -6.49382995, 9.91160201, -8.59122399, -1.56711779, 4.7464535 ,\n",
468 | " 0.10183576, -2.61129868, -8.5574042 , -1.65643489, 3.69093277])]"
469 | ]
470 | },
471 | "execution_count": 14,
472 | "metadata": {},
473 | "output_type": "execute_result"
474 | }
475 | ],
476 | "source": [
477 | "model.centers"
478 | ]
479 | },
480 | {
481 | "cell_type": "code",
482 | "execution_count": null,
483 | "metadata": {
484 | "collapsed": true
485 | },
486 | "outputs": [],
487 | "source": []
488 | }
489 | ],
490 | "metadata": {
491 | "kernelspec": {
492 | "display_name": "Python 2",
493 | "language": "python",
494 | "name": "python2"
495 | },
496 | "language_info": {
497 | "codemirror_mode": {
498 | "name": "ipython",
499 | "version": 2
500 | },
501 | "file_extension": ".py",
502 | "mimetype": "text/x-python",
503 | "name": "python",
504 | "nbconvert_exporter": "python",
505 | "pygments_lexer": "ipython2",
506 | "version": "2.7.6"
507 | }
508 | },
509 | "nbformat": 4,
510 | "nbformat_minor": 0
511 | }
512 |
--------------------------------------------------------------------------------
/example/sparksql_basic.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# **SparkSQL Lab: **\n",
8 | "#### From this lab, you would write code to execute SQL query in Spark. Makes your analytic life simpler and faster.\n",
9 | "#### ** During this lab we will cover: **\n",
10 | "#### *Part 1:* Linking with SparkSQL\n",
11 | "#### *Part 2:* Loading data programmatically\n",
12 | "#### *Part 3:* User-Defined Functions \n",
13 | "#### *Part 4:* Caching for performance \n",
14 | "#### *Part 5:* Your show time - How many authors tagged as spam?\n",
15 | "#### Reference for Spark RDD [Spark's Python API](https://spark.apache.org/docs/latest/api/python/pyspark.html#pyspark.RDD)"
16 | ]
17 | },
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {},
21 | "source": [
22 | "##Part 1: Linking with SparkSQL"
23 | ]
24 | },
25 | {
26 | "cell_type": "code",
27 | "execution_count": null,
28 | "metadata": {
29 | "collapsed": true
30 | },
31 | "outputs": [],
32 | "source": [
33 | "from pyspark.sql import HiveContext, Row\n",
34 | "sqlContext= HiveContext(sc)"
35 | ]
36 | },
37 | {
38 | "cell_type": "code",
39 | "execution_count": null,
40 | "metadata": {
41 | "collapsed": false
42 | },
43 | "outputs": [],
44 | "source": [
45 | "sqlContext"
46 | ]
47 | },
48 | {
49 | "cell_type": "markdown",
50 | "metadata": {},
51 | "source": [
52 | "#### HiveContext, a superset of SQLContext, was recommended for most use cases. Please make sure you are using HiveContext now!"
53 | ]
54 | },
55 | {
56 | "cell_type": "markdown",
57 | "metadata": {},
58 | "source": [
59 | "##Part 2: Loading data programmatically"
60 | ]
61 | },
62 | {
63 | "cell_type": "markdown",
64 | "metadata": {},
65 | "source": [
66 | "#### ** (2a) Read local JSON file to DataFrame **\n",
67 | "#### Now, try to read json file from Spark Example. Thank for the hashed spam data from PIXNET [PIXNET HACKATHON 2015](https://pixnethackathon2015.events.pixnet.net/)"
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": null,
73 | "metadata": {
74 | "collapsed": true
75 | },
76 | "outputs": [],
77 | "source": [
78 | "jsonfile = \"file:///opt/spark-1.4.1-bin-hadoop2.6/examples/src/main/resources/people.json\"\n",
79 | "df = sqlContext.read.load(jsonfile, format=\"json\")"
80 | ]
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "metadata": {},
85 | "source": [
86 | "####Show time: Query top 2 row"
87 | ]
88 | },
89 | {
90 | "cell_type": "code",
91 | "execution_count": null,
92 | "metadata": {
93 | "collapsed": false
94 | },
95 | "outputs": [],
96 | "source": [
97 | "# TODO: Replace with appropriate code\n",
98 | "df."
99 | ]
100 | },
101 | {
102 | "cell_type": "code",
103 | "execution_count": null,
104 | "metadata": {
105 | "collapsed": false
106 | },
107 | "outputs": [],
108 | "source": [
109 | "#print df's schema\n",
110 | "df.printSchema()"
111 | ]
112 | },
113 | {
114 | "cell_type": "markdown",
115 | "metadata": {},
116 | "source": [
117 | "#### ** (2b) Read from Hive **\n",
118 | "####Don't forget the configuration of Hive should be done by placing your hive-site.xml file in conf/."
119 | ]
120 | },
121 | {
122 | "cell_type": "code",
123 | "execution_count": null,
124 | "metadata": {
125 | "collapsed": false
126 | },
127 | "outputs": [],
128 | "source": [
129 | "sqlContext.sql(\"SHOW TABLES\").show()"
130 | ]
131 | },
132 | {
133 | "cell_type": "markdown",
134 | "metadata": {},
135 | "source": [
136 | "#### In this class, you will use *pixnet_user_log_1000* for further works"
137 | ]
138 | },
139 | {
140 | "cell_type": "markdown",
141 | "metadata": {},
142 | "source": [
143 | "#### Print the schema! What do we have?"
144 | ]
145 | },
146 | {
147 | "cell_type": "code",
148 | "execution_count": null,
149 | "metadata": {
150 | "collapsed": false
151 | },
152 | "outputs": [],
153 | "source": [
154 | "sqlContext.sql(\"SELECT *\\ \n",
155 | " FROM pixnet_user_log_1000\").printSchema()"
156 | ]
157 | },
158 | {
159 | "cell_type": "markdown",
160 | "metadata": {},
161 | "source": [
162 | "#### How many rows in *pixnet_user_log*"
163 | ]
164 | },
165 | {
166 | "cell_type": "code",
167 | "execution_count": null,
168 | "metadata": {
169 | "collapsed": false
170 | },
171 | "outputs": [],
172 | "source": [
173 | "from datetime import datetime\n",
174 | "start_time = datetime.now()\n",
175 | "\n",
176 | "df2 = sqlContext.sql(\"SELECT * \\\n",
177 | " FROM pixnet_user_log_1000\")\n",
178 | "\n",
179 | "end_time = datetime.now()\n",
180 | "\n",
181 | "print df2.count()\n",
182 | "print('Duration: {}'.format(end_time - start_time))"
183 | ]
184 | },
185 | {
186 | "cell_type": "code",
187 | "execution_count": null,
188 | "metadata": {
189 | "collapsed": false
190 | },
191 | "outputs": [],
192 | "source": [
193 | "df2.select('time').show(2)"
194 | ]
195 | },
196 | {
197 | "cell_type": "markdown",
198 | "metadata": {},
199 | "source": [
200 | "##Part 3: User-Defined Functions"
201 | ]
202 | },
203 | {
204 | "cell_type": "markdown",
205 | "metadata": {},
206 | "source": [
207 | "###In part 3, you will create your first UDF in Spark SQL with elegant lambda"
208 | ]
209 | },
210 | {
211 | "cell_type": "code",
212 | "execution_count": null,
213 | "metadata": {
214 | "collapsed": true
215 | },
216 | "outputs": [],
217 | "source": [
218 | "#registers this RDD as a temporary table using the given name.\n",
219 | "df2.registerTempTable(\"people\")\n",
220 | "\n",
221 | "# Create an UDF for how long some text is\n",
222 | "# example from user guide, length function\n",
223 | "sqlContext.registerFunction(\"strLenPython\", lambda x: len(x)) \n",
224 | "\n",
225 | "# split function for parser\n",
226 | "sqlContext.registerFunction(\"strDate\", lambda x: x.split(\"T\")[0])\n",
227 | "\n",
228 | "# put udf with expected columns\n",
229 | "results = sqlContext.sql(\"SELECT author, \\\n",
230 | " strDate(time) AS dt, \\\n",
231 | " strLenPython(action) AS lenAct \\\n",
232 | " FROM people\")"
233 | ]
234 | },
235 | {
236 | "cell_type": "code",
237 | "execution_count": null,
238 | "metadata": {
239 | "collapsed": true
240 | },
241 | "outputs": [],
242 | "source": [
243 | "# or you could use df\n",
244 | "df2.select('author').show(3)\n",
245 | "\n",
246 | "#\n",
247 | "strLenPython = udf(lambda s: len(s), IntegerType())\n",
248 | "df2.select(strLenPython(df2.action).alias('action_len')).show(2)\n"
249 | ]
250 | },
251 | {
252 | "cell_type": "code",
253 | "execution_count": null,
254 | "metadata": {
255 | "collapsed": false
256 | },
257 | "outputs": [],
258 | "source": [
259 | "# print top 5 results\n",
260 | "results.show(5)"
261 | ]
262 | },
263 | {
264 | "cell_type": "markdown",
265 | "metadata": {},
266 | "source": [
267 | "##Part 4: Caching for performance"
268 | ]
269 | },
270 | {
271 | "cell_type": "markdown",
272 | "metadata": {},
273 | "source": [
274 | "#### ** Saving to persistent tables**\n",
275 | "#### `saveAsTable ` : Saves the contents of this DataFrame to a data source as a table."
276 | ]
277 | },
278 | {
279 | "cell_type": "code",
280 | "execution_count": 19,
281 | "metadata": {
282 | "collapsed": true
283 | },
284 | "outputs": [],
285 | "source": [
286 | "sqlContext.cacheTable(\"people\")"
287 | ]
288 | },
289 | {
290 | "cell_type": "code",
291 | "execution_count": null,
292 | "metadata": {
293 | "collapsed": false
294 | },
295 | "outputs": [],
296 | "source": [
297 | "start_time = datetime.now()\n",
298 | "\n",
299 | "sqlContext.sql(\"SELECT * FROM people\").count()\n",
300 | "\n",
301 | "end_time = datetime.now()\n",
302 | "print('Duration: {}'.format(end_time - start_time))"
303 | ]
304 | },
305 | {
306 | "cell_type": "code",
307 | "execution_count": null,
308 | "metadata": {
309 | "collapsed": false
310 | },
311 | "outputs": [],
312 | "source": [
313 | "sqlContext.sql(\"SELECT strDate(time) AS dt,\\\n",
314 | " count(distinct author) AS cnt \\\n",
315 | " FROM people \\\n",
316 | " GROUP BY strDate(time)\").show(5)"
317 | ]
318 | },
319 | {
320 | "cell_type": "code",
321 | "execution_count": null,
322 | "metadata": {
323 | "collapsed": false
324 | },
325 | "outputs": [],
326 | "source": [
327 | "sqlContext.uncacheTable(\"people\")"
328 | ]
329 | },
330 | {
331 | "cell_type": "markdown",
332 | "metadata": {},
333 | "source": [
334 | "##Part 5: Your show time - How many authors are tagged as spam from pixnet_user_log?\n",
335 | "\n",
336 | "#### Here are two hive tables you will need:\n",
337 | "#### (1) author with action *pixnet_user_spam*\n",
338 | "#### (2) author with spam tag *pixnet_user_log_1000*"
339 | ]
340 | },
341 | {
342 | "cell_type": "code",
343 | "execution_count": null,
344 | "metadata": {
345 | "collapsed": true
346 | },
347 | "outputs": [],
348 | "source": [
349 | "# TODO: Replace with appropriate code\n",
350 | "result = "
351 | ]
352 | },
353 | {
354 | "cell_type": "markdown",
355 | "metadata": {},
356 | "source": [
357 | "### Don't forget to stop sc"
358 | ]
359 | },
360 | {
361 | "cell_type": "code",
362 | "execution_count": 23,
363 | "metadata": {
364 | "collapsed": true
365 | },
366 | "outputs": [],
367 | "source": [
368 | "sc.stop()"
369 | ]
370 | }
371 | ],
372 | "metadata": {
373 | "kernelspec": {
374 | "display_name": "Python 2",
375 | "language": "python",
376 | "name": "python2"
377 | },
378 | "language_info": {
379 | "codemirror_mode": {
380 | "name": "ipython",
381 | "version": 2
382 | },
383 | "file_extension": ".py",
384 | "mimetype": "text/x-python",
385 | "name": "python",
386 | "nbconvert_exporter": "python",
387 | "pygments_lexer": "ipython2",
388 | "version": "2.7.5"
389 | }
390 | },
391 | "nbformat": 4,
392 | "nbformat_minor": 0
393 | }
394 |
--------------------------------------------------------------------------------
/hive-bootstrap.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo "Starting postgresql server..."
4 | sudo -u postgres $POSTGRESQL_BIN --config-file=$POSTGRESQL_CONFIG_FILE &
5 |
6 | /etc/bootstrap.sh
7 | echo "Leaving namenode safemode..."
8 | $HADOOP_PREFIX/bin/hdfs dfsadmin -safemode leave
9 |
--------------------------------------------------------------------------------
/hive-site.xml:
--------------------------------------------------------------------------------
1 |
2 | Branch: master docker-hive-on-tez/hive-site.xml
3 | @prasanthjprasanthj on Oct 26, 2014 misc config fixes. sample data and query added.
4 | 1 contributor
5 | RawBlameHistory 154 lines (154 sloc) 3.98 KB
6 |
7 |
8 | hive.metastore.cache.pinobjtypes
9 | Table,Database,Type,FieldSchema,Order
10 |
11 |
12 | javax.jdo.option.ConnectionDriverName
13 | org.postgresql.Driver
14 |
15 |
16 | javax.jdo.option.ConnectionUserName
17 | hive
18 |
19 |
20 | hive.auto.convert.join
21 | true
22 |
23 |
24 | fs.hdfs.impl.disable.cache
25 | true
26 |
27 |
28 | fs.file.impl.disable.cache
29 | true
30 |
31 |
32 | hive.metastore.warehouse.dir
33 | /apps/hive/warehouse
34 |
35 |
36 | hive.auto.convert.sortmerge.join
37 | true
38 |
39 |
40 | hive.metastore.client.socket.timeout
41 | 60
42 |
43 |
44 | hive.optimize.bucketmapjoin
45 | true
46 |
47 |
48 | hive.optimize.bucketmapjoin.sortedmerge
49 | true
50 |
51 |
52 | hive.optimize.index.filter
53 | true
54 |
55 |
56 | hive.auto.convert.join.noconditionaltask.size
57 | 1000000000
58 |
59 |
60 | hive.auto.convert.join.noconditionaltask
61 | true
62 |
63 |
64 | hive.mapjoin.bucket.cache.size
65 | 10000
66 |
67 |
68 | hive.vectorized.execution.enabled
69 | true
70 |
71 |
72 | hive.security.authorization.enabled
73 | false
74 |
75 |
76 | hive.optimize.reducededuplication.min.reducer
77 | 4
78 |
79 |
80 | hive.server2.enable.doAs
81 | true
82 |
83 |
84 | hive.mapred.reduce.tasks.speculative.execution
85 | false
86 |
87 |
88 | javax.jdo.option.ConnectionURL
89 | jdbc:postgresql://localhost/metastore
90 |
91 |
92 | hive.enforce.bucketing
93 | true
94 |
95 |
96 | hive.metastore.execute.setugi
97 | true
98 |
99 |
100 | hive.enforce.sorting
101 | true
102 |
103 |
104 | hive.security.authorization.manager
105 | org.apache.hadoop.hive.ql.security.authorization.DefaultHiveAuthorizationProvider
106 |
107 |
108 | hive.map.aggr
109 | true
110 |
111 |
112 | hive.optimize.reducededuplication
113 | true
114 |
115 |
116 | hive.execution.engine
117 | tez
118 |
119 |
120 | hive.vectorized.execution.enabled
121 | true
122 |
123 |
124 | hive.vectorized.groupby.maxentries
125 | 10000
126 |
127 |
128 | hive.vectorized.groupby.checkinterval
129 | 10000
130 |
131 |
132 | hive.input.format
133 | org.apache.hadoop.hive.ql.io.HiveInputFormat
134 |
135 |
136 | javax.jdo.option.ConnectionPassword
137 | hive
138 |
139 |
140 | tez.am.node-blacklisting.enabled
141 | false
142 |
143 |
144 | hive.prewarm.numcontainers
145 | 3
146 |
147 | Controls the number of containers to prewarm for tez (hadoop 2 only)
148 |
149 |
150 |
151 | mapred.tez.java.opts
152 | -Xmx256m
153 |
154 |
155 | hive.tez.container.size
156 | 256
157 |
158 |
159 |
160 |
--------------------------------------------------------------------------------