英文:
Snowflake python sheet store file at stage
问题
我想将 xlsx 文件存储在 Snowflake 内部阶段,但出现以下错误:
Traceback (most recent call last):
Worksheet, line 17, in main
File "pandas/util/_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "pandas/util/_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "pandas/core/generic.py", line 2374, in to_excel
formatter.write(
File "pandas/io/formats/excel.py", line 944, in write
writer = ExcelWriter( # type: ignore[abstract]
File "pandas/io/excel/_xlsxwriter.py", line 205, in __init__
super().__init__(
File "pandas/io/excel/_base.py", line 1313, in __init__
self._handles = get_handle(
File "pandas/io/common.py", line 734, in get_handle
check_parent_directory(str(handle))
File "pandas/io/common.py", line 597, in check_parent_directory
raise OSError(rf"Cannot save file into a non-existent directory: '{parent}'")
OSError: Cannot save file into a non-existent directory: '@JV_TEST'
如何将文件存储到阶段?(我想使用 pandas 和 xlsxwriter,因为我想对 Excel 表格应用一些操作)
翻译完毕,不包括代码部分。
英文:
I have the following small test, where I would like to store a xlsx file at internal stage in snowflake:
import snowflake.snowpark as snowpark
import xlsxwriter
import pandas as pd
from snowflake.snowpark.functions import col
def main(session: snowpark.Session):
# Your code goes here, inside the "main" handler.
tableName = 'information_schema.packages'
dataframe = session.table(tableName).filter(col("language") == 'python')
x = dataframe.to_pandas()
unload_location = "@JV_TEST/jv.xlsx"
x.to_excel(unload_location)
# Print a sample of the dataframe to standard output.
dataframe.show()
# Return value will appear in the Results tab.
return dataframe
But I get the following error:
Traceback (most recent call last):
Worksheet, line 17, in main
File "pandas/util/_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "pandas/util/_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "pandas/core/generic.py", line 2374, in to_excel
formatter.write(
File "pandas/io/formats/excel.py", line 944, in write
writer = ExcelWriter( # type: ignore[abstract]
File "pandas/io/excel/_xlsxwriter.py", line 205, in __init__
super().__init__(
File "pandas/io/excel/_base.py", line 1313, in __init__
self._handles = get_handle(
File "pandas/io/common.py", line 734, in get_handle
check_parent_directory(str(handle))
File "pandas/io/common.py", line 597, in check_parent_directory
raise OSError(rf"Cannot save file into a non-existent directory: '{parent}'")
OSError: Cannot save file into a non-existent directory: '@JV_TEST'
How can I store the file at stage? (I would like to use pandas and xlsxwrite, because I would like to apply some stuff to the excel sheet)
答案1
得分: 2
目前不可能使用Python工作表写入阶段。
Python存储过程和UDFs的一般限制也适用于Python工作表。
这意味着您只能将文件写入/tmp
,一旦会话终止,文件将无法再从/tmp
访问。
您只能使用Python的内置函数如open()
来写入/tmp
,而不能使用外部函数如xlsxwriter
。
总的来说,使用Python操作存储在阶段上的文件是不可能的。
英文:
At this time it is not possible to write to a stage using Python Worksheets.
The general limitations from Python Stored Procedures and UDFs apply also to Python Worksheets.
This means you can only write files to /tmp
and once your session is terminated the files won't be accessible anymore from /tmp
.
You can only write to /tmp
using Python's built in functions like open()
, it doesn't work with external ones like xlsxwriter
.
As a general rule, manipulations of files stored on a stage using Python is not possible.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论