From 31f8f6f015c9b45493ec728d2d45a393ccdb0501 Mon Sep 17 00:00:00 2001 From: zoey han Date: Mon, 16 Sep 2024 22:37:44 +0000 Subject: [PATCH] SNOW-1665697 Description Testing update version Description Testing --- src/snowflake/snowpark/files.py | 16 ++++++++++++++++ tests/unit/test_files.py | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/src/snowflake/snowpark/files.py b/src/snowflake/snowpark/files.py index bb8b700c933..4ed237ae88b 100644 --- a/src/snowflake/snowpark/files.py +++ b/src/snowflake/snowpark/files.py @@ -15,6 +15,8 @@ import sys from io import RawIOBase +from snowflake.snowpark._internal.utils import private_preview + # Python 3.8 needs to use typing.Iterable because collections.abc.Iterable is not subscriptable # Python 3.9 can use both # Python 3.10 needs to use collections.abc.Iterable because typing.Iterable is removed @@ -122,6 +124,20 @@ def isatty(self) -> None: """ raise NotImplementedError(_DEFER_IMPLEMENTATION_ERR_MSG) + @classmethod + @private_preview(version="1.22.1") + def open_new_result(cls, mode: str = "w") -> _SnowflakeFile: + """ + Returns a :class:`~snowflake.snowpark.file.SnowflakeFile`. + In UDF and Stored Procedures, the object works like a Python IOBase object and as a wrapper for an IO stream of remote files. The IO Stream is to support the file operations defined in this class. + + You can use this particular scoped URL to access files from within Snowflake (through another UDF or the COPY FILES command), but not from outside of Snowflake as a pre-signed URL. The scoped URL is valid for 24 hours. + + Args: + mode: A string used to mark the type of an IO stream. + """ + return cls("new results file", mode, require_scoped_url=0, from_result_api=True) + def read(self, size: int = -1) -> None: """ See https://docs.python.org/3/library/io.html#io.RawIOBase.read diff --git a/tests/unit/test_files.py b/tests/unit/test_files.py index 2ea3aa80268..b5864670022 100644 --- a/tests/unit/test_files.py +++ b/tests/unit/test_files.py @@ -6,6 +6,7 @@ import pytest +from snowflake.snowpark._internal.utils import private_preview from snowflake.snowpark.files import _DEFER_IMPLEMENTATION_ERR_MSG, SnowflakeFile @@ -14,6 +15,12 @@ def test_create_snowflakefile(): assert snowflake_file._file_location == "test_file_location" assert snowflake_file._mode == "r" +@private_preview(version="1.22.1") +def test_write_snowflakefile(): + with SnowflakeFile.open_new_result("w") as snowflake_file: + assert snowflake_file._file_location == "new results file" + assert snowflake_file._mode == "w" + def test_snowflake_file_attribute(): with SnowflakeFile.open("test_file_location") as snowflake_file: