Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {
  7. "scrolled": false
  8. },
  9. "outputs": [],
  10. "source": [
  11. "import pyspark\n",
  12. "from pyspark import SparkContext, SQLContext, SparkConf\n",
  13. "\n",
  14. "from pyspark.sql.functions import udf, col\n",
  15. "from pyspark.sql.types import FloatType\n",
  16. "\n",
  17. "import os\n",
  18. "\n",
  19. "\n",
  20. "os.environ['SPARK_HOME'] = \"/home/jlaura/bigdata/spark-2.1.1-bin-hadoop2.7\"\n",
  21. "os.environ['SPARK_CONF_DIR'] = \"/tmp/spark/j_spark/749078/conf/\" # This is a per job variable\n",
  22. "\n",
  23. "conf = SparkConf()\\\n",
  24. " .setMaster('spark://neb1:7077')\\\n",
  25. " .setAppName(\"KelvinJobs\")\\\n",
  26. " .set(\"spark.cores.max\", 20)\n",
  27. "sc = SparkContext(conf=conf)\n",
  28. "sqlContext = SQLContext(sc)"
  29. ]
  30. },
  31. {
  32. "cell_type": "code",
  33. "execution_count": 7,
  34. "metadata": {
  35. "collapsed": true,
  36. "scrolled": false
  37. },
  38. "outputs": [],
  39. "source": [
  40. "# df = sqlContext.read.format(\"jdbc\").options(url=\"jdbc:postgresql://172.16.3.181:31180/tes?user=postgres&password=pass\", dbtable=\"tiy25\",driver=\"org.postgresql.Driver\").load()"
  41. ]
  42. },
  43. {
  44. "cell_type": "code",
  45. "execution_count": 2,
  46. "metadata": {},
  47. "outputs": [],
  48. "source": [
  49. "properties = {\n",
  50. " \"driver\": \"org.postgresql.Driver\",\n",
  51. " \"user\": \"postgres\",\n",
  52. " \"password\" : \"pass\"\n",
  53. "}\n",
  54. "url = 'jdbc:postgresql://dcos-node1:31180/tes'\n",
  55. "df = sqlContext.read.jdbc(url=url, table='global_y25', properties=properties)"
  56. ]
  57. },
  58. {
  59. "cell_type": "code",
  60. "execution_count": 3,
  61. "metadata": {},
  62. "outputs": [
  63. {
  64. "data": {
  65. "text/plain": [
  66. "[Row(ti=0.0, long_idx=1, lat_idx=1, lsubs_idx=75),\n",
  67. " Row(ti=0.0, long_idx=1, lat_idx=1, lsubs_idx=76),\n",
  68. " Row(ti=0.3888888888888889, long_idx=1, lat_idx=2, lsubs_idx=43),\n",
  69. " Row(ti=0.06666666666666667, long_idx=1, lat_idx=2, lsubs_idx=44),\n",
  70. " Row(ti=0.6111111111111112, long_idx=1, lat_idx=2, lsubs_idx=60)]"
  71. ]
  72. },
  73. "execution_count": 3,
  74. "metadata": {},
  75. "output_type": "execute_result"
  76. }
  77. ],
  78. "source": [
  79. "df.head(5)"
  80. ]
  81. },
  82. {
  83. "cell_type": "code",
  84. "execution_count": 5,
  85. "metadata": {
  86. "collapsed": true
  87. },
  88. "outputs": [],
  89. "source": [
  90. "sc.stop()"
  91. ]
  92. },
  93. {
  94. "cell_type": "code",
  95. "execution_count": null,
  96. "metadata": {
  97. "collapsed": true
  98. },
  99. "outputs": [],
  100. "source": []
  101. }
  102. ],
  103. "metadata": {
  104. "kernelspec": {
  105. "display_name": "Python 3",
  106. "language": "python",
  107. "name": "python3"
  108. },
  109. "language_info": {
  110. "codemirror_mode": {
  111. "name": "ipython",
  112. "version": 3
  113. },
  114. "file_extension": ".py",
  115. "mimetype": "text/x-python",
  116. "name": "python",
  117. "nbconvert_exporter": "python",
  118. "pygments_lexer": "ipython3",
  119. "version": "3.5.3"
  120. }
  121. },
  122. "nbformat": 4,
  123. "nbformat_minor": 2
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement