当前位置:   article > 正文

Java Integer,Python int和系统最大整数值_als only supports values in integer range for colu

als only supports values in integer range for columns userid and movieid. va

问题

在使用pyspark运行Spark ALS算法时,发生以下问题:

java.lang.IllegalArgumentException: ALS only supports values in Integer range and without fractional part for columns userId and softId. Value 13466056057 was either out of Integer range or contained a fractional part that could not be converted.
  • 1

分析

输出信息提示,13466056057超出Integer类型范围,或者是一个小数。很明显,13466056057不是一个小数,那就是说超出了Integer类型范围。

Java Integer取值范围是:[-2147483648, 2147483647]

获取方式:Integer.MAX_VALUEInteger.MIN_VALUE

解决

这个是数据ETL逻辑缺陷导致的,ETL逻辑是用Python写的,增加符合Java Integer类型的合法性检查即可。而对于现有的ETL之后的数据进行一次清理,将不合法的记录删除,重新运行任务。

其他

经过测试,在Python中,int类型的数据貌似是没有范围限制的,这个以前倒是没有注意过。

另外sys.maxsize是系统的整数最大值,64位系统中,输出如下:

>>> import sys
>>> print(sys.maxsize)
9223372036854775807
  • 1
  • 2
  • 3

实测Python int转换:

>>> print(int('92233720368547758070'))
92233720368547758070
>>> print(int('922337203685477580700'))
922337203685477580700
  • 1
  • 2
  • 3
  • 4
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/772815
推荐阅读
相关标签
  

闽ICP备14008679号