Hive(5)Hiveデータ操作DML言語

5. DMLデータ操作

5.1データのインポート

5.1.1データをテーブルにロードする(ロード)

  • 文法
hive> load data [local] inpath '路径' [overwrite] into table 表名 [partition (partcol1=val1,)];

(1)データのロード:データのロード

(2)ローカル:ローカルからハイブテーブルにデータをロードすることを意味します。それ以外の場合は、HDFSからハイブテーブルにデータをロードします

(3)inpath:データをロードするパスを示します

(4)上書き:テーブル内の既存のデータを上書きすることを意味します。それ以外の場合は追加することを意味します

(5)テーブルへ:ロードするテーブル

(6)テーブル名:特定のテーブルを示します

(7)パーティション:指定したパーティションにアップロードすることを意味します

5.1.2クエリステートメントを使用してテーブルにデータを挿入する(挿入)

  • 場合

基本的な挿入

insert into table  student partition(month='201709') values(1,'wangwu');
insert overwrite table student partition(month='201708') select id, name from student where month='201709';

複数挿入

from dept_partition
              insert overwrite table dept_partition partition(month='201707')
              select deptno,dname,loc where month='201709'
              insert overwrite table dept_partition partition(month='201706')
              select deptno,dname,loc  where month='201709';

5.1.3テーブルを作成し、クエリステートメントにデータを読み込む(選択時)

クエリ結果に基づいてテーブルを作成します(クエリ結果は新しく作成されたテーブルに追加されます)

create table if not exists student3 as select id, name from student;

5.1.4テーブルの作成時に場所を介してロードデータパスを指定する

テーブルを作成し、hdfs上の場所を指定する

create table if not exists student5(
id int, name string)
row format delimited fields terminated by '\t'
location '/user/hive/warehouse/student5';

hdfsへのデータのアップロード

dfs -put /opt/datas/student.txt /opt/hive/warehouse/student5;

5.1.5指定したHiveテーブルにデータをインポートする

注:最初にexportを使用してエクスポートしてから、データをインポートします。

import table student2 partition(month='201709') from '/opt/hive/warehouse/export/student';

5.2データのエクスポート

5.2.1挿入エクスポート

1。クエリ結果をローカルにエクスポート

insert overwrite local directory '/opt/datas' select * from dept_partition;

image-20200918084842193

image-20200918085621207

2。クエリ結果をフォーマットしてローカルにエクスポートする

insert overwrite local directory '/opt/datas/dept1'
row format delimited
fields terminated by '|'
select * from dept_partition;

image-20200918085644479

3。クエリの結果をHDFSにエクスポートする(ローカルなし)

insert overwrite directory '/opt/datas/dept'
row format delimited
fields terminated by '|'
select * from dept_partition;

image-20200918090048512

5.2.2ローカルへのHadoopコマンドのエクスポート

dfs -get /opt/hive/warehouse/employee/employee.txt /opt/datas/dept2/dept.txt;

5.2.3 Hive Shellコマンドのエクスポート

基本構文:(ハイブ-f / -e実行ステートメントまたはスクリプト>ファイル)

hive -e 'select * from hivetest.dept_partition;' > /opt/datas/dept3/dept.txt;

注:シェルウィンドウで実行する必要があります。ライブラリ名、テーブル名、およびローカルフォルダーが存在している必要があります。

image-20200918091555443

5.2.4 HDFSへのエクスポート

export table hivetest.dept_partition to '/opt/datas/dept2';

5.2.5 Sqoopエクスポート

ファローアップ

5.3テーブルのデータを消去する(切り捨て)

注:Truncateは管理テーブルのみを削除でき、外部テーブルのデータは削除できません

truncate table student;

おすすめ

転載: blog.csdn.net/zmzdmx/article/details/108658818