Inserting Data into Hive Table

后端 未结 11 1145
失恋的感觉
失恋的感觉 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:17

    this is supported from version hive 0.14

    INSERT INTO TABLE pd_temp(dept,make,cost,id,asmb_city,asmb_ct,retail) VALUES('production','thailand',10,99202,'northcarolina','usa',20)

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

    Hadoop file system does not support appending data to the existing files. Although, you can load your CSV file into HDFS and tell Hive to treat it as an external table.

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

    I think the best way is:
    a) Copy data into HDFS (if it is not already there)
    b) Create external table over your CSV like this

    CREATE EXTERNAL TABLE TableName (id int, name string)
    ROW FORMAT DELIMITED   
    FIELDS TERMINATED BY ',' 
    LINES TERMINATED BY '\n'
    STORED AS TEXTFILE
    LOCATION 'place in HDFS';
    

    c) You can start using TableName already by issuing queries to it.
    d) if you want to insert data into other Hive table:

    insert overwrite table finalTable select * from table name;
    
    0 讨论(0)
  • 2020-12-14 17:19

    Hive apparently supports INSERT...VALUES starting in Hive 0.14.

    Please see the section 'Inserting into tables from SQL' at: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML

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

    What ever data you have inserted into one text file or log file that can put on one path in hdfs and then write a query as follows in hive

      hive>load data inpath<<specify inputpath>> into table <<tablename>>;
    

    EXAMPLE:

    hive>create table foo (id int, name string)
    row format delimited
    fields terminated by '\t' or '|'or ','
    stored as text file;
    table created..
        DATA INSERTION::
        hive>load data inpath '/home/hive/foodata.log' into table foo;
    
    0 讨论(0)
  • 2020-12-14 17:21

    There's no direct way to insert 1 record at a time from the terminal, however, here's an easy straight forward workaround which I usually use when I want to test something:

    Assuming that t is a table with at least 1 record. It doesn't matter what is the type or number of columns.

    INSERT INTO TABLE foo
    SELECT '12', 'xyz'
    FROM t
    LIMIT 1;
    
    0 讨论(0)
提交回复
热议问题