Skip to content

Commit

Permalink
Move path splitting to helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dhung committed Apr 3, 2024
1 parent 17a0a85 commit bc86e8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/snowflake/snowpark/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ def normalize_local_file(file: str) -> str:
return normalize_path(file, is_local=True)


def split_path(path: str) -> Tuple[str, str]:
"""Split a file path into directory and file name."""
path = unwrap_single_quote(path)
return path.rsplit("/", maxsplit=1)


def unwrap_stage_location_single_quote(name: str) -> str:
new_name = unwrap_single_quote(name)
if any(new_name.startswith(prefix) for prefix in SNOWFLAKE_PATH_PREFIXES):
Expand Down
10 changes: 3 additions & 7 deletions src/snowflake/snowpark/file_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
normalize_local_file,
normalize_remote_file_or_dir,
result_set_to_rows,
unwrap_single_quote,
split_path,
)


Expand Down Expand Up @@ -274,9 +274,7 @@ def put_stream(
)
raise ne.with_traceback(tb) from None
else:
stage_with_prefix, dest_filename = unwrap_single_quote(
stage_location
).rsplit("/", maxsplit=1)
stage_with_prefix, dest_filename = split_path(stage_location)
put_result = self._session._conn.upload_stream(
input_stream=input_stream,
stage_location=stage_with_prefix,
Expand Down Expand Up @@ -341,9 +339,7 @@ def get_stream(
else:
options = {"parallel": parallel}
tmp_dir = tempfile.gettempdir()
src_file_name = unwrap_single_quote(stage_location).rsplit("/", maxsplit=1)[
1
]
src_file_name = split_path(stage_location)[1]
local_file_name = os.path.join(tmp_dir, src_file_name)
plan = self._session._plan_builder.file_operation_plan(
"get",
Expand Down

0 comments on commit bc86e8f

Please sign in to comment.