答案 0 :(得分:2)
您可以使用brickhouse(http://github.com/klout/brickhouse)中的conditional_emit
UDF来执行此操作。
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,它将为数组元素发出一个记录,该记录是真的(在传入的第一个数组中),传入的第二个数组中的相应字符串。注意,这只会传递一个数据,而UNION
将进行多次传递。
答案 1 :(得分:0)
你可以试试这个
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