Support Questions

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

Hive odbc with prepared statements: ParseException

avatar
Expert Contributor

Context: Hive3, HDP 3.1. Tests done with Python/odbc (official HDP driver) under Windows and Linux.

I ran the following queries:

  1. "select ? as lic, ? as cpg"
  2. "select * from (select ? as lic, ? as cpg) as t"
  3. "with init as (select ? as lic, ? as cpg) select * from init",

1) and 2) work fine, and give me the expected result. 3 gives me a ParseException :

Error while compiling statement: FAILED: ParseException line 1:21 cannot recognize input near '?' 'as' 'lic' in select clause (80) (SQLPrepare)")

The exact same statements ran with java/jdbc work fine. Note that 2) looks like is a workaround for 3) but it works for this tiny example, not for bigger queries.

Is there something I can do to have ODBC working as expected? Alternatively, where can I find the limits of the ODBC driver?

For full context, the full test code is as follow:

cnxnstr = 'DSN=HiveProd'
cnxn = pyodbc.connect(cnxnstr, autocommit=True)

cursor = cnxn.cursor()
queries = [ 
    "with init as (select ? as lic, ? as cpg) select * from init", 
    "select 2 * ? as lic, ? as cpg", 
    "select * from (select ? as lic, ? as cpg) as t", 
]

for q in queries:
    print("\nExecuting " + q)
    try:
        cursor.execute(q, '1', '2')
    except pyodbc.ProgrammingError as e:
        print(e)
        continue
1 ACCEPTED SOLUTION

avatar
Expert Contributor
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login
1 REPLY 1

avatar
Expert Contributor
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login