snowflake.snowpark.FileOperation.copy_files¶
- FileOperation.copy_files(source: Union[str, DataFrame], target_stage_location: str, *, files: Optional[List[str]] = None, pattern: Optional[str] = None, detailed_output: bool = True, statement_params: Optional[Dict[str, str]] = None) Union[List[str], int][source]¶
Copy files from a source location to an output stage.
You can use either a stage location (
str) or a DataFrame as the source:DataFrame source: The DataFrame must have exactly one or two columns of string type. Column names are not significant; Snowflake interprets columns by position:
First column (required): The existing url of the source file location (scoped URL, stage name, or stage URL).
Second column (optional): Then new file name which is the relative output path from the
targetstage. The file is copied to@[<namespace>.]<stage_name>[/<path>]<new_filename>.
If the second column is not provided, Snowflake uses the relative path of the first column’s value. Invalid input (for example, missing the first column, non-string values, or extra columns) is rejected by Snowflake and results in a server-side error.
Stage location source: Provide a stage location string for
source. You can optionally usefilesorpatternto restrict which files are copied.
References: Snowflake COPY FILES command.
- Parameters:
source – The source to copy from. Either a stage location string, or a DataFrame with 1–2 string columns where the first column is required (existing url) and the second column is optional (new file name).
target – The target stage and path where files will be copied.
files – Optional list of specific file names to copy; only applicable when
sourceis a stage location string.pattern – Optional regular expression pattern for filtering files to copy; only applicable when
sourceis a stage location string.detailed_output – If True, returns details for each file; if False, returns only the number of files copied. Defaults to True.
statement_params – Dictionary of statement level parameters to be set while executing this action.
Examples
- Returns:
If
detailed_outputis True, alist[str]of copied file paths. Otherwise, anintindicating the number of files copied.