Skip to content

Commit

Permalink
Add overwrite and parallel arguments to put_stage command (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-zblackwood authored Jan 13, 2023
1 parent 88a7a3b commit 27b6902
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/snowcli/cli/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path

import typer

from snowcli import config
from snowcli.config import AppConfig
from snowcli.utils import print_db_cursor
Expand Down Expand Up @@ -85,9 +86,17 @@ def stage_put(
dir_okay=True,
writable=True,
resolve_path=True,
help="Directory location to store downloaded files",
help="File or directory to upload to stage",
),
name: str = typer.Argument(..., help="Stage name"),
overwrite: bool = typer.Option(
False,
help="Overwrite existing files in stage",
),
parallel: int = typer.Option(
4,
help="Number of parallel threads to use for upload",
),
):
"""
Upload files to a stage from a local client
Expand All @@ -107,5 +116,7 @@ def stage_put(
warehouse=env_conf.get("warehouse"),
name=name,
path=str(filepath),
overwrite=overwrite,
parallel=parallel,
)
print_db_cursor(results)
7 changes: 6 additions & 1 deletion src/snowcli/snow_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from io import StringIO

import snowflake.connector
from snowcli.snowsql_config import SnowsqlConfig
from snowflake.connector.cursor import SnowflakeCursor

from snowcli.snowsql_config import SnowsqlConfig


class SnowflakeConnector:
"""Initialize a connection from a snowsql-formatted config"""
Expand Down Expand Up @@ -300,6 +301,8 @@ def putStage(
warehouse,
name,
path,
overwrite: bool = False,
parallel: int = 4,
) -> SnowflakeCursor:
return self.runSql(
"put_stage",
Expand All @@ -310,6 +313,8 @@ def putStage(
"warehouse": warehouse,
"name": name,
"path": path,
"overwrite": overwrite,
"parallel": parallel,
},
)

Expand Down
2 changes: 1 addition & 1 deletion src/snowcli/sql/put_stage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ use warehouse {warehouse};
use database {database};
use schema {schema};

put file://{path} @{name} auto_compress=false;
put file://{path} @{name} auto_compress=false parallel={parallel} overwrite={overwrite};

0 comments on commit 27b6902

Please sign in to comment.