generated from databricks-industry-solutions/industry-solutions-blueprints
-
Notifications
You must be signed in to change notification settings - Fork 7
/
04b_policy_claims_accident_iot.sql
65 lines (53 loc) · 1.63 KB
/
04b_policy_claims_accident_iot.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
-- Databricks notebook source
-- MAGIC %md This notebook is available at https://github.com/databricks-industry-solutions/smart-claims
-- COMMAND ----------
-- MAGIC %md
-- MAGIC # Add telematics and accident data to the claims & policy data
-- MAGIC * simulate iot streaming data join with claims
-- COMMAND ----------
-- MAGIC %run ./setup/initialize
-- COMMAND ----------
-- create table if not exists silver_claim_policy_accident as
-- (
-- select p_c.*, t.* except(t.claim_no, t.chassis_no)
-- from
-- silver_claim_policy_location as p_c
-- join
-- silver_accident as t
-- on p_c.claim_no=t.claim_no
-- )
-- COMMAND ----------
create table if not exists silver_claim_policy_telematics_avg as
(
select p_c.*, t.telematics_latitude, t.telematics_longitude, t.telematics_speed
from
silver_claim_policy_location as p_c
join
(select chassis_no, avg(speed) as telematics_speed,
avg(latitude) as telematics_latitude,
avg(longitude) as telematics_longitude
from
silver_telematics
group by chassis_no) t
on p_c.chassis_no=t.chassis_no
)
-- COMMAND ----------
-- create table if not exists silver_claim_policy_accident as
-- (
-- select p_c.*, t.* except(t.claim_no, t.chassis_no)
-- from
-- silver_claim_policy_telematics_avg as p_c
-- join
-- silver_accident as t
-- on p_c.claim_no=t.claim_no
-- )
-- COMMAND ----------
create table if not exists silver_claim_policy_telematics as
(
select p_c.*, t.latitude as telematics_latitude, t.longitude as telematics_longitude, t.event_timestamp as telematics_timestamp, t.speed as telematics_speed
from
silver_telematics as t
join
silver_claim_policy_location as p_c
on p_c.chassis_no=t.chassis_no
)