How to load a text file into a Hive table stored as sequence files

前端 未结 3 1596
忘掉有多难
忘掉有多难 2021-01-30 11:11

I have a hive table stored as a sequencefile.

I need to load a text file into this table. How do I load the data into this table?

3条回答
  •  遇见更好的自我
    2021-01-30 11:50

    You cannot directly create a table stored as a sequence file and insert text into it. You must do this:

    1. Create a table stored as text
    2. Insert the text file into the text table
    3. Do a CTAS to create the table stored as a sequence file.
    4. Drop the text table if desired

    Example:

    CREATE TABLE test_txt(field1 int, field2 string)
    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
    
    LOAD DATA INPATH '/path/to/file.tsv' INTO TABLE test_txt;
    
    CREATE TABLE test STORED AS SEQUENCEFILE
    AS SELECT * FROM test_txt;
    
    DROP TABLE test_txt;
    

提交回复
热议问题