从单行
abc
类型 ARRAY<STRING>
开始:
SELECT ARRAY ['a', 'b', 'c'] AS abc
如果我们使用
pyathena
执行查询:ArrowCursor
导入和参数在哪里:
cursor = pyathena.connect(**AWS_PARAMETERS).cursor(ArrowCursor)
execution_result = cursor.execute(query)
检查
import pyathena
from pyathena.arrow.cursor import ArrowCursor
AWS_PARAMETERS = {
'aws_access_key_id': ***,
'aws_secret_access_key': ***,
'region_name': ***,
's3_staging_dir': ***,
'work_group': ***,
}
:
execution_results
看来
execution_result.description
的列类型正确为
pyathena
:array
但是,当“具体化”pyarrow 表时:
[('abc', 'array', None, None, 0, 0, 'UNKNOWN')]
不幸的是,列内容变成了
table = execution_result.as_arrow()
而不是
STRING
:ARRAY<STRING>
我在这里想做的就是将该查询结果获取为具有
pyarrow.Table
abc: string
----
abc: [["[a, b, c]"]]
类型列的 Polars(或 Pandas)DataFrame。
我在这里缺少一种更好、更明显的方法来获得“正确的类型”吗?我真的应该自己将该字符串解析为字符串列表,还是将该字符串转换为 JSON,然后转换为字符串列表?
ARRAY<STRING>
正确实现了箭头表:
pyathena-3.0.10