Closed maskarb closed 1 year ago
The issue seems to be with the Trino server not recognizing the decimal literal '0E-10' as a valid decimal. One possible solution is to represent the decimal as a string instead of using scientific notation. You can try changing the query parameter to the string '0.0', which should be equivalent to the decimal 0E-10. Another solution could be to update the Trino server to recognize scientific notation for decimals, if possible. If you are willing to submit a pull request, you can also try to update the Trino Python client to handle scientific notation for decimals.
In the Trino Python client, we're doing the Decimal conversion here: https://github.com/trinodb/trino-python-client/blob/master/trino/dbapi.py#L457-L458
if isinstance(param, Decimal):
return "DECIMAL '%s'" % param
I was thinking of just converting the Decimal to a float and using the same logic for floats which is here: https://github.com/trinodb/trino-python-client/blob/master/trino/dbapi.py#L404-L411
if isinstance(param, float):
if param == float("+inf"):
return "infinity()"
if param == float("-inf"):
return "-infinity()"
if math.isnan(param):
return "nan()"
return "DOUBLE '%s'" % param
My only issue with doing that is I don't know the difference between DOUBLE
and DECIMAL
. We could just copy the logic and do this:
if isinstance(param, Decimal):
param = float(param)
if param == float("+inf"):
return "infinity()"
if param == float("-inf"):
return "-infinity()"
if math.isnan(param):
return "nan()"
return "DECIMAL '%s'" % param
But I'm just not sure.
Trino implicitly converts literals with scientific notation to DOUBLE. DECIMAL literals cannot use scientific notation.
Maybe we can detect this on the Python client side and normalize the literal to use decimal instead of scientific notation.
Expected behavior
In Python, Decimals can be represented with
e
orE
(e.g.Decimal('0E-10')
). When the Trino client receives a Decimal like this one, it should successfully convert the value to something Trino can process.Actual behavior
Given a basic sql query (
SELECT ?
) with the param ([Decimal('0E-10')]
), the Trino client prepared and executed the following:which results in the following error:
Steps To Reproduce
Log output
I've attached the
.json
output from the Trino UI.query.json.txt
Operating System
RHEL
Trino Python client version
0.321.0
Trino Server version
405
Python version
Python 3.9.13
Are you willing to submit PR?