Skip to content

Commit 6fc3bee

Browse files
accept stage paths starting with / for GET (#2889)
1 parent f61e698 commit 6fc3bee

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
- Added support for creating a temporary view via `DataFrame.create_or_replace_temp_view` from a DataFrame created by reading a file from a stage.
7474
- Added support for `value_contains_null` parameter to MapType.
7575
- Added `interactive` to telemetry that indicates whether the current environment is an interactive one.
76+
- Allow `session.file.get` in a Native App to read file paths starting with `/` from the current version
7677

7778
#### Bug Fixes
7879

src/snowflake/snowpark/_internal/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@
6565

6666
STAGE_PREFIX = "@"
6767
SNOWURL_PREFIX = "snow://"
68+
RELATIVE_PATH_PREFIX = "/"
6869
SNOWFLAKE_PATH_PREFIXES = [
6970
STAGE_PREFIX,
7071
SNOWURL_PREFIX,
7172
]
73+
SNOWFLAKE_PATH_PREFIXES_FOR_GET = SNOWFLAKE_PATH_PREFIXES + [
74+
RELATIVE_PATH_PREFIX,
75+
]
7276

7377
# Scala uses 3 but this can be larger. Consider allowing users to configure it.
7478
QUERY_TAG_TRACEBACK_LIMIT = 3
@@ -372,7 +376,7 @@ def normalize_path(path: str, is_local: bool) -> str:
372376
a directory named "load data". Therefore, if `path` is already wrapped by single quotes,
373377
we do nothing.
374378
"""
375-
prefixes = ["file://"] if is_local else SNOWFLAKE_PATH_PREFIXES
379+
prefixes = ["file://"] if is_local else SNOWFLAKE_PATH_PREFIXES_FOR_GET
376380
if is_single_quoted(path):
377381
return path
378382
if is_local and OPERATING_SYSTEM == "Windows":
@@ -408,7 +412,7 @@ def split_path(path: str) -> Tuple[str, str]:
408412

409413
def unwrap_stage_location_single_quote(name: str) -> str:
410414
new_name = unwrap_single_quote(name)
411-
if any(new_name.startswith(prefix) for prefix in SNOWFLAKE_PATH_PREFIXES):
415+
if any(new_name.startswith(prefix) for prefix in SNOWFLAKE_PATH_PREFIXES_FOR_GET):
412416
return new_name
413417
return f"{STAGE_PREFIX}{new_name}"
414418

tests/unit/test_internal_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def test_split_path(path: str, expected_dir: str, expected_file: str) -> None:
6262
False,
6363
"'snow://domain/test_entity/versions/test_version/file.txt'",
6464
),
65+
("/some/file.yml", False, "'/some/file.yml'"),
66+
("'/some/file.yml'", False, "'/some/file.yml'"),
6567
],
6668
)
6769
def test_normalize_path(path: str, is_local: bool, expected: str) -> None:

0 commit comments

Comments
 (0)