using JSON-SerDe in Hive tables

后端 未结 4 1320
被撕碎了的回忆
被撕碎了的回忆 2021-01-02 21:57

I\'m trying JSON-SerDe from below link http://code.google.com/p/hive-json-serde/wiki/GettingStarted.

         CREATE TABLE my_table (field1 string, field2          


        
4条回答
  •  感动是毒
    2021-01-02 22:05

    I solved similar problem -

    1. I took the jar from - [http://www.congiu.net/hive-json-serde/1.3.8/hdp23/json-serde-1.3.8-jar-with-dependencies.jar]

    2. Run the command in Hive CLI - add jar /path/to/jar

    3. Created table using -
    create table messages (
        id int,
        creation_date string,
        text string,
        loggedInUser STRUCT
    )
    row format serde "org.openx.data.jsonserde.JsonSerDe";
    
    1. This is my JSON data -
    {"id": 1,"creation_date": "2020-03-01","text": "I am on cotroller","loggedInUser":{"id":1,"name":"API"}}
    {"id": 2,"creation_date": "2020-04-01","text": "I am on service","loggedInUser":{"id":1,"name":"API"}}
    
    1. Loaded data in table using -
    LOAD DATA LOCAL INPATH '${env:HOME}/path-to-json'
    OVERWRITE INTO TABLE messages;
    
    1. select * from messages;
    1   2020-03-01    I am on cotroller   {"id":1,"name:"API"}
    2   2020-04-01    I am on service     {"id":1,"name:"API"}
    

提交回复
热议问题