如何解决Atoti的AtotiJavaException: Cannot make an array type non nullable异常
解决Atoti读取含numpy浮点数组列的DataFrame报错问题
问题重现
执行Atoti读取Pandas DataFrame的代码:
table = session.read_pandas(DF, keys=["col1",...."coln"], table_name="My_Table")
触发以下错误:
AtotiJavaException: Cannot make an array type non nullable. Field Type : FieldType(dataType=156032 -> Nullable double[], dataClass=class [D, defaultValueHolder=MultiTypeCell{codec=NULL, value=null})
解决方案
方案1:将numpy数组转换为Python原生列表
Atoti对Python原生列表的兼容性更强,先处理目标列的类型:
# 替换"array_col"为实际包含numpy数组的列名 DF["array_col"] = DF["array_col"].apply(lambda x: x.tolist() if x is not None else None) # 重新执行读取操作 table = session.read_pandas(DF, keys=["col1",...."coln"], table_name="My_Table")
方案2:显式指定列的可空数组类型
通过types参数强制声明该列为可空的浮点数组类型:
from atoti import Type table = session.read_pandas( DF, keys=["col1",...."coln"], table_name="My_Table", types={"array_col": Type.ARRAY(Type.DOUBLE, nullable=True)} )
报错原因
Atoti默认会将数组类型列标记为非可空,但你的数据中该列可能存在空值,或者numpy数组的类型映射导致Atoti无法自动识别其可空属性,进而触发类型冲突报错。上述两种方案分别通过类型转换或显式声明解决了这个问题。
内容的提问来源于stack exchange,提问作者Nicolas Velez
相关产品推荐
相关产品推荐

