Can we use pivot keyword in Impala Cloudera? - sql

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

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.

Getting Error when using SQL With Common Table Expression (CTE)

I am new to SQL. I am trying to use SQL CTE but I keep getting the error:
Msg 102, Level 15, State 1, Line 16
Incorrect syntax near ')'.
I am using ms-sql and reading the following blog for guide.
This is my query
WITH parents(BranchCode, SOLD,BANKERSCOUNT, [TARGET]) AS
(
SELECT MS.ParentBranchCode,
SUM(NP.SOLD) SOLD,
SUM(NP.BANKERSCOUNT) BANKERSCOUNT,
SUM(NP.[TARGET]) [TARGET]
FROM NEDLLIFEPARTICIPATION NP
INNER JOIN m_Structure MS
ON MS.BranchCode = NP.BranchCode
GROUP BY MS.ParentBranchCode, NP.Year, NP.MONTH, NP.ProductId
)
Does this give you an error? If not then it might be that you simply have not included a select statement following your common table expression. This would explain why your error is showing an issue with the closing bracket, it is just telling you (if my assumption is right) that your CTE is not being used in a query (and therefore will not compile).
WITH parents(BranchCode, SOLD,BANKERSCOUNT, [TARGET]) AS
(
SELECT MS.ParentBranchCode,
SUM(NP.SOLD) SOLD,
SUM(NP.BANKERSCOUNT) BANKERSCOUNT,
SUM(NP.[TARGET]) [TARGET]
FROM NEDLLIFEPARTICIPATION NP
INNER JOIN m_Structure MS
ON MS.BranchCode = NP.BranchCode
GROUP BY MS.ParentBranchCode, NP.Year, NP.MONTH, NP.ProductId
)
select * from parents;

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

Pivot query causing "incorrect syntax" error in the PIVOT clause

I am getting the error, "incorrect syntax near 'Basic'" when I try to execute the following query:
WITH BaseQuery AS (
SELECT Region,Essbase_Channel,Product,COUNT(New_reconnects)
FROM NDW.dbo.SOS_Detail SOS
WHERE SOS.EntityID IN ('000310','000700','000815','000854')
AND Division ='NORTHEAST DIVISION' AND Month_Name ='MAR'
GROUP BY Month_Name,Product,Region,Essbase_Channel,EntityID,Division
)
SELECT * FROM BaseQuery
PIVOT (COUNT(New_reconnects) FOR Product IN ('BASIC','HSI','CDV','H1','X1')) AS PVT
ORDER BY Product,Region,Essbase_Channel
My goal would be to have the first column based on Essbase_Channel, the pivot columns to be Product values: BASIC, HSI, CDV, H1 and the values in the pivot to be COUNT(New_reconnects).
How should I change the syntax of the query to avoid this error?
Change to:
FOR Product IN ([BASIC],[HSI],[CDV],[H1],[X1])