├── 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 | # Introduction 3 | 4 | - Apache Hive (trunk version) 5 | - Apache Tez 0.5.2 6 | - Apache Hadoop 2.5.2 7 | - PostgreSQL 9.3 (Hive metastore backend) 8 | - Apach Spark 1.4.1 9 | - Jupyter 10 | 11 | # Install Docker 12 | 13 | - Linux:https://docs.docker.com/linux/step_one/ 14 | - Mac:https://docs.docker.com/installation/mac/ 15 | - Install boot2docker 16 | - **Recommand** Simulate a pure Linux(like Ubuntu) enviroment in VMWARE and install docker in it. 17 | 18 | # **Attention** for boot2docker user 19 | The default memory of boot2docker is only 2G, and recommended system requirement is 4G. 20 | There may be some unexpection problem if memory is not enough. 21 | You can change the default memory setting in following way: 22 | 23 | - `vim ~/.boot2docker/profile` 24 | - add `Memory = 4096` in this file. 25 | * **Attention** The following process will reset your boot2docker, it's mean your images and caontainers will be erased. 26 | - boot2docker stop 27 | - boot2docker destroy 28 | - boot2docker init 29 | - boot2docker start 30 | 31 | # Recommended System Requirement 32 | - CPU 4core 33 | - RAM 4G up 34 | - HDD 10G up (4G for Docker images) 35 | 36 | # Pull The Docker Image 37 | 38 | - `docker pull bryanyang0528/docker-spark-hive-ipython` 39 | 40 | # Build The Docker Image 41 | 42 | - Install git first 43 | - Enter a apropriate directory 44 | - `git clone https://github.com/bryanyang0528/docker-spark-hive-ipython.git` 45 | - `cd docker-spark-hive-ipython` 46 | - `docker build .` 47 | - `docker images` confirm the images id 48 | - `docker tag docker-spark-hive-ipython:latest` 49 | 50 | # Run the Docker Image 51 | 52 | - `docker run -d -p 8888:8888 -p 4040:4040 --name pyspark bryanyang0528/docker-spark-hive-ipython` 53 | 54 | # Launch the Jupyter 55 | 56 | - linux: Type the web address `http://localhost:8888` in any browser. The link of Spark UI is `http://localhost:4040`. 57 | - Mac:(for boot2docker) In your terminal, press `boot2docker ip` confirm the ip address of boot2docker,the type `http://:8888`in the browser. 58 | 59 | #### SparkContext(as **sc**) and SqlContext(as **sqlContext**) will launch automatically when you open a notebook. 60 | -------------------------------------------------------------------------------- /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 SQLContext, Row\n", 34 | "sqlContext = SQLContext(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": "code", 50 | "execution_count": null, 51 | "metadata": { 52 | "collapsed": true 53 | }, 54 | "outputs": [], 55 | "source": [ 56 | "from pyspark.sql import HiveContext, Row\n", 57 | "sqlContext= HiveContext(sc)" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": null, 63 | "metadata": { 64 | "collapsed": false 65 | }, 66 | "outputs": [], 67 | "source": [ 68 | "sqlContext" 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "metadata": {}, 74 | "source": [ 75 | "#### HiveContext, a superset of SQLContext, was recommended for most use cases. Please make sure you are using HiveContext now!" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "##Part 2: Loading data programmatically" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "#### ** (2a) Read local JSON file to DataFrame **\n", 90 | "#### 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/)" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": { 97 | "collapsed": true 98 | }, 99 | "outputs": [], 100 | "source": [ 101 | "jsonfile = \"file:///opt/spark-1.4.1-bin-hadoop2.6/examples/src/main/resources/people.json\"\n", 102 | "df = sqlContext.read.load(jsonfile, format=\"json\")" 103 | ] 104 | }, 105 | { 106 | "cell_type": "markdown", 107 | "metadata": {}, 108 | "source": [ 109 | "####Show time: Query top 2 row" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": null, 115 | "metadata": { 116 | "collapsed": false 117 | }, 118 | "outputs": [], 119 | "source": [ 120 | "# TODO: Replace with appropriate code\n", 121 | "df." 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": null, 127 | "metadata": { 128 | "collapsed": false 129 | }, 130 | "outputs": [], 131 | "source": [ 132 | "#print df's schema\n", 133 | "df.printSchema()" 134 | ] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "metadata": {}, 139 | "source": [ 140 | "#### ** (2b) Read from Hive **\n", 141 | "####Don't forget the configuration of Hive should be done by placing your hive-site.xml file in conf/." 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": null, 147 | "metadata": { 148 | "collapsed": false 149 | }, 150 | "outputs": [], 151 | "source": [ 152 | "sqlContext.sql(\"SHOW TABLES\").show()" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": {}, 158 | "source": [ 159 | "#### In this class, you will use *pixnet_user_log_1000* for further works" 160 | ] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "metadata": {}, 165 | "source": [ 166 | "#### Print the schema! What do we have?" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": null, 172 | "metadata": { 173 | "collapsed": false 174 | }, 175 | "outputs": [], 176 | "source": [ 177 | "sqlContext.sql(\"SELECT * FROM pixnet_user_log_1000\").printSchema()" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "metadata": {}, 183 | "source": [ 184 | "#### How many rows in *pixnet_user_log*" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": null, 190 | "metadata": { 191 | "collapsed": false 192 | }, 193 | "outputs": [], 194 | "source": [ 195 | "from datetime import datetime\n", 196 | "start_time = datetime.now()\n", 197 | "\n", 198 | "df2 = sqlContext.sql(\"SELECT * FROM pixnet_user_log_1000\")\n", 199 | "\n", 200 | "end_time = datetime.now()\n", 201 | "print df2.count()\n", 202 | "print('Duration: {}'.format(end_time - start_time))" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": null, 208 | "metadata": { 209 | "collapsed": false 210 | }, 211 | "outputs": [], 212 | "source": [ 213 | "df2.select('time').show(2)" 214 | ] 215 | }, 216 | { 217 | "cell_type": "markdown", 218 | "metadata": {}, 219 | "source": [ 220 | "##Part 3: User-Defined Functions" 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "metadata": {}, 226 | "source": [ 227 | "###In part 3, you will create your first UDF in Spark SQL with elegant lambda" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": null, 233 | "metadata": { 234 | "collapsed": true 235 | }, 236 | "outputs": [], 237 | "source": [ 238 | "#registers this RDD as a temporary table using the given name.\n", 239 | "df2.registerTempTable(\"people\")\n", 240 | "\n", 241 | "# Create an UDF for how long some text is\n", 242 | "# example from user guide, length function\n", 243 | "sqlContext.registerFunction(\"strLenPython\", lambda x: len(x)) \n", 244 | "\n", 245 | "# split function for parser\n", 246 | "sqlContext.registerFunction(\"strDate\", lambda x: x.split(\"T\")[0])\n", 247 | "\n", 248 | "# put udf with expected columns\n", 249 | "results = sqlContext.sql(\"SELECT author, \\\n", 250 | " strDate(time) AS dt, \\\n", 251 | " strLenPython(action) AS lenAct \\\n", 252 | " FROM people\")" 253 | ] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "execution_count": null, 258 | "metadata": { 259 | "collapsed": false 260 | }, 261 | "outputs": [], 262 | "source": [ 263 | "# print top 5 results\n", 264 | "results.show(5)" 265 | ] 266 | }, 267 | { 268 | "cell_type": "markdown", 269 | "metadata": {}, 270 | "source": [ 271 | "##Part 4: Caching for performance" 272 | ] 273 | }, 274 | { 275 | "cell_type": "markdown", 276 | "metadata": {}, 277 | "source": [ 278 | "#### ** Saving to persistent tables**\n", 279 | "#### `saveAsTable ` : Saves the contents of this DataFrame to a data source as a table." 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 19, 285 | "metadata": { 286 | "collapsed": true 287 | }, 288 | "outputs": [], 289 | "source": [ 290 | "sqlContext.cacheTable(\"people\")" 291 | ] 292 | }, 293 | { 294 | "cell_type": "code", 295 | "execution_count": null, 296 | "metadata": { 297 | "collapsed": false 298 | }, 299 | "outputs": [], 300 | "source": [ 301 | "start_time = datetime.now()\n", 302 | "\n", 303 | "sqlContext.sql(\"SELECT * FROM people\").count()\n", 304 | "\n", 305 | "end_time = datetime.now()\n", 306 | "print('Duration: {}'.format(end_time - start_time))" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": null, 312 | "metadata": { 313 | "collapsed": false 314 | }, 315 | "outputs": [], 316 | "source": [ 317 | "sqlContext.sql(\"SELECT strDate(time) AS dt,\\\n", 318 | " count(distinct author) AS cnt \\\n", 319 | " FROM people \\\n", 320 | " GROUP BY strDate(time)\").show(5)" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": null, 326 | "metadata": { 327 | "collapsed": false 328 | }, 329 | "outputs": [], 330 | "source": [ 331 | "sqlContext.uncacheTable(\"people\")" 332 | ] 333 | }, 334 | { 335 | "cell_type": "markdown", 336 | "metadata": {}, 337 | "source": [ 338 | "##Part 5: Your show time - How many authors are tagged as spam from pixnet_user_log?\n", 339 | "\n", 340 | "#### Here are two hive tables you will need:\n", 341 | "#### (1) author with action *pixnet_user_spam*\n", 342 | "#### (2) author with spam tag *pixnet_user_log_1000*" 343 | ] 344 | }, 345 | { 346 | "cell_type": "code", 347 | "execution_count": null, 348 | "metadata": { 349 | "collapsed": true 350 | }, 351 | "outputs": [], 352 | "source": [ 353 | "# TODO: Replace with appropriate code\n", 354 | "result = " 355 | ] 356 | }, 357 | { 358 | "cell_type": "markdown", 359 | "metadata": {}, 360 | "source": [ 361 | "### Don't forget to stop sc" 362 | ] 363 | }, 364 | { 365 | "cell_type": "code", 366 | "execution_count": 23, 367 | "metadata": { 368 | "collapsed": true 369 | }, 370 | "outputs": [], 371 | "source": [ 372 | "sc.stop()" 373 | ] 374 | } 375 | ], 376 | "metadata": { 377 | "kernelspec": { 378 | "display_name": "Python 2", 379 | "language": "python", 380 | "name": "python2" 381 | }, 382 | "language_info": { 383 | "codemirror_mode": { 384 | "name": "ipython", 385 | "version": 2 386 | }, 387 | "file_extension": ".py", 388 | "mimetype": "text/x-python", 389 | "name": "python", 390 | "nbconvert_exporter": "python", 391 | "pygments_lexer": "ipython2", 392 | "version": "2.7.9" 393 | } 394 | }, 395 | "nbformat": 4, 396 | "nbformat_minor": 0 397 | } 398 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------