Last active
July 30, 2020 12:50
-
-
Save ragingbal/85f615a70249bd452680 to your computer and use it in GitHub Desktop.
This file contains 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
import sys | |
import json | |
''' | |
Base data of the user. | |
CREATE TABLE imp_base (person_id string,name string,first_name string,last_name string,username string,country_code string,age string,email string,gender string,birthday string) | |
add file /vagrant/base_data.py ; | |
INSERT OVERWRITE TABLE imp_base SELECT TRANSFORM(lines) USING 'python base_data.py' AS (person_id,name,first_name,last_name,username,country_code,age,email,gender,birthday) FROM u_data; | |
select * from imp_base limit 100 ; | |
''' | |
#f = open("people.json",'r') | |
#for line in f: | |
for line in sys.stdin: | |
line = line.strip() | |
t = json.loads(line) | |
person_id = str(t.get('person_id')) | |
person_id = unicode(person_id) | |
name = str(t.get('name').encode('utf8')) | |
first_name = 'NA' if t.get('first_name') == None else str(t.get('first_name').encode('utf8')) | |
last_name = 'NA' if t.get('last_name') == None else str(t.get('last_name')) | |
username = 'NA' if t.get('username') == None else str(t.get('username')) | |
country_code = 'NA' if t.get('country_code') == None else str(t.get('country_code')) | |
age = 'NA' if t.get('age') == None else str(t.get('age')) | |
email = 'NA' if t.get('email') == None else t.get('email') | |
gender = 'NA' if t.get('gender') == None else t.get('gender') | |
birthday ='NA' if t.get('birthday') == None else str(t.get('birthday')) | |
print ('\t'.join([person_id.encode('utf8'),name,first_name,last_name,username,country_code,age,email,gender,birthday])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment