hive中inとnot in
mysqlではin/existsを含むか含まないかを表現したいのですが、hive 1のバージョンではこの構文はサポートされていません.hive 2はこの構文をサポートしていますが、効率は極めて低く、ここでは解決策を示します.
テーブルの作成とデータのインポート
データ#データ#
parent_id pname comments
テーブルの作成とデータのインポート
parent_id person_id cname comments
データ#データ#
例1:親の資料が表にある子供の名前を探し出す
inクエリー方式
クエリ結果
例2:親の資料が表にない子どもの名前を見つける
not inクエリー方式
クエリ結果
テーブルの作成とデータのインポート
create table if not exists parent(parent_id int,pname string,comments string) row format delimited fields terminated by "\t";
load data local inpath "/home/hadoop/hive_data/parent.txt" into table parent;
データ#データ#
parent_id pname comments
1 Dan so what
2 Jack who cares
3 Rose yeah right
テーブルの作成とデータのインポート
parent_id person_id cname comments
create table if not exists children(parent_id int,person_id int,cname string,comments string) row format delimited fields terminated by "\t";
load data local inpath "/home/hadoop/hive_data/children.txt" into table children;
データ#データ#
1 2 annne who cares
1 1 julia yeah right
2 1 marcella so what
4 3 alice yeah right
例1:親の資料が表にある子供の名前を探し出す
inクエリー方式
select cname
from children a left outer join parent b on a.parent_id=b.parent_id
where b.comments is not null;
クエリ結果
cname
annne
julia
marcella
例2:親の資料が表にない子どもの名前を見つける
not inクエリー方式
select cname
from children a left outer join parent b on a.parent_id=b.parent_id
where b.comments is null;
クエリ結果
cname
alice