2016-08-25 3 views
0

ハイブはピボットをサポートしていないので、ハイブでは以下のシナリオではより良いアプローチが必要です。ハイブで移調する方法

enter image description here

そして、私は以下の結果に変換する必要があります。

enter image description here

+0

サンプル出力を共有してください。どういう意味ですか?_col1、_col2 –

答えて

0

あなたはこれを行うにはブリックハウス(http://github.com/klout/brickhouse)からconditional_emit UDFを使用することができ、この

Select ID, Yes from (
SELECT ID, 'Col1' as 'Yes' where Col1 = 'yes' 
UNION ALL 
SELECT ID, 'Col2' as 'Yes' where Col2 = 'yes' 
UNION ALL 
SELECT ID, 'Col3' as 'Yes' where Col3 = 'yes' 
UNION ALL 
SELECT ID, 'Col4' as 'Yes' where Col4 = 'yes' 
UNION ALL 
SELECT ID, NULL as 'Yes' where Col1 != 'yes' and Col2 != 'yes' and Col3 != 'yes' and Col4 != 'yes' 
) TempTable ORDER BY ID 
+0

このソリューションは、効率性を気にすると絶対的な災難です。 – gobrewers14

2

を試すことができます。

SELECT ID, ce.feature as yes 
FROM 
table 
LATERAL VIEW conditional_emit( 
     ARRAY(col1 = 'yes', 
       col2 = 'yes', 
       col3 = 'yes', 
       col4 = 'yes', 
       col1 != 'yes' and col2 != 'yes' and col3 != 'yes' and col4 != 'yes'), 
     ARRAY('col1', 'col2', col3', 'col4', ' ')) c as ce; 

conditional_emit渡された二番目の配列からの対応する文字列で(渡された最初の配列に)真である配列要素のレコードを放出するUDTFである。これは上1回だけになることに注意してくださいデータは、UNIONは複数のパスを行います。

関連する問題