Skip to content

Commit

Permalink
add regx for anonymous procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-yuwang committed Sep 17, 2024
1 parent 791cf2a commit b458a85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/snowflake/snowpark/profiler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
#
import re
from contextlib import contextmanager
from typing import List, Optional

Expand Down Expand Up @@ -109,8 +110,11 @@ def disable_profiler(self):
self.session.sql(self.disable_profiler_sql).collect()

def _get_last_query_id(self):
pattern = r"WITH\s+.*?\s+AS\s+PROCEDURE\s+.*?\s+CALL\s+.*"
for query in self.query_history.queries[::-1]:
if query.sql_text.startswith("CALL"):
if query.sql_text.startswith("CALL") or re.match(
pattern, query.sql_text, re.DOTALL
):
return query.query_id
return None

Expand Down
18 changes: 18 additions & 0 deletions tests/integ/test_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,21 @@ def single_value_sp(session: snowflake.snowpark.Session) -> str:
session.register_profiler_modules([])
assert res is not None
assert "Modules Profiled" in res


def test_anonymous_procedure(session, db_parameters):
def single_value_sp(session: snowflake.snowpark.Session) -> str:
return "success"

single_value_sp = session.sproc.register(single_value_sp, anonymous=True)
session.register_profiler_modules(["table_sp"])
with profiler(
stage=f"{db_parameters['database']}.{db_parameters['schema']}.{tmp_stage_name}",
active_profiler="LINE",
session=session,
):
single_value_sp()
res = session.show_profiles()
session.register_profiler_modules([])
assert res is not None
assert "Modules Profiled" in res

0 comments on commit b458a85

Please sign in to comment.