json을 정보를 저장하는 테이블에 view를 생성해서 json없는 테이블처럼 사용할 수 있다. 

(더 정확히 말하면 general하게 로그 수집을 위한 모델링할 수 있는 로그에 json를 사용할 수 있으면서 

쉽게 정보를 파악할 수 있는 방법이다)




아래와 같은 row를 가진 hive 테이블이 있다. 


1787821114291 service 15 birthday {"result":true,"birth":"0224","id":"15","action":"add"}  2011-02-23


이런 hive테이블을 조회하려면 아래와 같이 실행해야 한다.


select * from googleplus_reqlog where date_id='2011-02-23' and label='birthday' and get_json_object(props, '$.id')='15';





hive 질의 시 get_json_object를 사용하는 것이 불편하기 때문에 새로운 view를 만든다.


CREATE VIEW `stat`.`birthday` COMMENT 'google plus birthday' AS SELECT

`birthday_temp`.`ts` AS `ts`,

`birthday_temp`.`date_id` AS `date_id`,

`birthday_temp`.`result` AS `result`,

`birthday_temp`.`birth` AS `birth`,

`birthday_temp`.`id` AS `id`,

`birthday_temp`.`action` AS `action`,

`birthday_temp`.`from` AS `from`

FROM (

  select

    ts,

    date_id,

    get_json_object(`googleplus_reqlog`.`props`, '$.result') as result,

    get_json_object(`googleplus_reqlog`.`props`, '$.birth') as birth,

    get_json_object(`googleplus_reqlog`.`props`, '$.id') as id,

    get_json_object(`googleplus_reqlog`.`props`, '$.action') as action,

  from `src`.`googleplus_reqlog`

  where label='birthday') `birthday_temp`;

  

  

  

view를 확인한다. 


hive> desc birthday;

OK

ts                   bigint

date_id             string

result               string

birth               string

id           string

action               string




이제 get_json_object 없이 간단하게 hive 질의를 할 수 있다. 

  

 select * from birthday where date_id='2011-02-23' and account_id='15';

  


처음에 소개한 hive 질의와 동일한 결과를 내지만, 훨씬 편하다.


select * from googleplus_reqlog where date_id='2011-02-23' and label='birthday' and get_json_object(props, '$.id')='15';



Posted by '김용환'
,


mysql의 경우 reserved word를 table의 컬럼명으로 쓰인다면 back quote(`)을 사용해야 한다.


https://dev.mysql.com/doc/refman/5.7/en/identifiers.html



The identifier quote character is the backtick (`):

mysql> SELECT * FROM `select` WHERE `select`.id > 100;




마찬가지로 hive에서도 reserved word를 table의 컬럼명으로 쓰인다면 back quote(`)을 사용해야 한다.



https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Select

 Any column name that is specified within backticks (`) is treated literally. 


hive> select * from googleplus_log where `date`='2037-08-23' and label='birthday' and `to`='11935385';

Posted by '김용환'
,


과거에는 netstat -anp을 이용해 특정 포트를 리스닝(Listen)하는 특정 프로세스를 찾았다.



$ netstat -anp | grep LISTEN


tcp        0      0 172.17.64.41:7077           0.0.0.0:*                   LISTEN      26464/java

tcp        0      0 0.0.0.0:51047               0.0.0.0:*                   LISTEN      13816/java

...



lsof에도 비슷한 옵션이 있다. 조금 더 깔끔하게 출력된다. 그리고 컬럼 크기도 정할 수 있어서 유용하다.



$ lsof +c10  -iTCP -sTCP:LISTEN


COMMAND      PID   USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME

java        1627 www   15u  IPv4 605880628      0t0  TCP *:41384 (LISTEN)

java        1627 www   30u  IPv4 605880676      0t0  TCP *:36194 (LISTEN)


Posted by '김용환'
,