Last active
June 30, 2017 17:40
-
-
Save Kelvinrr/ec721f9843af75845b913789041bfb43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"scrolled": false | |
}, | |
"outputs": [], | |
"source": [ | |
"import pyspark\n", | |
"from pyspark import SparkContext, SQLContext, SparkConf\n", | |
"\n", | |
"from pyspark.sql.functions import udf, col\n", | |
"from pyspark.sql.types import FloatType\n", | |
"\n", | |
"import os\n", | |
"\n", | |
"\n", | |
"os.environ['SPARK_HOME'] = \"/home/jlaura/bigdata/spark-2.1.1-bin-hadoop2.7\"\n", | |
"os.environ['SPARK_CONF_DIR'] = \"/tmp/spark/j_spark/749078/conf/\" # This is a per job variable\n", | |
"\n", | |
"conf = SparkConf()\\\n", | |
" .setMaster('spark://neb1:7077')\\\n", | |
" .setAppName(\"KelvinJobs\")\\\n", | |
" .set(\"spark.cores.max\", 20)\n", | |
"sc = SparkContext(conf=conf)\n", | |
"sqlContext = SQLContext(sc)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": true, | |
"scrolled": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# 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()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"properties = {\n", | |
" \"driver\": \"org.postgresql.Driver\",\n", | |
" \"user\": \"postgres\",\n", | |
" \"password\" : \"pass\"\n", | |
"}\n", | |
"url = 'jdbc:postgresql://dcos-node1:31180/tes'\n", | |
"df = sqlContext.read.jdbc(url=url, table='global_y25', properties=properties)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[Row(ti=0.0, long_idx=1, lat_idx=1, lsubs_idx=75),\n", | |
" Row(ti=0.0, long_idx=1, lat_idx=1, lsubs_idx=76),\n", | |
" Row(ti=0.3888888888888889, long_idx=1, lat_idx=2, lsubs_idx=43),\n", | |
" Row(ti=0.06666666666666667, long_idx=1, lat_idx=2, lsubs_idx=44),\n", | |
" Row(ti=0.6111111111111112, long_idx=1, lat_idx=2, lsubs_idx=60)]" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"df.head(5)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"sc.stop()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment