Hive的列分隔符和行分隔符

2021-10-04 23:04:03 字數 2528 閱讀 8315

在建立hive表時,預設行分隔符"^a",列分隔符"\n",這兩項也是可以設定的。在實際開發中,一般預設使用預設的分隔符,當然有些場景下也會自定義分隔符。

spark-hive

use test_db;

# 建立外部表

create external table test_tb (

user_id bigint comment '使用者id',

user_name string comment '使用者名稱'

)location '/home/test_db/test_tb'

;

show create table test_tb;

20/04/13 11:47:49 info sparkhiveshell: current sql: show create table test_tb

create external table `test_tb`(

`user_id` bigint comment '使用者id',

`user_name` string comment '使用者名稱')

row format serde

'org.apache.hadoop.hive.serde2.lazy.lazy******serde' # 預設分隔符,行分割符:"\n",列分割符:"^a"

stored as inputformat

'org.apache.hadoop.mapred.textinputformat' # 預設儲存格式textfile

outputformat

'org.apache.hadoop.hive.ql.io.hiveignorekeytextoutputformat' # hdfs儲存目錄

location

'hdfs:'

tblproperties (

'transient_lastddltime'='1586749208')

time taken: 1.702 s

create external table test_tb_2 (

user_id bigint comment '使用者id',

user_name string comment '使用者名稱'

)row format delimited fields terminated by '\t'

lines terminated by '\n'

location '/home/test_db/test_tb_2'

;

show create table test_tb_2;

20/04/13 11:55:22 info sparkhiveshell: current sql: show create table test_tb_2

create external table `test_tb_2`(

`user_id` bigint comment '使用者id',

`user_name` string comment '使用者名稱')

row format delimited

fields terminated by '\t' # 列分割符,表2的列分割符為:"\t"

lines terminated by '\n' # 行分割符,表2的行分隔符為:"\n"

stored as inputformat

'org.apache.hadoop.mapred.textinputformat'

outputformat

'org.apache.hadoop.hive.ql.io.hiveignorekeytextoutputformat'

location

'hdfs:_2'

tblproperties (

'transient_lastddltime'='1586749805')

time taken: 2.485 s

從如上兩個例子中可以看出:hive預設的列分隔符型別為「org.apache.hadoop.hive.serde2.lazy.lazy******serde」。

hive中預設的列分割符為:"^a"(ctrl+v,ctrl+a),在資料檔案中為:"1^ajom\n",如果需要自定義分隔符,需要設定 "row format delimited fields terminated by '\t'",因為^a八進位制編碼為「\001」,如果使用預設的分隔符,可以不加此引數。

hive中預設行分隔符為"\n",也可以通過"lines terminated by '\n' "來設定。

一般來說hive預設行分隔符為換行符,如果非要自定義分隔符,可以通過定義inputformat和outputformat類來指定特定的(行|列)分隔符。

使用時需要注意:資料中如果包含:"\001","\n"等分隔符,需要提前處理掉。正常在hql中我們需要regexp_replace(字段,'\r|\n|\r\n|\001|\002|\003|\t', '')把常用的分隔符轉移掉,免得帶來串列,斷行的困擾。

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

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

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...

Sqoop匯入hive分隔符問題

sqoop從oracle匯入資料到hive,示例 plain view plain copy sqoop import connect jdbc oracle thin oracle host port orcl username name password passwd hive import t...