Skip to content

Commit 01cc4ee

Browse files
Adding the create and delete database in the notebook
1 parent 87d6396 commit 01cc4ee

File tree

2 files changed

+363
-332
lines changed

2 files changed

+363
-332
lines changed

tutorials/005 - Glue Catalog.ipynb

Lines changed: 74 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
"metadata": {},
3737
"outputs": [
3838
{
39-
"name": "stdin",
39+
"name": "stdout",
4040
"output_type": "stream",
4141
"text": [
42-
" ··········································\n"
42+
"········\n"
4343
]
4444
}
4545
],
@@ -192,77 +192,62 @@
192192
"metadata": {},
193193
"outputs": [
194194
{
195-
"data": {
196-
"text/html": [
197-
"<div>\n",
198-
"<style scoped>\n",
199-
" .dataframe tbody tr th:only-of-type {\n",
200-
" vertical-align: middle;\n",
201-
" }\n",
202-
"\n",
203-
" .dataframe tbody tr th {\n",
204-
" vertical-align: top;\n",
205-
" }\n",
206-
"\n",
207-
" .dataframe thead th {\n",
208-
" text-align: right;\n",
209-
" }\n",
210-
"</style>\n",
211-
"<table border=\"1\" class=\"dataframe\">\n",
212-
" <thead>\n",
213-
" <tr style=\"text-align: right;\">\n",
214-
" <th></th>\n",
215-
" <th>Database</th>\n",
216-
" <th>Description</th>\n",
217-
" </tr>\n",
218-
" </thead>\n",
219-
" <tbody>\n",
220-
" <tr>\n",
221-
" <th>0</th>\n",
222-
" <td>awswrangler_test</td>\n",
223-
" <td>AWS Data Wrangler Test Arena - Glue Database</td>\n",
224-
" </tr>\n",
225-
" <tr>\n",
226-
" <th>1</th>\n",
227-
" <td>default</td>\n",
228-
" <td>Default Hive database</td>\n",
229-
" </tr>\n",
230-
" <tr>\n",
231-
" <th>2</th>\n",
232-
" <td>sampledb</td>\n",
233-
" <td>Sample database</td>\n",
234-
" </tr>\n",
235-
" </tbody>\n",
236-
"</table>\n",
237-
"</div>"
238-
],
239-
"text/plain": [
240-
" Database Description\n",
241-
"0 awswrangler_test AWS Data Wrangler Test Arena - Glue Database\n",
242-
"1 default Default Hive database\n",
243-
"2 sampledb Sample database"
244-
]
245-
},
246-
"execution_count": 4,
247-
"metadata": {},
248-
"output_type": "execute_result"
195+
"name": "stdout",
196+
"output_type": "stream",
197+
"text": [
198+
" Database Description\n",
199+
"0 aws_data_wrangler AWS Data Wrangler Test Arena - Glue Database\n",
200+
"1 default Default Hive database\n"
201+
]
249202
}
250203
],
251204
"source": [
252-
"wr.catalog.databases()"
205+
"databases = wr.catalog.databases()\n",
206+
"print(databases)"
253207
]
254208
},
255209
{
256210
"cell_type": "markdown",
257211
"metadata": {},
258212
"source": [
259-
"## Checking the empty database"
213+
"### Create the database awswrangler_test if not exists"
260214
]
261215
},
262216
{
263217
"cell_type": "code",
264218
"execution_count": 5,
265219
"metadata": {},
220+
"outputs": [
221+
{
222+
"name": "stdout",
223+
"output_type": "stream",
224+
"text": [
225+
" Database Description\n",
226+
"0 aws_data_wrangler AWS Data Wrangler Test Arena - Glue Database\n",
227+
"1 awswrangler_test \n",
228+
"2 default Default Hive database\n"
229+
]
230+
}
231+
],
232+
"source": [
233+
"if \"awswrangler_test\" not in databases.values:\n",
234+
" wr.catalog.create_database(\"awswrangler_test\")\n",
235+
" print(wr.catalog.databases())\n",
236+
"else:\n",
237+
" print(\"Database awswrangler_test already exists\")"
238+
]
239+
},
240+
{
241+
"cell_type": "markdown",
242+
"metadata": {},
243+
"source": [
244+
"## Checking the empty database"
245+
]
246+
},
247+
{
248+
"cell_type": "code",
249+
"execution_count": 6,
250+
"metadata": {},
266251
"outputs": [
267252
{
268253
"data": {
@@ -293,37 +278,17 @@
293278
" </tr>\n",
294279
" </thead>\n",
295280
" <tbody>\n",
296-
" <tr>\n",
297-
" <th>0</th>\n",
298-
" <td>awswrangler_test</td>\n",
299-
" <td>lambda</td>\n",
300-
" <td></td>\n",
301-
" <td>col1, col2</td>\n",
302-
" <td></td>\n",
303-
" </tr>\n",
304-
" <tr>\n",
305-
" <th>1</th>\n",
306-
" <td>awswrangler_test</td>\n",
307-
" <td>noaa</td>\n",
308-
" <td></td>\n",
309-
" <td>id, dt, element, value, m_flag, q_flag, s_flag...</td>\n",
310-
" <td></td>\n",
311-
" </tr>\n",
312281
" </tbody>\n",
313282
"</table>\n",
314283
"</div>"
315284
],
316285
"text/plain": [
317-
" Database Table Description \\\n",
318-
"0 awswrangler_test lambda \n",
319-
"1 awswrangler_test noaa \n",
320-
"\n",
321-
" Columns Partitions \n",
322-
"0 col1, col2 \n",
323-
"1 id, dt, element, value, m_flag, q_flag, s_flag... "
286+
"Empty DataFrame\n",
287+
"Columns: [Database, Table, Description, Columns, Partitions]\n",
288+
"Index: []"
324289
]
325290
},
326-
"execution_count": 5,
291+
"execution_count": 6,
327292
"metadata": {},
328293
"output_type": "execute_result"
329294
}
@@ -341,7 +306,7 @@
341306
},
342307
{
343308
"cell_type": "code",
344-
"execution_count": 6,
309+
"execution_count": 7,
345310
"metadata": {},
346311
"outputs": [],
347312
"source": [
@@ -408,7 +373,7 @@
408373
},
409374
{
410375
"cell_type": "code",
411-
"execution_count": 7,
376+
"execution_count": 8,
412377
"metadata": {},
413378
"outputs": [
414379
{
@@ -463,7 +428,7 @@
463428
"0 crim, zn, indus, chas, nox, rm, age, dis, rad,... "
464429
]
465430
},
466-
"execution_count": 7,
431+
"execution_count": 8,
467432
"metadata": {},
468433
"output_type": "execute_result"
469434
}
@@ -474,7 +439,7 @@
474439
},
475440
{
476441
"cell_type": "code",
477-
"execution_count": 8,
442+
"execution_count": 9,
478443
"metadata": {},
479444
"outputs": [
480445
{
@@ -529,7 +494,7 @@
529494
"0 crim, zn, indus, chas, nox, rm, age, dis, rad,... "
530495
]
531496
},
532-
"execution_count": 8,
497+
"execution_count": 9,
533498
"metadata": {},
534499
"output_type": "execute_result"
535500
}
@@ -540,7 +505,7 @@
540505
},
541506
{
542507
"cell_type": "code",
543-
"execution_count": 9,
508+
"execution_count": 10,
544509
"metadata": {},
545510
"outputs": [
546511
{
@@ -595,7 +560,7 @@
595560
"0 crim, zn, indus, chas, nox, rm, age, dis, rad,... "
596561
]
597562
},
598-
"execution_count": 9,
563+
"execution_count": 10,
599564
"metadata": {},
600565
"output_type": "execute_result"
601566
}
@@ -606,7 +571,7 @@
606571
},
607572
{
608573
"cell_type": "code",
609-
"execution_count": 10,
574+
"execution_count": 11,
610575
"metadata": {},
611576
"outputs": [
612577
{
@@ -661,7 +626,7 @@
661626
"0 crim, zn, indus, chas, nox, rm, age, dis, rad,... "
662627
]
663628
},
664-
"execution_count": 10,
629+
"execution_count": 11,
665630
"metadata": {},
666631
"output_type": "execute_result"
667632
}
@@ -679,7 +644,7 @@
679644
},
680645
{
681646
"cell_type": "code",
682-
"execution_count": 11,
647+
"execution_count": 12,
683648
"metadata": {},
684649
"outputs": [
685650
{
@@ -846,7 +811,7 @@
846811
"13 "
847812
]
848813
},
849-
"execution_count": 11,
814+
"execution_count": 12,
850815
"metadata": {},
851816
"output_type": "execute_result"
852817
}
@@ -864,27 +829,36 @@
864829
},
865830
{
866831
"cell_type": "code",
867-
"execution_count": 12,
832+
"execution_count": 13,
868833
"metadata": {},
869834
"outputs": [],
870835
"source": [
871836
"for table in wr.catalog.get_tables(database=\"awswrangler_test\"):\n",
872837
" wr.catalog.delete_table_if_exists(database=\"awswrangler_test\", table=table[\"Name\"])"
873838
]
874839
},
840+
{
841+
"cell_type": "markdown",
842+
"metadata": {},
843+
"source": [
844+
"### Delete Database"
845+
]
846+
},
875847
{
876848
"cell_type": "code",
877-
"execution_count": null,
849+
"execution_count": 14,
878850
"metadata": {},
879851
"outputs": [],
880-
"source": []
852+
"source": [
853+
"wr.catalog.delete_database('awswrangler_test')"
854+
]
881855
}
882856
],
883857
"metadata": {
884858
"kernelspec": {
885-
"display_name": "conda_python3",
859+
"display_name": "Python 3",
886860
"language": "python",
887-
"name": "conda_python3"
861+
"name": "python3"
888862
},
889863
"language_info": {
890864
"codemirror_mode": {
@@ -896,9 +870,9 @@
896870
"name": "python",
897871
"nbconvert_exporter": "python",
898872
"pygments_lexer": "ipython3",
899-
"version": "3.6.5"
873+
"version": "3.7.7"
900874
}
901875
},
902876
"nbformat": 4,
903877
"nbformat_minor": 4
904-
}
878+
}

0 commit comments

Comments
 (0)