日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Hive的数据模型-外部表

發布時間:2025/3/11 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Hive的数据模型-外部表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


概述

包含External 的表叫外部表
刪除外部表只刪除metastore的元數據,不刪除hdfs中的表數據
外部表 只有一個過程,加載數據和創建表同時完成,并不會移動到數據倉庫目錄中,只是與外部數據建立一個鏈接。當刪除一個 外部表 時,僅刪除該鏈接
指向已經在 HDFS 中存在的數據,可以創建 Partition
它和 內部表 在元數據的組織上是相同的,而實際數據的存儲則有較大的差異


語法

CREATE EXTERNAL TABLE page_view
( viewTime INT,?
? userid BIGINT,
? page_url STRING,
?referrer_url STRING,
? ip STRING COMMENT 'IP Address of the User',
? country STRING COMMENT 'country of origination‘
)
? ? COMMENT 'This is the staging page view table'
? ? ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'
? ? STORED AS TEXTFILE
? ? LOCATION 'hdfs://centos:9000/user/data/staging/page_view';


實驗

hive (default)> create external table
? ? ? ? ? ? ? > external_test(name string,city string,address string)
? ? ? ? ? ? ? > row format delimited fields terminated by '\t'
? ? ? ? ? ? ? > location '/home/hive/extable';
OK
Time taken: 0.559 seconds
hive (default)> desc formatted external_test;
OK
col_name ? ? ? ?data_type ? ? ? comment
# col_name ? ? ? ? ? ? ?data_type ? ? ? ? ? ? ? comment ? ? ? ? ? ??
? ? ? ? ? ? ? ? ?
name ? ? ? ? ? ? ? ? ? ?string ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
city ? ? ? ? ? ? ? ? ? ?string ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
address ? ? ? ? ? ? ? ? string ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ?
# Detailed Table Information ? ? ? ? ? ??
Database: ? ? ? ? ? ? ? default ? ? ? ? ? ? ? ? ?
Owner: ? ? ? ? ? ? ? ? ?hadoop ? ? ? ? ? ? ? ? ??
CreateTime: ? ? ? ? ? ? Wed Sep 21 20:18:21 CST 2016 ? ??
LastAccessTime: ? ? ? ? UNKNOWN ? ? ? ? ? ? ? ? ?
Retention: ? ? ? ? ? ? ?0 ? ? ? ? ? ? ? ? ? ? ? ?
Location: ? ? ? ? ? ? ? hdfs://hello110:9000/home/hive/extable ??
Table Type: ? ? ? ? ? ? EXTERNAL_TABLE ?? ? ? ??
Table Parameters: ? ? ? ? ? ? ? ?
? ? ? ? EXTERNAL ? ? ? ? ? ? ? ?TRUE ? ? ? ? ? ? ? ?
? ? ? ? transient_lastDdlTime ? 1474460301 ? ? ? ? ?
? ? ? ? ? ? ? ? ?
# Storage Information ? ? ? ? ? ?
SerDe Library: ? ? ? ? ?org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe ? ? ??
InputFormat: ? ? ? ? ? ?org.apache.hadoop.mapred.TextInputFormat ? ? ? ??
OutputFormat: ? ? ? ? ? org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat ? ? ??
Compressed: ? ? ? ? ? ? No ? ? ? ? ? ? ? ? ? ? ??
Num Buckets: ? ? ? ? ? ?-1 ? ? ? ? ? ? ? ? ? ? ??
Bucket Columns: ? ? ? ? [] ? ? ? ? ? ? ? ? ? ? ??
Sort Columns: ? ? ? ? ? [] ? ? ? ? ? ? ? ? ? ? ??
Storage Desc Params: ? ? ? ? ? ??
? ? ? ? field.delim ? ? ? ? ? ? \t ? ? ? ? ? ? ? ? ?
? ? ? ? serialization.format ? ?\t ? ? ? ? ? ? ? ? ?
Time taken: 0.065 seconds, Fetched: 29 row(s)

hive (default)> load data local inpath '/data/ext_test' into table external_test;
Loading data to table default.external_test
OK
Time taken: 1.286 seconds


hive (default)> select * from external_test;
OK
external_test.name ? ? ?external_test.city ? ? ?external_test.address
1 ? ? ? dddd ? ?dddd
2 ? ? ? www ? ? www
3 ? ? ? eeee ? ?wwww
4 ? ? ? tttt ? ?cccc
5 ? ? ? yyycc ? dddd
Time taken: 1.92 seconds, Fetched: 5 row(s)




不指定location,會默認在:hdfs://hello110:9000/user/hive/warehouse/ 下面


刪除

外部表drop table t1。hdfs里數據還在,不會刪除。

再創建與剛才相同的表名的表的時候,
select * from t1,會發現表數據會依然還在。

(如果指定了location,則location要一樣,如果沒有指定,則都在?/user/hive/warehouse 下。




總結

以上是生活随笔為你收集整理的Hive的数据模型-外部表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。