Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Impala ODBC driver and python query with params

avatar
New Contributor

Hi folks,

 

I tried to submit a query with params via ODBC to Impala. Thi is my code:

 

 

 

import pyodbc

# connect
crsr = pyodbc.connect('DSN=impala', autocommit=True).cursor()
param1 = 1000000000
param2 = '2023-01-01'

# long query
query = """
select *
from target_test.test d 
left outer join 
  (select cli, fsc, nom_rag_soc, dat_ini_val, dat_ccz_inl, dat_csz_efv, dta_cessata, sta, prg_var, cod_cau_csz_dl, rn 
  from 
    (select 
      c2.cod_cli as cli, 
      trim(c2.cod_fsc) as fsc,
      trim(c2.nom_rag_soc) as nom_rag_soc,
      c2.dat_ini_val,
      dat_ccz_inl,
      dat_csz_efv, 
      (case when c2.dat_csz_efv= '1900-01-01 00:00:00' then '2999-01-01 00:00:00' else c2.dat_csz_efv end) as dta_cessata,
      sta,
      prg_var,
      cod_cau_csz_dl,
      row_number() over (partition by cod_fsc order by (case when c2.dat_csz_efv='1900-01-01 00:00:00' then '2999-01-01 00:00:00' else c2.dat_csz_efv end) desc) as rn
    from target_test.test2 c2 
    where  
      c2.sta='c' 
      and c2.dat_ini_val = (select max(c1.dat_ini_val) from target_test.test3 c1 where c1.sta='c' and c2.cod_cli=c1.cod_cli and c2.cod_fsc=c1.cod_fsc) 
      and prg_var = (select max(prg_var) from target_test.v_padln_t_cliente xc where c2.cod_cli = xc.cod_cli and sta ='c' and xc.dat_ini_val = c2.dat_ini_val) 
    ) a 
    where rn=1 
  ) k 
on trim(d.cod_fsc)=k.fsc
  where 
    d.prg_rig < ?
    and d.dat_cre_flu >= ?
    and d.tip_flu = 'f24';
"""

try:
  res = crsr.execute(query, param1, param2).fetchall
  print(res)
except pyodbc.Error as e:
  e.args = (e.args[1],)
  raise

 

 

 

But this is the output:

disoardi_0-1727356242556.png

I installed this driver: ClouderaImpalaODBC-2.7.1.1009-1.x86_64.rpm

If I try whit simple query, without subqueries, it works.

 

Any suggestions?

1 ACCEPTED SOLUTION

avatar
Community Manager

@disoardi, Welcome to our community! To help you get the best possible answer, I have tagged our Impala experts @ChethanYM @SVB @mszurap  who may be able to assist you further.

Please feel free to provide any additional information or details about your query, and we hope that you will find a satisfactory solution to your question.



Regards,

Vidya Sargur,
Community Manager


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community:

View solution in original post

1 REPLY 1

avatar
Community Manager

@disoardi, Welcome to our community! To help you get the best possible answer, I have tagged our Impala experts @ChethanYM @SVB @mszurap  who may be able to assist you further.

Please feel free to provide any additional information or details about your query, and we hope that you will find a satisfactory solution to your question.



Regards,

Vidya Sargur,
Community Manager


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community: