Hadoop HIVE 資料表 使用

2021-09-08 19:26:51 字數 1883 閱讀 3329

3 使用

3.1 資料匯入

3.1.1 可以使用命令列匯入,也可以直接上傳到hdfs的特定目錄

3.1.2 格式問題

3.1.2.1 缺失/不合法字段預設值為null

3.1.2.2 最好資料是格式化的,不要缺失字段

3.1.3 從hdfs其他目錄匯入

3.1.3.1 hadoop fs -put order_ext.txt / load data inpath '/order_ext.txt' into table tbl_order;

3.1.3.2 自動移動資料到hdfs特定目錄

3.2 資料表型別

3.2.1 managed

3.2.1.1 預設table型別

3.2.1.2 drop

3.2.1.2.1 資料刪除,整個目錄刪除

3.2.2 external

3.2.2.1 不要求資料放在特定目錄,不影響業務系統的持續執行

3.2.2.2 示例

3.2.2.2.1 hadoop fs -mkdir -p /hive_ext hadoop fs -put order_ext.txt /hive_ext create external table tbl_order_ext(id int, name string, size string, price double) row format delimited fields terminated by '\t' location '/hive_ext';

3.2.2.3 external型別table在hdfs上沒有新建特定目錄,在hive的tbls表中可以查詢

3.2.2.4 drop

3.2.2.4.1 只刪除邏輯表(元資料),資料不刪除,不影響業務資料

3.2.3 臨時表

3.2.3.1 create as

3.2.3.1.1 參考

3.2.3.1.1.1

3.2.3.1.2 示例

3.2.3.1.2.1 create table tbl_order_ctas as select id,name,price from tbl_order; select * from tbl_order_ctas;

3.2.3.2 insert into/overwrite

3.2.3.2.1 參考

3.2.3.2.1.1

3.2.3.2.2 示例

3.2.3.2.2.1 insert into tbl_order_ctas select id,name,price from tbl_order_ext;

3.2.4 partition

3.2.4.1 示例

使用IF NOT EXISTS建立資料表

如果簡單的使用如下sql語句可能會返回失敗,失敗的原因極有可能是已經存在這張資料表了。create table sales3 id numeric,sale date datetime not null partition by range to days sale date partition s...

建立資料表和修改資料表

建立表 sql中建立和刪除資料庫物件的語句被稱為資料定義語言 data definition language,ddl 操作這些物件中資料的語句被稱為資料操作語言 data manipulation language,dml 建立語句屬於ddl,用create table命令 create temp...

使用SQL語句建立資料表

create database test usetest 使用text庫,作為當前查詢的庫 create table tbclass clsid intprimary keyidentity 1,1 班級編號自增,主鍵,逗號後值為增量 clsname nvarchar 16 unique,唯一性約束...