Hive 建表 插入資料 插入復合型別

2021-09-06 21:37:42 字數 1477 閱讀 4127

新建hive表:

create

table

`test`

(`a`

timestamp

,`b` struct>

)--下面可選

[row format delimited fields

terminated

by'\t'

][stored as parquet]

檢視建好的表的結構:

hive>

show

create

table test;

okcreate

table

`test`

(`a`

timestamp

,`b` struct>

)row format serde

'org.apache.hadoop.hive.serde2.lazy.lazy******serde'

stored as inputformat

'org.apache.hadoop.mapred.textinputformat'

outputformat

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

location

tblproperties (

'column_stats_accurate'=''

,'numfiles'

='2'

,'numrows'

='2'

,'rawdatasize'

='78'

,'totalsize'

='80'

,'transient_lastddltime'

='1532416983'

)time taken: 0.189 seconds, fetched: 18

row(s)

插入資料:

hive 不支援直接用insert插入復合型別(如test表中struct型別列),可以用以下方式間接插入

insert

into test

select unix_timestamp(

'1970-01-01 08:00:00'),

named_struct(

't', cast(unix_timestamp(

'1970-01-01 08:00:00')as

timestamp))

-- named_struct是生成struct型別的函式

from tmp_table limit

1;

補充:

hive表資料檔案如果是parquet型別,struct復合型別裡的型別為timestamp的列在訪問時候,時區換算會出錯,所以可以用varchar型別代替timestamp。

hive 建庫建表插入資料

hive 建庫建表插入資料 先上傳檔案 sftp put users chenxin downloads hql50 hql50 score.txt root data hql50 sftp put users chenxin downloads hql50 hql50 teacher.txt ro...

oracle insert all 復合表插入

insert all 復合表插入 是將乙個查詢結果同時插入多個表中的功能。使用insert all的好處是通過讀取一次源表就可以插入多張目標表,減少重複讀取的開銷。語法 insert all conditional insert clause insert into clause value cla...

Mysql 建庫 建表 插入資料

檢視所有資料庫 show databases 新建test資料庫,建議不要用中文或者關鍵字,如果一定要用的化可以加反引號 引起來 charset 分為utf8 gbk create database test charset utf8 開啟test資料庫 use沒有退出資料庫的命令,但是可以檢視資料...