We are migrating greenplum to hive and we are have to convert similar operation in hive, as below statement needs to convert hive. please help me.
Greenplum :
round(Payg_usage/(1024.00^2),2)
the operator ^ not supporting
Hive ?
In hive you can use pow/power function. Below returns m to power n (m^n)
POW( double m, double n ),
Or
POWER( double m, double n )
Use
Round(Payg_usage/pow(cast(1024.00 as double),cast(2 as double)),2)
Related
I am writing Hive query in the Hue editor in Cloudera VM. But somehow I am not getting the data in 2 decimal places. Same code if I run on shell it gives correct result. I am using latest cloudera version.
select u.column1, r.column2, AVG(round(r.metric,2)) as avgr from table1 r, table2 u where u.userid= r.userid and r.metric is not null group by u.column1, r.column2;
round() returns double, AVG() also returns double.
Better apply round after AVG:
round(AVG(r.metric),2)
If the GUI still displays it incorrectly, convert to decimal explicitly:
cast(round(AVG(r.metric),2) as decimal(19,2))
I want to display the decimal precision along with the result for decimal datatype in hive. However if there is no fraction part , in hive it will not display the decimal points.
hive> select cast(11 as decimal(14,2));
11
hive> select cast(11.22 as decimal(14,2));
11.22
In the above example instead of 11 it should display 11.00.How to achieve this?
Please help.
The following format_number() function should do it.Source, return type will be string though.
select format_number(11,2)
Note: Precision and Scale were added from Hive 0.13.
Use round or float_number to set the decimal point where u like , example :
select round(SUM(150.100 + 127.0090), 2);
or
select float_number(var,2);
I am trying to replicate a view from netezza to Hive and getting error while encountering to statement having double colon(::), used for data type casting I think.
Below is the sample statement:
CASE WHEN (DB.VW.ABC ISNULL) THEN ''::"NVARCHAR" ELSE DB.VW.ABC END AS ABC_FIXED
Oracle SQL provides
width_bucket(expression,min_value,max_value,num_buckets)
function to create a histogram. WIDTH_BUCKET Oracle SQL Reference. I want to know if the same functionality can be achieved using a nested query or something ?
Update: If it is not possible through a single query, I would like to know which of the following methods to implement the histogram function would be fastest in performance?
SQL PL stored procedure
JAVA stored procedure
JDBC program
WIDTH_BUCKET ( e, m, M, p ) is an ISO SQL function that can be convert in a simple mathematic formulae...
The strict equivalent in "plain" SQL is :
CASE
WHEN e < m
THEN 0
ELSE 1 + FLOOR((e - m ) / ((M - m)/p))
END
I have a bit shifting to be done on NUMBER column in table.
It is something like (NUMBER & MASK) >> 27 .. and i need to compare the result of this. Is this something that can be done through SQL select query. So far i am using scripts to do this/
Oracle's PL/SQL has a BITAND() function. Shift-right is the same as integer division by a power of 2. Assuming X is an integer, X >> 27 is the same as X / 134217728.