-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SNOW-427759: fetch_pandas_all not using int64 for NUMBER(38, 0) #828
Comments
Aha, this only seems to happen when doing a |
@jonashaag, we're looking into this. In the meanwhile, given your comment above, can you provide sample code and observed behavior without the result_scan ? |
Here's a minimal example. # eng is SQLAlchemy engine object
>>> eng.execute("create table xxx.snow427759 (x number(38,0))")
>>> eng.execute("insert into xxx.snow427759 (x) values (1)")
>>> res = eng.connect().execute("select * from xxx.snow427759")
>>> res.cursor._result._fetch_arrow_all()
pyarrow.Table
X: int8
>>> res2 = eng.connect().execute(f"select * from table(result_scan('{res.cursor.sfqid}'))")
>>> res2.cursor._result._fetch_arrow_all()
pyarrow.Table
X: decimal(38, 0) |
@jonashaag I tried reproducing your issue , I found that the following worked as expected. import snowflake.connector
import pyarrow
config = {...}
with snowflake.connector.connect(
**config,
) as cnx:
with cnx.cursor() as cur:
cur.execute("select 1::number(38,0) as x")
res = cur.fetch_arrow_all()
assert pyarrow.types.is_int8(res["X"].type)
sfqid = cur.sfqid
cur.execute(f"select * from table(result_scan('{sfqid}'))")
res = cur.fetch_arrow_all()
assert pyarrow.types.is_int8(res["X"].type) I tried using a table and also running the |
Interesting. I can reproduce the behaviour with connector versions 2.4, 2.5, 2.6, using the following script: import snowflake.connector
import pyarrow
config = ...
with snowflake.connector.connect(
**config,
) as cnx:
with cnx.cursor() as cur:
cur.execute("select 1::number(38,0) as x")
try:
res = cur.fetch_arrow_all()
except:
res = cur._result._fetch_arrow_all()
assert pyarrow.types.is_int8(res["X"].type), res["X"].type
sfqid = cur.sfqid
# Same behaviour with or without new conn.
# with snowflake.connector.connect(
# **config,
# ) as cnx:
# with cnx.cursor() as cur:
cur.execute(f"select * from table(result_scan('{sfqid}'))")
try:
res = cur.fetch_arrow_all()
except:
res = cur._result._fetch_arrow_all()
assert pyarrow.types.is_int8(res["X"].type), res["X"].type
|
@jonashaag I copy pasted your code snippet and I cannot reproduce your issue. If you could post those here I could take a look. If you are not comfortable doing that then please open a support ticket with a link to this issue and then we can have a private communication channel that way. |
Query ID of Query ID of |
Sorry, it took me a while to get to this.
What happens is that when you have a sub-query (I suspect this to be more complicated and it really depends on the available metadata at the time of query execution) Snowflake is unable to tell the maximum number in a row. So it defaults to the type that could hold the maximum value. We allow up to 38 digits, which does not fit into a 64 bit integer, so we'll probably need to go to 128 bits. The only mitigations that I see:
Edit: I never included the script's output:
|
I wonder why this doesn’t happen in the original query but only in the result scan. Is that because it is a sub query? Could the Snowflake backend be taught to use the original query’s metadata for the result scan query? |
To clean up and re-prioritize bugs and feature requests we are closing all issues older than 6 months as of March 1, 2023. If there are any issues or feature requests that you would like us to address, please re-create them. For urgent issues, opening a support case with this link Snowflake Community is the fastest way to get a response |
Connector version 2.5.1.
X
is aNUMBER(38, 0)
column with values that fit intoint8
. It is fetched as decimal number rather than int64, unless you explicitly cast toNUMBER(18, 0)
:The text was updated successfully, but these errors were encountered: