Hive Serde-csv, TSV

Source: Internet
Author: User

CSV

hive-0.14.0 built-insupport for CSV Serde, previous versions require the introduction of a third-party library of Jar packages (Http://https://github.com/ogrodnek/csv-serde)
Now there is a text file A.csv (the data exported from the database is usually this format), the contents are as follows:
  
 
  1. [[email protected] ~]$ more a.csv 
  2. ‘1‘,‘zhangsan‘,‘20‘,‘beijing,shanghai,shandong‘,1
  3. ‘2‘,‘lisi‘,‘22‘,‘guangdong,hainan‘,1
  4. ‘3‘,‘wangwu‘,‘23‘,‘shandong,jiangsu,xizang‘,0
now it needs to be loaded into hive for processing, in the following steps:

1) Introduction of third-party jar packages(versions prior to 0.14)
 
   
  
  1. add jar /xx/yy/zz.jar;
2) Create a table
  
 
  1. CREATE TABLE T_csv(IDint,namestring,Addressstring,Sex tinyint)row Format Serde' Org.apache.hadoop.hive.serde2.OpenCSVSerde ' withserdeproperties("Separatorchar"=",","QuoteChar"="'","Escapechar"= "\\")stored astextfile;
Separatorchar is the delimiter between fields
QuoteChar are symbols that include fields, such as single quotes, double quotes
Escapechar is a non-processed character
3) Load Data
 
   
  
  1. load data local inpath ‘${env:HOME}/a.csv‘ into table t_csv;
4) Query
 
   
  
  1. select name, address from t_csv;

TSV
Currently there is no dedicated TSV Serde jar package, but you can use the CSV Serde to set its separatorchar= ' \ t '



From for notes (Wiz)

Hive Serde-csv, TSV

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.