Support Questions

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

straight SELECT and SELECT via CTE produce different results

avatar
Explorer

I ran into an issue last week, which seems to be an issue related to the Cloudera ODBC Driver for Impala.

 

First I thought it was an issue with pyodbc, but after submitting the issue on their github we figured out that it was a driver issue. For reference: pyodbc github issue 1197

 

Simply put, executing query1 and query2 should produce the same results, but it doesn't:

 

query1 = """SELECT
    col1, col2 as col2_orig, 
    (CASE WHEN col2 IS NOT NULL THEN col2
        ELSE 0 END) AS col2_1,
    (CASE WHEN col2 IS NULL THEN 0
        ELSE col2 END) AS col2_2
    FROM  sandbox.jk_test"""

query2 = f"""WITH wrapped_table AS ({query1}) SELECT * FROM wrapped_table"""

 

It results in two different sets:

 

['col1', 'col2_orig', 'col2_1', 'col2_2']
['1   ', '1        ', '1     ', '1     ']
['2   ', 'None     ', 'None  ', '0     ']

['col1', 'col2_orig', 'col2_1', 'col2_2']
['1   ', '1        ', '1     ', '1     ']
['2   ', 'None     ', '0     ', '0     ']

 

The 2nd result is the expected one.

* See the github issue for the code used to run these queries.

 

 

Running the queries with CData's driver solves the issue, as does connecting using a JDBC connection.

My Environment:

  • Python: Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)]
  • OS: Windows 10 Enterprise 20H2 64-bit
  • driver: Cloudera ODBC Driver for Impala 2.06.16.1022
  • Windows Script Host Version 5.812 (for vbs script)
1 ACCEPTED SOLUTION

avatar

Hi @JKarount ,

To close the loop, this has been resolved in the latest Cloudera Impala ODBC driver 2.7.0, see the Resolved Issues section in the Release Notes:
https://docs.cloudera.com/documentation/other/connectors/impala-odbc/2-7-0/Release-Notes-Impala-ODBC... 

"[IMP-946][02795738] The connector does not generate the last COALESCE
parameter from the ELSE expression in the CASE statement."

You can download it from:

https://www.cloudera.com/downloads/connectors/impala/odbc/2-7-0.html 

I hope this will help you to implement your usecases as expected.

Best regards

 Miklos Szurap

Customer Operations Engineer, Cloudera

View solution in original post

10 REPLIES 10

avatar
Community Manager

@JKarount, If any of the replies from @mszurap  has helped you reach a solution, can you please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future?  



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: