从 MYSQL 查询时出现 dask read_sql 错误

dask read_sql error when querying from MYSQL

我正在使用 python 2.7 和 dask 并尝试从远程机器查询数据库 table 到 dask 数据帧

我在 table 中有一个多列索引,我尝试使用以下脚本读取它

ddf = dd.read_sql_table("table name", "mysql://user:pass@ip:port/Dbname",spesific column name).head()

并出现以下错误

start = asanyarray(start) * 1.0 TypeError: ufunc 'multiply' did not contain a loop with signature matching types dtype('S32')

dtype('S32') dtype('S32')

我按照说明获得了 sqlalchemy uri here

我不确定是什么问题,当我尝试通过另一列作为索引进行查询,并且只使用 ddf head() 时,我没有得到错误,当我尝试计算整个 ddf 我得到同样的错误,我认为这是一个关于列不是唯一值的问题,我没有单列索引,而是多列,在这里读取整个 table 的解决方案是什么?

谢谢。

完整追溯

> Traceback (most recent call last):   File "path", line 28, in <module>
>     ddf = dd.read_sql_table("tablename", "mysql://user:pass@ip:port/dbname","indexcolumn")   File "file", line
> 123, in read_sql_table
>     divisions = np.linspace(mini, maxi, npartitions + 1).tolist()   File
> "/home/user/.local/lib/python2.7/site-packages/numpy/core/function_base.py",
> line 108, in linspace
>     start = asanyarray(start) * 1.0 TypeError: ufunc 'multiply' did not contain a loop with signature matching types dtype('S32')
> dtype('S32') dtype('S32')

对于您没有提供更多信息或仅指定分区数的情况,read_sql_table中的分区逻辑仅适用于数字,因为我们需要一种在最小值和最大值之间进行有序划分的方法.

显然,但查询(获取 max/min)正在为这种情况返回一个字符串。 read_sql_table 仍然可以工作,但您需要自己定义要拆分的部门,并为其提供部门关键字,例如,

ddf = dd.read_sql_table("table name", "mysql://user:pass@ip:port/Dbname", 
    'index_col', divisions=['aardvark', 'llama', 'tapir', 'zebra']).head()

或者,有问题的字符串看起来确实像一个数字,因此您可能需要更新 table 的架构以确保它被解释为一个数字。