简体   繁体   English

从雪花查询到数据类型映射中的python数据框问题

[英]From Snowflake query to python dataframe problem in data type mapping

I have a problem casting data type from a snowflake query into pandas dataframe.我在将雪花查询中的数据类型转换为熊猫数据框时遇到问题。 I want to use the smaller data types as possible in order to reduce my memory usage.我想尽可能使用较小的数据类型以减少我的内存使用量。 Thus, I would like to have my pandas columns into int8 or int16 for integer, instead of the int64 that i have for the moment.因此,我想将我的 pandas 列放入 int8 或 int16 作为整数,而不是我目前拥有的 int64。

My problem is the following:我的问题如下:

From the snowflake documentation, we can read that: from a snowflake number we can cast in any integer type in python从雪花文档中,我们可以读到:从雪花数中,我们可以在 python 中转换为任何整数类型

I tried to cast my int columns in the following manner:我尝试按以下方式转换我的 int 列:

select myvariable::smallint
from mytable 

and

select myvariable::number(5,0) -- totaly arbitrary precision, depends on the column
from mytable 

which are supposed to be smaller data types.应该是较小的数据类型。

However, any of thoses solutions do not work and i still have int64 types in my pandas dataframe.但是,这些解决方案中的任何一个都不起作用,我的 pandas 数据框中仍然有 int64 类型。

I did not see any parameter to add in my snowflake connector, or in the query.我没有看到要在雪花连接器或查询中添加的任何参数。 I Know I can cast the data type directly in python, but I would like that the transformation is directly made from snowflake.我知道我可以直接在 python 中转换数据类型,但我希望转换是直接由雪花制成的。

If anyone know a solution for this, I would be very interested如果有人知道这个解决方案,我会很感兴趣

Snowflake's INTEGER data types are all INT64 actually. Snowflake 的 INTEGER 数据类型实际上都是 INT64。

The various names (SMALLINT like in your example) are to simplify porting from other systems and to suggest the expected range of values for a column of the specified type, but they are still INT64.各种名称(如您的示例中的 SMALLINT)是为了简化从其他系统的移植,并建议指定类型的列的预期值范围,但它们仍然是 INT64。

For more information have a look here .欲了解更多信息,请查看此处

You will have to cast the data type directly in Python.您必须直接在 Python 中转换数据类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM