Hiveの——ビュー
転載は出典を明記してください.https://blog.csdn.net/l1028386804/article/details/88384861
ビューを使用してクエリーの複雑さを軽減
たとえば、ネストされたクエリー:
ここでは、ネストされたサブクエリをビューにします.
これで、このビューを操作テーブルのように操作できます.
ビューを使用して、条件に基づいてフィルタリングされたデータを制限ビューを介してデータアクセスを制限することで、情報が任意にクエリーされないように保護できます.
Where句を使用してデータ・アクセスを制限できます.たとえば、特定の部門からの従業員情報のみを露出する従業員テーブル・ビューを提供します.
ダイナミックパーティションのビューとmapタイプには、次のデータがあります.
テーブルの作成:
type値がrequestに等しいcity,state,partの3つのフィールドのみを取り出し,ordersと名付け,state,city,partの3つのフィールドを持つビューを作成することができる.
次にビューshipmentsを作成します.このビューはtimeとpartの2つのフィールドを列として返し、typeの値がresponseであることを示します.
ビュー文にlimit 100句が含まれ、このビューに使用されるクエリにlimit 200句が含まれている場合、最終的には最大100件の結果レコードしか取得できません.ビューに関連するテーブルまたはカラムが存在しない場合、ビュークエリーが失敗します.ビューを作成するときに、他の句を使用することもできます.
1つのビューの名前は、このビューが存在するデータベースの下にある他のすべてのテーブルとビューの名前とは異なります.as select句に名前の付いていない別の式が含まれている場合、たとえばsize(cols)(colsの要素の個数を計算)では、hiveは_を使用します.CNは新しいカラム名として、Nは0から始まる整数を表し、as select文が合法でない場合、ビューの作成プロセスは失敗します.
ビューのコピー:
externalとlocation句を選択的に使用することもできます.
ビューを削除:
describe文とdescribe extended文は、ビューのメタデータ情報を表示できます.
ビューはinsertまたはloadコマンドのターゲットテーブルとして使用できません.ビューは読み取り専用で、メタデータのtblpropertiesプロパティ情報のみを変更できます.
ビューを使用してクエリーの複雑さを軽減
たとえば、ネストされたクエリー:
from (
select * from people join cart
on(cart.pepople_id = people.id) where firstname = 'join'
)a select a.lastname where a.id = 3;
ここでは、ネストされたサブクエリをビューにします.
create view shorter_join as
select * from people join cart
on (cart.pepople_id = people.id) where firstname = 'join';
これで、このビューを操作テーブルのように操作できます.
select lastname from shorter_join where id = 3;
ビューを使用して、条件に基づいてフィルタリングされたデータを制限ビューを介してデータアクセスを制限することで、情報が任意にクエリーされないように保護できます.
create table userinfo(firstname string, lastname string, ssn string, password string);
create view safer_user_info as select firstname, lastname from userinfo;
Where句を使用してデータ・アクセスを制限できます.たとえば、特定の部門からの従業員情報のみを露出する従業員テーブル・ビューを提供します.
create table employee(firstname string, lastname string, ssn string, password string, department string);
create view techops_employee as select firstname, lastname, ssn from userinfo where department = 'techops';
ダイナミックパーティションのビューとmapタイプには、次のデータがあります.
time^B1342567890123^Atype^Brequest^Astate^Bny^Acity^Bwhite plains^Apart\^Bmuffler
time^B1342567890124^Atype^Bresponse^Astate^Btx^Acity^Btarrytown^Apart\^Bmuffler
テーブルの作成:
create external table dynamictable(cols map)
row format delimited
fields terminated by '\004'
collection items terminated by '\001'
map keys terminated by '\002'
stored as textfile;
type値がrequestに等しいcity,state,partの3つのフィールドのみを取り出し,ordersと名付け,state,city,partの3つのフィールドを持つビューを作成することができる.
create view orders(state, city, part) as
select cols['state'], cols['city'], cols['part']
from dynamictable where cols['type'] = 'request';
次にビューshipmentsを作成します.このビューはtimeとpartの2つのフィールドを列として返し、typeの値がresponseであることを示します.
create view shipments(time, part) as
select cols["time"], cols["part"]
from dynamictable where cols["type"] = 'response';
ビュー文にlimit 100句が含まれ、このビューに使用されるクエリにlimit 200句が含まれている場合、最終的には最大100件の結果レコードしか取得できません.ビューに関連するテーブルまたはカラムが存在しない場合、ビュークエリーが失敗します.ビューを作成するときに、他の句を使用することもできます.
create view if not exists shipments(time, part)
comment 'Time and parts for shipments.'
tblproperties(creator='me')
as select ...;
1つのビューの名前は、このビューが存在するデータベースの下にある他のすべてのテーブルとビューの名前とは異なります.as select句に名前の付いていない別の式が含まれている場合、たとえばsize(cols)(colsの要素の個数を計算)では、hiveは_を使用します.CNは新しいカラム名として、Nは0から始まる整数を表し、as select文が合法でない場合、ビューの作成プロセスは失敗します.
ビューのコピー:
create table orders2 like orders;
externalとlocation句を選択的に使用することもできます.
ビューを削除:
drop view if exists orders;
describe文とdescribe extended文は、ビューのメタデータ情報を表示できます.
ビューはinsertまたはloadコマンドのターゲットテーブルとして使用できません.ビューは読み取り専用で、メタデータのtblpropertiesプロパティ情報のみを変更できます.
alter view orders set tblproperties('create_at' = 'some_timestamp');