trinodb / trino-python-client

Python client for Trino
Apache License 2.0
307 stars 151 forks source link

Null values are getting converted to None #362

Closed Raghav-254 closed 1 year ago

Raghav-254 commented 1 year ago

Expected behavior

Null values in the dataset should remain as null.

Actual behavior

Null values are getting converted to None

Steps To Reproduce

You can take any dataset having null value, it will automatically get converted to None. For instance refer the below process:

  1. Create a table CREATE TABLE IF NOT EXISTS null_data ( c1 row(id VARCHAR, id1 VARCHAR), c2 VARCHAR );
  2. Insert values into the table INSERT INTO null_data VALUES (ROW('a', 'b'), NULL); INSERT INTO null_data VALUES (NULL, 'c');
  3. Run the select query select * from null_data

Expected output should have NULL values in it, but the NULL values got replaced by None.

Log output

No response

Operating System

NA

Trino Python client version

0.322.0

Trino Server version

NA

Python version

5.10

Are you willing to submit PR?

mdesmet commented 1 year ago

IMHO this is working as expected, None is the Python equivalent of a SQL null value.

Raghav-254 commented 1 year ago

Yes, None is equivalent to SQL null. But is it possible to remain it as null, because currently it is changing the dataset, and is against the SQL standard. Also other clients for example trino-cli keep this as it is and doesn't convert null to none.

hashhar commented 1 year ago

If you want to retrieve results as strings you can disable the behaviour which maps results to Python type by enabling the legacy mode https://github.com/trinodb/trino-python-client#legacy-primitive-types.