does impala support the "window xxx as" syntax? - hive

I'm on a CDH5.13 with hive-1.1 and impala-2.10.
And I found the following sql works well on hive and wrong in impala :
SELECT name,sum(age) OVER w, avg(age) OVER w FROM test1 WINDOW w AS (PARTITION BY name ORDER BY age DESC);
And the error msg:
select name,sum(age) OVER w, avg(age) OVER w FROM test...
^
Encountered: IDENTIFIER
Expected: (
CAUSED BY: Exception: Syntax error

Related

SQLite - problem with "near « ) » : syntax error"

I try here since i didn't find anything anywhere else.
I have a query which has been check by my colleagues and "teachers", but the error remains:
" near « ) » : syntax error".
The (last) query is the following one:
WITH valeur_par_ville AS
(
SELECT dep_code, com_code, AVG(valeur_fonciere) as valeur
FROM vente
JOIN bien ON bien.bien_id = vente.bien_id
JOIN commune ON commune.com_id = bien.com_id
WHERE dep_code IN (6,13,33,59,69)
GROUP BY dep_code, com_id
)
SELECT dep_code AS "Département", com_id AS "Commune", round(valeur,1) AS "Prix moyen"
FROM(
SELECT dep_code, com_nom, valeur_fonciere,
rank() OVER (PARTITION BY dep_code ORDER BY valeur_fonciere DESC) AS
rang
FROM valeur_par_ville) AS result
WHERE rang <= 3
I hope you can help me on this, because it becomes "black magic" to me!
Thanks.
I tried different ways to reach a result, but the same thing keeps going... I Checked all my data tables, updated SQLite (so PARTITION BY works on it now), reboot, checked the query little by little... No idea where it comes from.
Others colleagues (we are kind of students) managed to have a valid result with their own queries.
But for me:
" near « ) » : syntax error".
The error is coming from a different part of the code. I added CREATE TABLE statements to be able to run your code and it's failing differently.
CREATE TABLE vente(dep_code, com_code, valeur_fonciere, bien_id);
CREATE TABLE bien(bien_id, com_id);
CREATE TABLE commune(com_id);
-- your code here
The error:
Parse error near line 4: ambiguous column name: com_id
RE dep_code IN (6,13,33,59,69) GROUP BY dep_code, com_id ) SELECT dep_code AS
error here ---^
After prefixing it with a table name, there's another bunch of errors, e.g.
arse error near line 4: no such column: com_nom
(valeur,1) AS "Prix moyen" FROM( SELECT dep_code, com_nom, valeur_fonciere, ra
error here ---^
Parse error near line 4: no such column: valeur_fonciere
) AS "Prix moyen" FROM( SELECT dep_code, com_nom, valeur_fonciere, rank() OVER
error here ---^
etc.

Hive Terminal RuntimeException after query execution

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.

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

SemanticException [Error 10004]: Line 11:18 Invalid table alias or column reference

This question is related to the answer of my previous question. Please notice that datetime is string. Therefore I convert it to unix timestamp.
I execute this query in Hive 1.2.1:
select count(*) / count(distinct to_date(datetime)) as trips_per_day
from (select radar_id,to_unix_timestamp(datetime),lead(radar_id) over w as
next_radar_id,lead(to_unix_timestamp(datetime)) over w as
next_datetime
from mytable
where radar_id in ('A21','B15') window w as
(partition by car_id order by to_unix_timestamp(datetime))) t
where radar_id = 'A21' and next_radar_id = 'B15'
and to_unix_timestamp(datetime) + 30*60 > to_unix_timestamp(next_datetime);
But I get the following error:
SemanticException [Error 10004]: Line 11:18 Invalid table alias or
column reference 'datetime': (possible column names are: radar_id, _c1,
next_radar_id, next_datetime)
Where is an error?

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