Hive學習之路 多分隔符的使用

2021-09-27 02:17:17 字數 1723 閱讀 3161

通常情況下,我們建立的都是單分隔符的hive表,但是在實際業務環境中,多數情況下使用的是多分隔符,本篇文章我們**下hive多分隔的用法以及注意事項。

單分隔符示例:

create table hello(name string,code timestamp) 

row format delimited fields terminated by ','   

lines terminated by '\n'                        

stored as textfile;

說明:上述示例中採用「,」作為列分隔,「\n」作為行分隔。

多分隔符使用:

第一種:使用org.apache.hadoop.hive.contrib.serde2.multidelimitserde介面

create external table if not exists inform(

binglijlxh string ,

jilunr string

)comment '內容注釋'

row format serde 'org.apache.hadoop.hive.contrib.serde2.multidelimitserde'

with serdeproperties ('field.delim'='\001$^#g','line.delim'='\002h-q^v', 'serialization.format'='\001$^#g')

stored as textfile

location '/user/hive/temp';

說明:'\001$^#g','\002h-q^v','\001$^#g'表示多分隔符,其中\001,\002表示hive預設隱藏分隔符,是不可見字元,\001在vim裡面表示^a,\002表示^b。

\001          ^a ,需要按照ctrl+v+a打出,不是shift+^+b

\002          ^b,需要按照ctrl+v+b打出,不是shift+^+b

sed -e 's/|/\^a$^#g/g' data.txt

sed -i 's/|/\^a$^#g/g' data.txt      替換但分隔符「|」為多分隔符「\001$^#g」,^需要轉義

第二種:使用org.apache.hadoop.hive.contrib.serde2.regexserde介面(正則)

create external table inform(a string, b string)

row format serde 'org.apache.hadoop.hive.contrib.serde2.regexserde'

with serdeproperties ("input.regex" = "^(.*)\\$\\%\\#(.*)$")

location '/user/hive/temp';

分隔符使用不正確,會出現count數目不正確或者insert會插入到第乙個欄位中,其餘欄位中沒有資料。

hive實現多分隔符

一 測試外表 create external 外表標識 table tmp.deli tmp 0117 z1 string,z2 string partitioned by pt string comment yyyymm row format serde org.apache.hadoop.hiv...

awk linux 分隔 awk多分隔符

awk的 f引數可以指定新的分隔符,有些時候可能需求指定多個分隔符,比如下面的內容 root n1 netstat an grep estab udp 0 0 192.168.1.120 35570 212.47.249.141 123 established udp 0 0 192.168.1.1...

hive的列分隔符和行分隔符的使用

目錄 一 hive中預設的分割符如下 二 分隔符的指定與使用 三 建好表之後更改字段分隔符 分隔符描述 n 行分隔符 a欄位分隔符 001 barray struct的元素間的分隔符,map的鍵值對與鍵值對間分隔符 002 cmap中鍵與值之間的 分隔符 003 hive中在建立表時,一般會根據匯入...