The next query would work in oracle, but not in hive:
select user_key,(sum(333)/(select 10 from table.dual)) calculationResult from user_usage_table group by user_key;
The result I expect:
user_key calculationResult
DB-_app6_61_28fba6e2f0_12d 2930.4
DB-_app6_61_28fba6e2f0_171 2930.4
DB-_app6_61_28fba6e2f0_1b5 2930.4
DB-_app6_61_28fba6e2f0_69 2930.4
DB-_app6_61_28fba6e2f0_e9 2930.4
what do I get:
FAILED: ParseException line 1:33 cannot recognize input near 'select' '10' 'from' in expression specification
How do I apply this in hive?
Your query is quite strange. Why not just write:
select user_key, (sum(333) / 10) as calculationResult
from user_usage_table
group by user_key;
This should work in both Oracle and hive.
Related
CTE is giving parseError : ParseException line 1:42 mismatched input 'as' expecting ) near 'cust_xref_id' in statement
with table1 as
(select 2020.cust_xref_id as 2020_cust, 2019.cust_xref_id as 2019_cust
from dea.sp_2020_us as 2020
left join dea.sp_2019_us as 2019
on 2020.cust_xref_id = 2019.cust_xref_id)
select count(distinct(*))
from tabel1
where 2019_cust is not null;
Can't figure out where the mistake is.
Any help would be appreciated!
If the column's name does not start with a string, you have to enclose the name with backticks (`2020_cust`).
I have the following SQL query in impala
SELECT currentdate,close
FROM ( SELECT * FROM spyprice)
Where currentdate between '2015-01-16' and '2016-06-17';
And it is giving me the error:
Starting Impala Shell without Kerberos authentication
ERROR: AnalysisException: Syntax error in line 15:
WHERE currentdate BETWEEN '2015-01-16' and '2016-06-17'
^
Encountered: WHERE
Expected: AS, DEFAULT, IDENTIFIER
CAUSED BY: Exception: Syntax error
Anyone knows what's going on?
Thanks in advance!
#James Xiang The right syntax of the query statement is :
SELECT a.currentdate, a.close FROM
(
SELECT * FROM spyprice
) a
Where a.currentdate between '2015-01-16' and '2016-06-17';
I have fields like date_column = 20140228 in the table 1. When I hard code the number like below it works, but when I specify the column name its failing. With error
H110 Unable to submit statement. Error while compiling statement: FAILED: ParseException line 2:1 cannot recognize input near 'select' 'date_format' '(' in select clause [ERROR_STATUS]
Working:
select date_format(from_unixtime(unix_timestamp(cast('2014022817' as string),'yyyyMMddHH')),'yyyy-MM-dd HH');
Failing:
select
select date_format(from_unixtime(unix_timestamp(cast(date_column as string),'yyyyMMddHH')),'yyyy-MM-dd HH')
from
table1
Why are you repeating the select? Try this:
select date_format(from_unixtime(unix_timestamp(cast(date_column as string
),'yyyyMMddHH'
)
),'yyyy-MM-dd HH'
)
from table1
Is there any way to convert below LEAD function into HIVE QL format??
NVL(LEAD(START_DT) OVER (PARTITION BY EV_ID,AR_EV_RLTNSHP_TYPE_CD ORDER BY START_DT)-1,'2099-12-31') AS DERIVED_END_DT
PFB the error:
FAILED: ParseException line 1:1599 missing ) at 'OVER' near '(' in
subquery source line 1:1603 missing FROM at '(' near '(' in subquery
source line 1:1604 cannot recognize input near 'PARTITION' 'BY'
'EV_ID' in subquery source
It is complicated in HiveSQL but you can do it with a left join and aggregation:
select t.ev_id, t.ar_ev_rltnshp_type_cd, t.start_date,
coalesce(min(tnext.start_dt) - 1, '2099-12-31') as derived_end_dt
from table t left join
table tnext
on t.ev_id = tnext.ev_id and t.ar_ev_rltnshp_type_cd = tnext.ar_ev_rltnshp_type_cd and
tnext.start_date > t.start_date
group by t.ev_id, t.ar_ev_rltnshp_type_cd, t.start_date;
This makes certain assumptions about start_date being unique within a given group, but it will probably work for your purposes.
Is there a way to do this in HiveQL :
SELECT ......
from
default.thm_renta_produits_jour rpj
WHERE
rpj.co_societe = '${hiveconf:in_co_societe}'
AND rpj.dt_jour >= (SELECT MIN(dt_jour) FROM default.calendrier WHERE co_an_semaine = '${hiveconf:in_co_an_sem}')
Because when i do this, i get this error :
FAILED: ParseException line 51:26 cannot recognize input near 'SELECT' 'MIN' '(' in expression specification
Thanks,
Hive does not support sub queries in where clause it supports sub queries in from clause only.
Hive does not support sub queries in the WHERE clause. Perhaps you can work around this by moving your sub query to a JOIN clause like so:
SELECT
rpj.*
FROM
default.thm_renta_produits_jour rpj
JOIN
( SELECT MIN(dt_jour) AS min_dt_jour
FROM default.calendrier
WHERE co_an_semaine = '${hiveconf:in_co_an_sem}'
) m
WHERE
rpj.co_societe = '${hiveconf:in_co_societe}'
AND rpj.dt_jour >= m.min_dt_jour;
Hope that helps.
I know that this is an old post, but the previous answers are now outdated. Newer versions of Hive (0.13+) support subqueries of where clauses, so your query should run.
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+SubQueries#LanguageManualSubQueries-SubqueriesintheWHEREClause