-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SNOW-919476: Do not ignore stage location for using imports when is_permanent is False #1053
Changes from 5 commits
0e1d2a2
928abfb
b7b873d
082bc85
453c0a6
a5e1195
61a3bfa
23d5f5c
1171dee
7c4107a
747f171
06bc8d2
8f55183
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -685,7 +685,8 @@ def _resolve_import_path( | |
|
||
def _resolve_imports( | ||
self, | ||
stage_location: str, | ||
import_stage: str, | ||
upload_stage: str, | ||
udf_level_import_paths: Optional[ | ||
Dict[str, Tuple[Optional[str], Optional[str]]] | ||
] = None, | ||
|
@@ -695,9 +696,11 @@ def _resolve_imports( | |
"""Resolve the imports and upload local files (if any) to the stage.""" | ||
resolved_stage_files = [] | ||
stage_file_list = self._list_files_in_stage( | ||
stage_location, statement_params=statement_params | ||
import_stage, statement_params=statement_params | ||
) | ||
normalized_stage_location = unwrap_stage_location_single_quote(stage_location) | ||
# probably shouldn't do it. It is already done in resolve_imports_and_pacakges | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove this comment if we already have tests :p |
||
normalized_import_location = unwrap_stage_location_single_quote(import_stage) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we verify if this could lead to bugs (e.g. over-unwrapping)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are some tests in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added more tests. Overwrapping does not lead to bugs |
||
normalized_upload_location = unwrap_stage_location_single_quote(upload_stage) | ||
|
||
import_paths = udf_level_import_paths or self._import_paths | ||
for path, (prefix, leading_path) in import_paths.items(): | ||
|
@@ -713,7 +716,12 @@ def _resolve_imports( | |
filename_with_prefix = f"{prefix}/{filename}" | ||
if filename_with_prefix in stage_file_list: | ||
_logger.debug( | ||
f"{filename} exists on {normalized_stage_location}, skipped" | ||
f"{filename} exists on {normalized_import_location}, skipped" | ||
) | ||
resolved_stage_files.append( | ||
normalize_remote_file_or_dir( | ||
f"{normalized_import_location}/{filename_with_prefix}" | ||
) | ||
) | ||
else: | ||
# local directory or .py file | ||
|
@@ -723,7 +731,7 @@ def _resolve_imports( | |
) as input_stream: | ||
self._conn.upload_stream( | ||
input_stream=input_stream, | ||
stage_location=normalized_stage_location, | ||
stage_location=normalized_upload_location, | ||
dest_filename=filename, | ||
dest_prefix=prefix, | ||
source_compression="DEFLATE", | ||
|
@@ -736,17 +744,17 @@ def _resolve_imports( | |
else: | ||
self._conn.upload_file( | ||
path=path, | ||
stage_location=normalized_stage_location, | ||
stage_location=normalized_upload_location, | ||
dest_prefix=prefix, | ||
compress_data=False, | ||
overwrite=True, | ||
skip_upload_on_content_match=True, | ||
) | ||
resolved_stage_files.append( | ||
normalize_remote_file_or_dir( | ||
f"{normalized_stage_location}/{filename_with_prefix}" | ||
resolved_stage_files.append( | ||
normalize_remote_file_or_dir( | ||
f"{normalized_upload_location}/{filename_with_prefix}" | ||
) | ||
) | ||
) | ||
|
||
return resolved_stage_files | ||
|
||
|
@@ -1707,7 +1715,6 @@ def connection(self) -> "SnowflakeConnection": | |
and Snowflake server.""" | ||
return self._conn._conn | ||
|
||
|
||
def _run_query( | ||
self, | ||
query: str, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's define import_stage first then
upload_stage = import_stage if is_permanent else session_stage
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there's a better name for
upload_stage
, because technically we need to upload files toimport_stage
too. How about something likesproc_stage
vsimport_stage
?In addition, could you please add a one line documentation for these args to clarify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your point but the stage is used for udfs as well. How about
import_only_stage
andupload_and_import_stage
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we upload files to import stage, but it is the other way around (we import the upload stage). And as Afroz mentioned, the import/upload difference is application to UDF families as well. I cannot come up with a better name than what Afroz suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done