Insert data into Hbase using Hive (JSON file)

前端 未结 1 1677
清歌不尽
清歌不尽 2020-12-18 17:16

I have already created a table in hbase using hive:

hive> CREATE TABLE hbase_table_emp(id int, name string, role string) 
STORED BY \'org.apache.hadoop.hi         


        
相关标签:
1条回答
  • 2020-12-18 17:47

    You can use the get_json_object function to parse the data as a JSON object. For instance, if you create a staging table with your JSON data:

    DROP TABLE IF EXISTS staging;
    CREATE TABLE staging (json STRING);
    LOAD DATA LOCAL INPATH '/local/path/to/jsonfile' INTO TABLE staging;
    

    Then use get_json_object to extract the attributes you want to load into the table:

    INSERT OVERWRITE TABLE hbase_table_emp SELECT
      get_json_object(json, "$.id") AS id,
      get_json_object(json, "$.name") AS name,
      get_json_object(json, "$.role") AS role
    FROM staging;
    

    There is more comprehensive discussion of this function here.

    0 讨论(0)
提交回复
热议问题