SQL hive建表 匯入資料

2021-10-04 16:18:00 字數 1695 閱讀 7473

1、直接在資料庫中建立:

use tmp_ubtdb;

create

table tablenamedemo (

field1 string comment

'field1 comment'

, field2 string comment

'field2 comment'

)comment

'table comment'

partitioned by

(d string comment

'date'

)-- 若無分割槽則刪除

stored as orc;

2、從已有的資料庫進行資料抽取從新生成一張表:

use tmp_ubtdb;

drop

table

ifexists tmp_ubtdb.aaaa;

create

table

ifnot

exists tmp_ubtdb.aaaa

asselect

*from tmp_ubtdb.bbbb

;

3、建立一張空錶帶資料結構(like)

create

table tmp_ubtdb.cccc like tmp_ubtdb.aaaa;

select

*from tmp_ubtdb.cccc;

1、本地檔案上傳 (暫不分享)

2、insert into 插入資料,不覆蓋,追加模式

use tmp_ubtdb;

insert

into

table tmp_ubtdb.dddd

select

*from tmp_ubtdb.cccc -- 把ccc表追加到aaa匯入dddd

;

3、insert overwrite 覆蓋

use tmp_ubtdb;

insert overwrite table tmp_ubtdb.ffff partition

(d)select

*from tmp_ubtdb.aaaa -- 把aaaa表追加到ffff表中,覆蓋同樣分割槽(d)

;

注:

insert into 的巧用:

可以查詢每天的資料生成中間表,插入到結果表中,可以減少記憶體的使用,提高製表效率

– insert into 與insert overwrite 之間的異同,兩者都可以向 hive 表中插入資料,

–但 insert into 操作是以追加的方式向 hive 表尾部追加資料,

–而 insert overwrite 操作則是直接重寫資料,即先刪除 hive 表的資料,再執行寫入操作。

–注意,如果 hive 表是分割槽表的話,insert overwrite 操作只會重寫當前分割槽的資料,不會重寫其他分割槽資料

–hive刪除表:

–drop table table_name;

–hive刪除表中資料:

–truncate table table_name;

–hive按分割槽刪除資料:

–alter table table_name drop partition (partition_name=『分割槽名』)

hive 匯入sql hive資料匯入VS匯出

hive包括以下四種資料匯入方式 1.1 本地檔案匯入到hive表 load data local inpath home hadoop sourcea.txt into table table1 partition create time 2020 11 20 1.2 hive表匯入到hive表 ...

hive建表 匯入資料 匹配

1.建表 建立非重複表,分隔符設定為 create table if not exists imei guid imei string row format delimited fields terminated by 2.匯入 將本地資料夾的資料上傳到hive,適用資料量較大情況 concaten...

建表匯入csv

部分 參考 資料檔案中的列數跟 mysql 資料表字段數目沒有完全匹配,並且 sql mode 設為 strict 模式 先查詢當前的sql mode,再設定sql mode的模式。show variables like sql mode set sql mode 建表語句 create table...