Pyathena to_sql 创建空表
我试图将 df 写入 Athena,但创建的表始终为空。我使用python 3.8和windows 11系统。我使用 pyathena 将数据帧写入 Athena,但到目前为止从未出现过问题。
from pyathena import connect
from pyathena.pandas.util import to_sql
conn = connect(aws_access_key_id="KEY",
aws_secret_access_key="SKEY",
s3_staging_dir="STAGINGDIR", # query location dir
region_name="eu-central-1")
to_sql(df,
"TABLENAME",
conn,
"MYS3PATH",
schema="MYSCHEMA",
index=False,
if_exists="replace"
)
I am trying to write a df into Athena, but the created table is always empty. I use python 3.8 and windows 11 system. I use pyathena writing dataframes to Athena but problems have never occurred till now.
from pyathena import connect
from pyathena.pandas.util import to_sql
conn = connect(aws_access_key_id="KEY",
aws_secret_access_key="SKEY",
s3_staging_dir="STAGINGDIR", # query location dir
region_name="eu-central-1")
to_sql(df,
"TABLENAME",
conn,
"MYS3PATH",
schema="MYSCHEMA",
index=False,
if_exists="replace"
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您在 S3 路径末尾遗漏“/”时,通常会发生这种情况。
我通常在将 var 传递给 to_sql 之前使用一个函数来格式化 s3 路径,无论如何只是为了确定。
这应该有效。
This usually happens when you miss a '/' at the end of the S3 Path.
I usually use a function to format the s3 path at right before passing the var to to_sql no matter what just to be sure.
This should work.