Inserting Data into Hive Table

后端 未结 11 1146
失恋的感觉
失恋的感觉 2020-12-14 17:01

I am new to hive. I have successfully setup a single node hadoop cluster for development purpose and on top of it, I have installed hive and pig.

I created a dummy t

相关标签:
11条回答
  • 2020-12-14 17:21

    You can use following lines of code to insert values into an already existing table. Here the table is db_name.table_name having two columns, and I am inserting 'All','done' as a row in the table.

    insert into table db_name.table_name
    select 'ALL','Done';
    

    Hope this was helpful.

    0 讨论(0)
  • 2020-12-14 17:33

    Use this -

    create table dummy_table_name as select * from source_table_name;
    

    This will create the new table with existing data available on source_table_name.

    0 讨论(0)
  • 2020-12-14 17:38

    It's a limitation of hive.

    1.You cannot update data after it is inserted

    2.There is no "insert into table values ... " statement

    3.You can only load data using bulk load

    4.There is not "delete from " command

    5.You can only do bulk delete

    But you still want to insert record from hive console than you can do select from statck. refer this

    0 讨论(0)
  • 2020-12-14 17:39

    You may try this, I have developed a tool to generate hive scripts from a csv file. Following are few examples on how files are generated. Tool -- https://sourceforge.net/projects/csvtohive/?source=directory

    1. Select a CSV file using Browse and set hadoop root directory ex: /user/bigdataproject/

    2. Tool Generates Hadoop script with all csv files and following is a sample of generated Hadoop script to insert csv into Hadoop

      #!/bin/bash -v
      hadoop fs -put ./AllstarFull.csv /user/bigdataproject/AllstarFull.csv hive -f ./AllstarFull.hive

      hadoop fs -put ./Appearances.csv /user/bigdataproject/Appearances.csv hive -f ./Appearances.hive

      hadoop fs -put ./AwardsManagers.csv /user/bigdataproject/AwardsManagers.csv hive -f ./AwardsManagers.hive

    3. Sample of generated Hive scripts

      CREATE DATABASE IF NOT EXISTS lahman;
      USE lahman;
      CREATE TABLE AllstarFull (playerID string,yearID string,gameNum string,gameID string,teamID string,lgID string,GP string,startingPos string) row format delimited fields terminated by ',' stored as textfile;
      LOAD DATA INPATH '/user/bigdataproject/AllstarFull.csv' OVERWRITE INTO TABLE AllstarFull;
      SELECT * FROM AllstarFull;

    Thanks Vijay

    0 讨论(0)
  • 2020-12-14 17:42

    to insert ad-hoc value like (12,"xyz), do this:

    insert into table foo select * from (select 12,"xyz")a;
    
    0 讨论(0)
提交回复
热议问题