Use rcfile in hive

Source: Internet
Author: User

(1) create student & student1 table: (hive managed)
Create Table student (ID int, age int, name string)
Partitioned by (stat_date string)
Clustered by (ID) sorted by (AGE) into 4 buckets
Row format delimited fields terminated ',';

Create Table studentrc (ID int, age int, name string)
Partitioned by (stat_date string)
Clustered by (ID) sorted by (AGE) into 4 buckets
Row format delimited fields terminated by ', 'stored as rcfile;

Create Table studentlzo (ID int, age int, name string)
Partitioned by (stat_date string)
Clustered by (ID) sorted by (AGE) into 4 buckets
Row format delimited fields terminated by ', 'stored as rcfile;

File Format: textfile, sequencefile, rcfile
(2) Set environment variables:
Set hive. Enforce. bucketing = true;
(3) Insert data:
Load data local inpath '/home/hadoop/hivetest1.txt' overwrite into Table student partition (stat_date = "20120802 ");


(High CPU usage)
From student
Insert overwrite table student1 partition (stat_date = "20120802 ")
Select ID, age, name where stat_date = "20120802" sort by age;

View data
Select ID, age, name from student distribute by ID; // distribute is equivalent to the key in mapreduce


Data extraction (usually used for testing)
Select * from student tablesample (bucket 1 out of 2 on ID );
Tablesample (bucket X out of Y)
X must be smaller than Y, and y must be a factor or multiple of the number of bucket on during table creation. Hive determines the sample size based on Y, for example, if the original score is 32 and Y = 16, 32/16 = 2 is extracted. tablesample (bucket 3 out of 16) this means that 3rd and 16th + 3 = 19 points are to be extracted. if y = 64, 32/64 = 1/2 pieces of data will be extracted. tablesample (bucket 3 out of 64) means that half of the 3rd pieces of data will be extracted.

Rcfile operation

// Import (gzip compression)
Set hive. Enforce. bucketing = true;
Set hive.exe C. Compress. Output = true;
Set mapred. Output. Compress = true;
Set mapred. Output. Compression. codec = org. Apache. hadoop. Io. Compress. gzipcodec;
Set Io. Compression. codecs = org. Apache. hadoop. Io. Compress. gzipcodec;
From student
Insert overwrite table studentrc partition (stat_date = "20120802 ")
Select ID, age, name where stat_date = "20120802" sort by age;


// Lzo Compression
Set hive. Io. rcfile. Record. Buffer. size = 16777216; // 16*1024*1024
Set Io. file. Buffer. size = 131072; // buffer size: 128*1024

Set hive. Enforce. bucketing = true;
Set hive.exe C. Compress. Output = true;
Set mapred. Output. Compress = true;
Set mapred. Output. Compression. codec = com. hadoop. Compression. lzo. lzocodec;
Set Io. Compression. codecs = com. hadoop. Compression. lzo. lzocodec;
From student
Insert overwrite table studentlzo partition (stat_date = "20120802 ")
Select ID, age, name where stat_date = "20120802" sort by age;

// Sequencefile Import
Set hive.exe C. Compress. Output = true;
Set mapred. Output. Compress = true;
Set mapred. Output. Compression. codec = org. Apache. hadoop. Io. Compress. gzipcodec;
Set Io. Compression. codecs = org. Apache. hadoop. Io. Compress. gzipcodec;
Insert overwrite table studentseq select * from student;

Use rcfile in hive

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.