Skip to content

Commit c78a0bc

Browse files
committed
3-4 files update
1 parent 81413cd commit c78a0bc

File tree

3 files changed

+151
-1
lines changed

3 files changed

+151
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,4 @@ venv.bak/
319319

320320
/extraction/
321321
/load/
322+
/test.py

Tester.ipynb

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"collapsed": true
7+
},
8+
"source": [
9+
"### Check outputs from Data Engineering Capstone Project for Udacity"
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"#### Read config"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"# import necessary configurations\n",
26+
"import configparser\n",
27+
"\n",
28+
"config = configparser.ConfigParser()\n",
29+
"config.read_file(open('dwh.cfg'))\n",
30+
"\n",
31+
"# amazon aws\n",
32+
"KEY = config.get('AWS', 'key')\n",
33+
"SECRET = config.get('AWS', 'secret')\n",
34+
"\n",
35+
"# Redshift\n",
36+
"DWH_DB = config.get('DWH', 'DWH_DB')\n",
37+
"DWH_DB_USER = config.get('DWH', 'DWH_DB_USER')\n",
38+
"DWH_DB_PASSWORD = config.get('DWH', 'DWH_DB_PASSWORD')\n",
39+
"DWH_PORT = config.get('DWH', 'DWH_PORT')\n",
40+
"DWH_CLUSTER_TYPE = config.get('DWH', 'DWH_CLUSTER_TYPE')\n",
41+
"DWH_NUM_NODES = config.get('DWH', 'DWH_NUM_NODES')\n",
42+
"DWH_NODE_TYPE = config.get('DWH', 'DWH_NODE_TYPE')\n",
43+
"DWH_IAM_ROLE_NAME = config.get('DWH', 'DWH_IAM_ROLE_NAME')\n",
44+
"DWH_CLUSTER_IDENTIFIER = config.get('DWH', 'DWH_CLUSTER_IDENTIFIER')\n",
45+
"DWH_SCHEMA = config.get('DWH', 'DWH_SCHEMA')\n",
46+
"DWH_LOG_STAGING_TABLE = config.get('DWH', 'DWH_LOG_STAGING_TABLE')\n",
47+
"DWH_SONG_STAGING_TABLE = config.get('DWH', 'DWH_SONG_STAGING_TABLE')\n",
48+
"DWH_REGION = config.get('DWH', 'DWH_REGION')\n",
49+
"\n",
50+
"# s3\n",
51+
"LOG_JSON_FORMAT = config.get('S3', 'LOG_JSON_FORMAT')\n",
52+
"S3_BUCKET_LOG_JSON_PATH = config.get('S3', 'S3_BUCKET_LOG_JSON_PATH')\n",
53+
"S3_BUCKET_SONG_JSON_PATH = config.get('S3', 'S3_BUCKET_SONG_JSON_PATH')"
54+
]
55+
},
56+
{
57+
"cell_type": "markdown",
58+
"metadata": {},
59+
"source": [
60+
"#### Create SQL Connection String"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": null,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"%load_ext sql"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"# save your DWH_ENDPOINT here:\n",
79+
"DWH_ROLE_ARN = '<fill_it_up_here>'\n",
80+
"DWH_ENDPOINT = '<fill_it_up_here>'"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": null,
86+
"metadata": {},
87+
"outputs": [],
88+
"source": [
89+
"# creating connection to your DB in Amazon Redshift\n",
90+
"conn_string=\"postgresql://{}:{}@{}:{}/{}\".format(DWH_DB_USER, DWH_DB_PASSWORD, DWH_ENDPOINT, DWH_PORT, DWH_DB)\n",
91+
"print(conn_string)\n",
92+
"%sql $conn_string"
93+
]
94+
},
95+
{
96+
"cell_type": "markdown",
97+
"metadata": {},
98+
"source": [
99+
"#### Get result from query"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": null,
105+
"metadata": {},
106+
"outputs": [],
107+
"source": [
108+
"import pandas as pd\n",
109+
"import numpy as np\n",
110+
"from sqlalchemy import create_engine\n",
111+
" \n",
112+
"test_query = \"\"\"\n",
113+
"\n",
114+
"\"\"\"\n",
115+
" \n",
116+
"redshift_engine = create_engine('redshift+psycopg2://username:password@your.redshift.host.123456abcdef.us-east-1.redshift.amazonaws.com:port/database')\n",
117+
"test = pd.read_sql_query(test_query, redshift_engine)"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"metadata": {},
124+
"outputs": [],
125+
"source": []
126+
}
127+
],
128+
"metadata": {
129+
"kernelspec": {
130+
"display_name": "Python 3",
131+
"language": "python",
132+
"name": "python3"
133+
},
134+
"language_info": {
135+
"codemirror_mode": {
136+
"name": "ipython",
137+
"version": 3
138+
},
139+
"file_extension": ".py",
140+
"mimetype": "text/x-python",
141+
"name": "python",
142+
"nbconvert_exporter": "python",
143+
"pygments_lexer": "ipython3",
144+
"version": "3.6.5"
145+
}
146+
},
147+
"nbformat": 4,
148+
"nbformat_minor": 1
149+
}

dwh.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ DWH_NODE_TYPE=dc2.large
99

1010
DWH_IAM_ROLE_NAME=
1111
DWH_CLUSTER_IDENTIFIER=
12-
DWH_DB=
12+
DWH_DB=udacity
1313
DWH_DB_USER=
1414
DWH_DB_PASSWORD=
1515
DWH_PORT=5439

0 commit comments

Comments
 (0)