Skip to content

Commit 1a2bf40

Browse files
authored
Added file execute log for stage and git (#2139)
1 parent b34590a commit 1a2bf40

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

RELEASE-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
* Change binary builds to embed whole Python environment.
4343
* Fixed recursive copying to stage for unbalanced directory trees.
4444
* Fixed checking for new CLI version.
45+
* Added file execution log in stage and git commands.
4546

4647
# v3.5.0
4748

src/snowflake/cli/_plugins/stage/manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ def _call_execute_immediate(
707707
original_file: str,
708708
) -> Dict:
709709
try:
710+
log.info("Executing SQL file: %s", file_stage_path)
710711
query = f"execute immediate from {self.quote_stage_name(file_stage_path)}"
711712
if variables:
712713
query += variables
@@ -820,6 +821,7 @@ def _execute_python(
820821
from snowflake.snowpark.exceptions import SnowparkSQLException
821822

822823
try:
824+
log.info("Executing Python file: %s", file_stage_path)
823825
self._python_exe_procedure(self.get_standard_stage_prefix(file_stage_path), variables, session=self.snowpark_session) # type: ignore
824826
return StageManager._success_result(file=original_file)
825827
except SnowparkSQLException as e:

tests/git/test_git_commands.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ def test_execute(
588588
expected_stage,
589589
expected_files,
590590
os_agnostic_snapshot,
591+
caplog,
591592
):
592593
mock_execute.return_value = mock_cursor(
593594
[
@@ -602,20 +603,18 @@ def test_execute(
602603

603604
assert result.exit_code == 0, result.output
604605
create_call, copy_call, ls_call, *execute_calls = mock_execute.mock_calls
606+
stage = "FOO.BAR.snowflake_cli_tmp_stage_123"
605607
assert create_call == mock.call(
606-
"create temporary stage if not exists IDENTIFIER('FOO.BAR.snowflake_cli_tmp_stage_123')"
607-
)
608-
assert copy_call == mock.call(
609-
f"copy files into @FOO.BAR.snowflake_cli_tmp_stage_123/ from {expected_stage}/"
610-
)
611-
assert ls_call == mock.call(
612-
f"ls @FOO.BAR.snowflake_cli_tmp_stage_123", cursor_class=DictCursor
608+
f"create temporary stage if not exists IDENTIFIER('{stage}')"
613609
)
610+
assert copy_call == mock.call(f"copy files into @{stage}/ from {expected_stage}/")
611+
assert ls_call == mock.call(f"ls @{stage}", cursor_class=DictCursor)
614612
assert execute_calls == [
615-
mock.call(f"execute immediate from @FOO.BAR.snowflake_cli_tmp_stage_123{p}")
616-
for p in expected_files
613+
mock.call(f"execute immediate from @{stage}{p}") for p in expected_files
617614
]
618615
assert result.output == os_agnostic_snapshot
616+
for expected_file in expected_files:
617+
assert f"Executing SQL file: @{stage}{expected_file}" in caplog.messages
619618

620619

621620
@pytest.mark.parametrize(
@@ -658,6 +657,7 @@ def test_execute_new_git_repository_list_files(
658657
expected_stage,
659658
expected_files,
660659
os_agnostic_snapshot,
660+
caplog,
661661
):
662662
mock_execute.return_value = mock_cursor(
663663
[
@@ -672,20 +672,18 @@ def test_execute_new_git_repository_list_files(
672672

673673
assert result.exit_code == 0, result.output
674674
create_call, copy_call, ls_call, *execute_calls = mock_execute.mock_calls
675+
stage = "FOO.BAR.snowflake_cli_tmp_stage_123"
675676
assert create_call == mock.call(
676-
"create temporary stage if not exists IDENTIFIER('FOO.BAR.snowflake_cli_tmp_stage_123')"
677-
)
678-
assert copy_call == mock.call(
679-
f"copy files into @FOO.BAR.snowflake_cli_tmp_stage_123/ from {expected_stage}/"
680-
)
681-
assert ls_call == mock.call(
682-
f"ls @FOO.BAR.snowflake_cli_tmp_stage_123", cursor_class=DictCursor
677+
f"create temporary stage if not exists IDENTIFIER('{stage}')"
683678
)
679+
assert copy_call == mock.call(f"copy files into @{stage}/ from {expected_stage}/")
680+
assert ls_call == mock.call(f"ls @{stage}", cursor_class=DictCursor)
684681
assert execute_calls == [
685-
mock.call(f"execute immediate from @FOO.BAR.snowflake_cli_tmp_stage_123{p}")
686-
for p in expected_files
682+
mock.call(f"execute immediate from @{stage}{p}") for p in expected_files
687683
]
688684
assert result.output == os_agnostic_snapshot
685+
for expected_file in expected_files:
686+
assert f"Executing SQL file: @{stage}{expected_file}" in caplog.messages
689687

690688

691689
@pytest.mark.parametrize(

tests/stage/test_stage.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ def test_execute(
815815
expected_stage,
816816
expected_files,
817817
os_agnostic_snapshot,
818+
caplog,
818819
):
819820
mock_execute.return_value = mock_cursor(
820821
[
@@ -835,6 +836,8 @@ def test_execute(
835836
mock.call(f"execute immediate from {p}") for p in expected_files
836837
]
837838
assert result.output == os_agnostic_snapshot
839+
for expected_file in expected_files:
840+
assert f"Executing SQL file: {expected_file}" in caplog.messages
838841

839842

840843
@pytest.mark.parametrize(
@@ -855,6 +858,7 @@ def test_execute_from_user_stage(
855858
stage_path,
856859
expected_files,
857860
snapshot,
861+
caplog,
858862
):
859863
mock_execute.return_value = mock_cursor(
860864
[
@@ -875,6 +879,8 @@ def test_execute_from_user_stage(
875879
mock.call(f"execute immediate from '{p}'") for p in expected_files
876880
]
877881
assert result.output == snapshot
882+
for expected_file in expected_files:
883+
assert f"Executing SQL file: {expected_file}" in caplog.messages
878884

879885

880886
@mock.patch(f"{STAGE_MANAGER}.execute_query")

0 commit comments

Comments
 (0)