Created
October 5, 2014 23:58
-
-
Save cjmatta/6249f0b939071536bd47 to your computer and use it in GitHub Desktop.
Title
This file contains hidden or 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
## test customer view | |
```SQL | |
select | |
cast(row_key as int) as row_key, | |
cast(`address`['state'] as VARCHAR(255)) as state, | |
cast(`loyalty`['agg_rev'] as VARCHAR(255)) as agg_rev, | |
cast(`loyalty`['membership'] as VARCHAR(255)) as membership, | |
cast(`personal`['name'] as VARCHAR(255)) as name, | |
cast(`personal`['age'] as VARCHAR(255)) as age, | |
cast(`personal`['gender'] as VARCHAR(255)) as gender | |
from `maprdb`.`customers` limit 10; | |
``` | |
## Create the customer view | |
```SQL | |
create or replace view mfs.views.custview as select | |
cast(row_key as int) as cust_id, | |
cast(`address`['state'] as VARCHAR(255)) as state, | |
cast(`loyalty`['agg_rev'] as VARCHAR(255)) as agg_rev, | |
cast(`loyalty`['membership'] as VARCHAR(255)) as membership, | |
cast(`personal`['name'] as VARCHAR(255)) as name, | |
cast(`personal`['age'] as VARCHAR(255)) as age, | |
cast(`personal`['gender'] as VARCHAR(255)) as gender | |
from `maprdb`.`customers`; | |
``` | |
## Look at Nested JSON | |
## test Nested JSON view | |
```SQL | |
SELECT | |
trans_id, | |
CAST(`date` as DATE) as `date`, | |
CAST(`time` as TIME) as `time`, | |
CAST(user_info['cust_id'] as INT) as cust_id, | |
CAST(user_info['device'] as VARCHAR(255)) as device_type, | |
CAST(user_info['state'] as VARCHAR(255)) as state, | |
CAST(ad_info['camp_id'] as VARCHAR(255)) as camp_id, | |
CAST(trans_info['prod_id'][0] as INT) as prod_id, | |
CAST(trans_info['purch_flag'] as VARCHAR(255)) as purch_flag | |
FROM `mfs`.`nested`.`./clicks/clicks.campaign.json` | |
limit 10; | |
``` | |
## Create the clickview | |
```SQL | |
create or replace view mfs.views.clickview as SELECT | |
trans_id, | |
CAST(`date` as DATE) as `date`, | |
CAST(`time` as TIME) as `time`, | |
CAST(user_info['cust_id'] as INT) as cust_id, | |
CAST(user_info['device'] as VARCHAR(255)) as device_type, | |
CAST(user_info['state'] as VARCHAR(255)) as state, | |
CAST(ad_info['camp_id'] as VARCHAR(255)) as camp_id, | |
CAST(trans_info['prod_id'][0] as INT) as prod_id, | |
CAST(trans_info['purch_flag'] as VARCHAR(255)) as purch_flag | |
FROM `mfs`.`nested`.`./clicks/clicks.campaign.json`; | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment