Created
October 8, 2023 18:22
-
-
Save jonashaag/0a620291ed84ca906da9714e44de46f4 to your computer and use it in GitHub Desktop.
Snowflake Connector Python download table or query as Parquet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def unload_to_parquet(query: str, target_dir: Path, conn, stage_name: str = "unload_stage"): | |
conn.execute(f"CREATE TEMP STAGE {stage_name}") | |
conn.execute(f"COPY INTO @{stage_Name} FROM ({query}) file_format=(type='parquet') header=true") | |
target_dir.mkdir(parents=True) | |
conn.execute(f"GET @{stage_name} file://{str(target_dir)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment