Hive データのロード方法 (ロード、挿入、通常のテーブル、パーティション テーブル)

序文

Hiveデータの読み込み方法 (挿入、読み込み)の紹介


方法 1: データをロードする

基本的な構文:
load data [local] inpath '/opt/module/datas/student.txt' [overwrite] into table student[partition ]

パラメータの説明:
1 データのロード: データのロードを示します。
2 ローカル: データをローカルからハイブ テーブルにロードすることを示します。それ以外の場合は、HDFS からデータをハイブ テーブルにロードします。
3 inpath: データのロードの
相対パスを示します。例: project/data1
ABSパス (例:/user/hive/project/data1) には、次
のようなスキーマの完全な URI が含まれます。 hdfs://namenode:9000/user/hive/project/data1
4 上書き: テーブル内の既存のデータを上書きすることを意味します。 、それ以外の場合は追加を意味します。ターゲット テーブル (またはパーティション) のコンテンツが削除され、ファイルパスで指定されたファイル/ディレクトリのコンテンツがテーブル/パーティションに追加されます。 5 into table: どのテーブルをロードするかを示します。 6 Student: を示し
ます
。特定のテーブル
7 パーティション : 指定されたパーティションへのアップロードを示します

-- 加载本地文件
load data local inpath '/home/hadoop/load1.txt' into table tb_load1;

-- 加载HDFS文件
load data inpath '/hive/test/load2.txt' into table tb_load1;

-- 加载分区数据
load data inpath '/hive/test/load_part_male.txt' into table tb_load2 
partition (sex='male');

--使用overwrite:会覆盖之前的数据
load data local inpath '/home/hadoop/load3.txt' overwrite into table tb_load1;

方法 2: 挿入挿入

1.普通の時計

-- 覆盖 
insert overwrite table tb_insert1 select id,name from tb_select1;
-- 追加
insert into table tb_insert1 select id,name from tb_select1;

2.パーティションテーブル

-- 分区插入
insert overwrite table tb_insert_part partition(sex = 'male')
select id,name from tb_select1 where sex='male';

-- 动态分区插入(需先设置非严格模式)
set hive.exec.dynamic.partition.mode=nonstrict;

insert overwrite table tb_dy_part partition(sex) 
select id,name,sex from tb_select1;

方法 3: 選択として

注意: データは as モードでのみロードできます。他のパーティション フィールドがある場合、パーティション フィールドはフィールド形式でのみ保持されます。

create table tb_create_mode as 
select id,name from tb_select1;

データ出力

(1) ローカルへのエクスポート

insert overwrite local directory '/home/hadoop/'
select id,name from tb_select1;

例 :

INSERT overwrite directory "/user/yuanpengfei/ypf/lifeng/vehPOI" ROW format delimited fields terminated BY "," 
select substr( md5(concat('mb',field_2,'xx')),9,6), field_3, field_4, field_5, field_6, field_7
from default.longchuan_od_temp

要約する

この記事があなたのお役に立てば、偉い人たちが私を关注サポートしてくれることを願っています。ありがとうございました! 何か間違っていたら修正してください!!!点赞收藏评论

参考1
参考2

おすすめ

転載: blog.csdn.net/weixin_42326851/article/details/132214145