Hive Terminal RuntimeException after query execution - sql

I have executed this query on HIVE, using that dataset:
https://data.europa.eu/data/datasets/erasmus-mobility-statistics-2014-2019-v2?locale=en:
select i.foe, i.pn, i.massimo
from
(
SELECT m.foe, m.pn, max(m.somma) AS massimo
FROM
(
select pn, foe, sum(participants) as somma
from erasmus
WHERE foe <> "? Unknown ?" and participants>0
group by foe, pn
) as m
group by m.foe, m.pn
) as i
where i.massimo=
(
select sum(participants) as somma
from erasmus
WHERE foe <> "? Unknown ?" and participants>0 AND i.foe=foe
group by foe, pn
)
At the end of execution I get this error back:
Error: java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row (tag=0) {"key":{"_col0":"Audio-visual techniques and media production","_col1":"AD"},"value":null}
caused by: org.apache.hadoop.hive.ql.exec.UDFArgumentException: Scalar subquery expression returns more than one row.
How can I solve this? Thank you.

Related

Can we use pivot keyword in Impala Cloudera?

This code is giving error
-- HADOOP IMPALA VISION 1
SELECT * FROM
(
SELECT
K.XID,
K.KAMPUS,
K.CIHAZTIPI,
K.CIHAZMODELI,
K.SISTEM,
K.CIHAZMARKASI,
K.SAHAEKIPMANKODU
FROM ODAK_STAGE.ENERGY_SAVING_KLIMA_UNPIVOT K
)
PIVOT
(
SUM(DEGER)
FOR DEGERTIPI
IN (
'sahaekipmankodu',
'Basinc',
)
)
ORDER BY DEGERTIPI
SQL Error [500051] [HY000]: [Cloudera]ImpalaJDBCDriver ERROR processing query/statement. Error Code: 0, SQL state: TStatus(statusCode:ERROR_STATUS, sqlState:HY000, errorMessage:ParseException: Syntax error in line 14:¶( ¶^¶Encountered: (¶Expected: CROSS, FROM, FULL, GROUP, HAVING, INNER, JOIN, LEFT, LIMIT, OFFSET, ON, ORDER, RIGHT, STRAIGHT_JOIN, TABLESAMPLE, UNION, USING, WHERE, COMMA¶¶CAUSED BY: Exception: Syntax error¶), Query: SELECT * FROM¶(¶ SELECT ¶ K.XID,¶ K.KAMPUS,¶ K.CIHAZTIPI,¶ K.CIHAZMODELI,¶ K.SISTEM,¶ K.CIHAZMARKASI,¶ K.SAHAEKIPMANKODU¶ FROM ODAK_STAGE.ENERGY_SAVING_KLIMA_UNPIVOT K¶)¶PIVOT ¶( ¶ SUM(DEGER) ¶ FOR DEGERTIPI¶ IN ( ¶ 'sahaekipmankodu',¶ 'Basinc', ¶ ) ¶)¶ORDER BY DEGERTIPI.
You can't per the 6.1 documentation, PIVOT is not a current functionality.
https://www.cloudera.com/documentation/enterprise/6/6.1/topics/impala_reserved_words.html

Nested select statements in impala sql

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';

Issue with BigQuery WITH clause

I'm trying to use BigQuery's WITH clause as described in the documentation. I'm getting an error when running the following query:
WITH subQ1 AS (SELECT "1"),
subQ2 AS (SELECT "2")
SELECT * FROM subQ1
UNION ALL
SELECT * FROM subQ2;
The thrown error is:
Error: Encountered " "WITH" "WITH "" at line 1, column 1. Was expecting: <EOF>
Anyone has any idea of what I'm doing wrong?
You should do Enabling Standard SQL
Rather than this - you should be good!
BigQuery Legacy SQL does not support WITH

Hive query returing code 2 Exception

Following is the query running on hive server 4 map reduce jobs are running . It fails after running the second map-reduce job. Belowi is the query and following the error that seems to be coming . Please let me know if you have any idea.
select kpl.normalized_keyword, kpl.ptitle_id as feature_id, kpl.tagcount as tag_count, kpl.market_id, kpl.rpd_metric, kpl.rpi_metric,
kpl.imps_day, kpl.clicks_day, kpl.clicks, kpl.lang
from
(select coalesce(kpl_sprf.normalized_keyword, kpl_sr.normalized_keyword) normalized_keyword, coalesce(kpl_sprf.ptitle_id, kpl_sr.ptitle_id) ptitle_id,
coalesce(kpl_sprf.tagcount, kpl_sr.tagcount) tagcount, coalesce(kpl_sprf.market_id, kpl_sr.market_id)
market_id, kpl_sprf.rpd_metric, kpl_sprf.rpi_metric, kpl_sprf.lang, kpl_sprf.imps_day, kpl_sprf.clicks_day, kpl_sr.clicks
from
(select kpl_sprf.normalized_keyword, kpl_sprf.lang, kpl_sprf.ptitle_id, kpl_sprf.tagcount, kpl_sprf.market_id, kpl_sprf.rpd_metric,
kpl_sprf.rpi_metric, case when kp.avg_imps_short is not null then kp.avg_imps_short/kp.interval_days_short when datediff(kp.last_modified,
kp.interval_start_short) <= 0 then kp.cur_imps_short/1.0 else kp.cur_imps_short/datediff(kp.last_modified, kp.interval_start_short) end as
imps_day, case when kp.avg_clicks_short is not null then kp.avg_clicks_short/kp.interval_days_short when datediff(kp.last_modified, kp.interval_start_short)
<= 0 then cur_clicks_short/1.0 else cur_clicks_short/datediff(kp.last_modified, kp.interval_start_short) end as clicks_day
from
kpl_sprf_wk kpl_sprf
left semi join
(select * from scfg_kpl_sprf_wk where date_ = '2015-02-26') kw on kw.normalized_keyword
= kpl_sprf.normalized_keyword and kw.lang = kpl_sprf.lang join (select * from sprf_keyword_ptitle_ng_stats_wk where date_ = '2015-02-26')
kp on kp.normalized_keyword = kpl_sprf.normalized_keyword and kp.ptitle_id = kpl_sprf.ptitle_id and kp.market_id = kpl_sprf.market_id where
(kp.cur_clicks_long >= 3 or kp.avg_clicks_long >= 3) and (datediff(kp.last_modified, kp.interval_start_long) >= 7 or
kp.avg_imps_long is not null) and kp.ptitle_id not between 1100000000 and 1100100000) kpl_sprf full outer join
(select kpl_sr.normalized_keyword, kpl_sr.ptitle_id, kpl_sr.tagcount, kpl_sr.market_id, kpl_sr.clicks from kpl_sr_wk kpl_sr left semi join
(select * from scfg_kpl_sprf_wk where date_='2015-02-26') kw on kw.normalized_keyword = kpl_sr.normalized_keyword and kw.lang = kpl_sr.lang )
kpl_sr on kpl_sr.normalized_keyword = kpl_sprf.normalized_keyword and kpl_sr.ptitle_id = kpl_sprf.ptitle_id and kpl_sr.market_id = kpl_sprf.market_id)
kpl where kpl.market_id in (1)
which is giving the following error
Error: java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row {"normalized_keyword":"","lang":"es","date_":"2015-02-26"}
at org.apache.hadoop.hive.ql.exec.ExecMapper.map(ExecMapper.java:159)
at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:54)
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:428)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:340)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:157)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1408)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:152)
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row {"normalized_keyword":"","lang":"es","date_":"2015-02-26"}
at org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:675)
at org.apache.hadoop.hive.ql.exec.ExecMapper.map(ExecMapper.java:141)
... 8 more
Caused by: java.lang.RuntimeException: cannot find field normalized_keyword from [0:_col0, 1:_col1]
at org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils.getStandardStructFieldRef(ObjectInspectorUtils.java:346)
at org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector.getStructFieldRef(StandardStructObjectInspector.java:143)
at org.apache.hadoop.hive.ql.exec.ExprNodeColumnEvaluator.initialize(ExprNodeColumnEvaluator.java:57)
at org.apache.hadoop.hive.ql.exec.ExprNodeGenericFuncEvaluator.initialize(ExprNodeGenericFuncEvaluator.java:128)
at org.apache.hadoop.hive.ql.exec.FilterOperator.processOp(FilterOperator.java:85)
at org.apache.hadoop.hive.ql.exec.Operator.process(Operator.java:474)
at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:800)
at org.apache.hadoop.hive.ql.exec.SelectOperator.processOp(SelectOperator.java:84)
at org.apache.hadoop.hive.ql.exec.Operator.process(Operator.java:474)
at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:800)
at org.apache.hadoop.hive.ql.exec.TableScanOperator.processOp(TableScanOperator.java:83)
at org.apache.hadoop.hive.ql.exec.Operator.process(Operator.java:474)
at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:800)
at org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:658)
This issue seems to be coming since a lot. I think it is because of join query used Any Idea how to resolve it ?
Somewhere in that query you are referencing the field normalized_keyword, but it wasn't found in the fields you had selected. First thing I would suggest is to replace SELECT * with the actual fields and work through each instance of normalized_keyword to make sure it is available to be selected.

PreparedStatementCallback; bad SQL grammar

I'm getting the following sql error in my sql command! please can anyone explain me what I'm doing wrong here!
15:20:43,686 ERROR [PageExceptionFlowInterceptor] Exception (EJBException) while executing Action [com.jkcs.khms.web.cashiering.hotelTax.HotelTaxAction] : org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT * FROM (SELECT rs_qry.*, ROWNUM rn_qry FROM ( SELECT ht.htl_tax_id,
ht.hotel_id,
ht.tax_id,
ht.status,
ht.display_sequence,
t.id,
t.code,
h.hotel_name,
h.hotel_id
FROM
PMS_T_HTL_TAX ht,
CRS_T_TAX t,
CRS_T_HOTEL h WHERE ht.hotel_id IN (1) AND ht.tax_id IN (31,3,37,38,36,23,29,30,24,10,12,20,11,1,16,17,18,19,34,35,15,33,22,2,21,32) order by ht.hotel_id, ht.htl_tax_id ) rs_qry ) WHERE rn_qry BETWEEN 1 AND 10]; nested exception is java.sql.SQLException: ORA-00904: "T"."ID": invalid identifier
Your CRS_T_TAX table doesn't have a column called ID