Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 01-29-2018 11:21 PM
I have a requirement to calculate greatest value in multiple columns.
Input:
| name | sub1 | sub2 | sub3 |
| st1 | 10 | 12 | 15 |
| st2 | 50 | 30 | 35 |
| st3 | 15 | 18 | 13 |
expected output:
| name | max_sub |
| st1 | 15 |
| st2 | 50 |
| st3 | 18 |
When I try to use greatest function as below, I'm getting
Failed with exception java.io.IOException:org.apache.hadoop.hive.ql.metadata.HiveException: Error evaluating greatest(sub1,sub2,sub3)
select name,greatest(sub1,sub2,sub3) from students;
any other functions or simple udf available?
Note: I cant' use CASE statement as I have to consider around 15 columns.
Created 01-30-2018 03:41 PM
To work around your issue, you can explicitly cast to string or int (or whatever your data type should be).
I could reproduce your case:
select greatest(month, billed) from sales limit 5; Error: java.io.IOException: org.apache.hadoop.hive.ql.metadata.HiveException: Error evaluating greatest(month,billed) (state=,code=0)
with workaround:
select greatest(int(month), int(billed)) from sales limit 5; +------+--+ | _c0 | +------+--+ | 8 | | 8 | | 8 | | 8 | | 2 | +------+--+
or
select greatest(string(month), string(billed)) from sales limit 5; +------+--+ | _c0 | +------+--+ | 8 | | 8 | | 8 | | 8 | | 2 | +------+--+
Created 01-30-2018 07:43 AM
Can you attach a desc extended for your table. Greatest should work provided all the columns have the same datatype and are only primitive types.
Created 01-30-2018 03:22 PM
Created 01-30-2018 03:41 PM
To work around your issue, you can explicitly cast to string or int (or whatever your data type should be).
I could reproduce your case:
select greatest(month, billed) from sales limit 5; Error: java.io.IOException: org.apache.hadoop.hive.ql.metadata.HiveException: Error evaluating greatest(month,billed) (state=,code=0)
with workaround:
select greatest(int(month), int(billed)) from sales limit 5; +------+--+ | _c0 | +------+--+ | 8 | | 8 | | 8 | | 8 | | 2 | +------+--+
or
select greatest(string(month), string(billed)) from sales limit 5; +------+--+ | _c0 | +------+--+ | 8 | | 8 | | 8 | | 8 | | 2 | +------+--+
Created 01-31-2018 07:25 AM
This is related to HIVE-12082. This issue exist in Hive1
1) You can either use Hive2 (Interactive HS2)
2) Workaround using explicitly cast to int.
select name, greatest(int(sub1),int(sub2),int(sub3)) from students;
3) Use orc format
Created 01-31-2018 07:14 PM
Thanks @Naresh P R. Can you please let me know where can I track all the issues like this?
Thanks in advance!
Created 02-01-2018 05:19 AM
You can check for the relevant issue in HIVE Jira