我有一个场景,我需要从三列中选择行中的最大值,有一个名为Greatest的函数,但它在我的Hive 0.13版本中不起作用。
请建议更好的方法来完成它。
示例表:
MultiValueMap<String, String> body = new LinkedMultiValueMap<String, String>();
body.add("client_id", "fe3..b2");
// ... rest params
// Note the body object as first parameter!
HttpEntity<?> entity = new HttpEntity<Object>(body, new HttpHeaders());
预期结果:
+---------+------+------+------+
| Col1 | Col2 | Col3 | Col4 |
+---------+------+------+------+
| Group A | 1 | 2 | 3 |
+---------+------+------+------+
| Group B | 4 | 5 | 1 |
+---------+------+------+------+
| Group C | 4 | 2 | 1 |
+---------+------+------+------+
答案 0 :(得分:4)
NSString * NSStringFromClass(Class aClass);
<强> sort_array(阵列)强>
根据数组元素的自然顺序按升序对输入数组进行排序并返回它 (从0.9.0版开始)。 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
select col1
,tuple.col1 as output_max
,concat('Col',tuple.col2) as max_column
from (select Col1
,sort_array(array(struct(Col2,2),struct(Col3,3),struct(Col4,4)))[2] as tuple
from t
) t
;