-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spark-Tables.sql
76 lines (58 loc) · 1.91 KB
/
Spark-Tables.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
-- Databricks notebook source
drop table if exists demo_db1.fire_service_calls_tbl;
drop view if exists demo_db1;
-- COMMAND ----------
-- MAGIC %fs rm -r dbfs:/user/hive/warehouse/demo_db1.db
-- COMMAND ----------
CREATE DATABASE IF NOT EXISTS demo_db1
-- COMMAND ----------
CREATE TABLE IF NOT EXISTS demo_db1.fire_service_calls_tbl(
CallNumber integer,
UnitID string,
IncidentNumber integer,
CallType string,
CallDate string,
WatchDate string,
CallFinalDisposition string,
AvailableDtTm string,
Address string,
City string,
Zipcode integer,
Battalion string,
StationArea string,
Box string,
OriginalPriority string,
Priority string,
FinalPriority integer,
ALSUnit boolean,
CallTypeGroup string,
NumAlarms integer,
UnitType string,
UnitSequenceInCallDispatch integer,
FirePreventionDistrict string,
SupervisorDistrict string,
Neighborhood string,
Location string,
RowID string,
Delay float
) USING parquet
-- COMMAND ----------
insert into demo_db1.fire_service_calls_tbl values(1234, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)
-- COMMAND ----------
truncate table demo_db1.fire_service_calls_tbl
-- COMMAND ----------
-- MAGIC %python
-- MAGIC fire_df = spark.read\
-- MAGIC .format("csv")\
-- MAGIC .option("header","true")\
-- MAGIC .option("inferSchema","true")\
-- MAGIC .load("/databricks-datasets/learning-spark-v2/sf-fire/sf-fire-calls.csv")
-- COMMAND ----------
-- MAGIC %python
-- MAGIC fire_df.createGlobalTempView("fireview") #converts dataframe to table view
-- COMMAND ----------
-- we do not use insert command in big data world either data is loaded from files or from another tables
insert into demo_db1.fire_service_calls_tbl
select * from global_temp.fireview
-- COMMAND ----------
select * from demo_db1.fire_service_calls_tbl