Skip to content

Commit a31a1a5

Browse files
SNOW-2347456 Properly escape _ and % in snow logs --partial (#2616)
1 parent 7a6f267 commit a31a1a5

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ def get_raw_logs(
9696
# Build the object name condition based on partial_match flag
9797
if partial_match:
9898
# Use ILIKE for case-insensitive partial matching with wildcards
99-
escaped_pattern = escape_like_pattern(escaped_object_name)
99+
escaped_pattern = escape_like_pattern(
100+
escaped_object_name, escape_sequence="\\"
101+
)
100102
object_condition = f"object_name ILIKE '%{escaped_pattern}%'"
101103
else:
102104
# Use exact match (original behavior)

tests/logs/__snapshots__/test_logs.ambr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@
133133
FROM SNOWFLAKE.TELEMETRY.EVENTS
134134
WHERE record_type = 'LOG'
135135
AND (record:severity_text IN ('INFO', 'WARN', 'ERROR', 'FATAL') or record:severity_text is NULL )
136-
AND object_name ILIKE '%test\\_obj%'
136+
AND object_name ILIKE '%test\_obj%'
137137
AND timestamp >= TO_TIMESTAMP_LTZ('2022-02-02T02:02:02')
138138
AND timestamp <= TO_TIMESTAMP_LTZ('2022-02-03T02:02:02')
139139

140140
ORDER BY timestamp;
141141
'''
142142
# ---
143-
# name: test_partial_match_with_like_wildcards[test_obj_with_percent]
143+
# name: test_partial_match_with_like_wildcards["test%obj"]
144144
'''
145145
SELECT
146146
timestamp,
@@ -152,7 +152,7 @@
152152
FROM SNOWFLAKE.TELEMETRY.EVENTS
153153
WHERE record_type = 'LOG'
154154
AND (record:severity_text IN ('INFO', 'WARN', 'ERROR', 'FATAL') or record:severity_text is NULL )
155-
AND object_name ILIKE '%test\\_obj\\_with\\_percent%'
155+
AND object_name ILIKE '%"test\%obj"%'
156156

157157
ORDER BY timestamp;
158158
'''
@@ -169,7 +169,7 @@
169169
FROM SNOWFLAKE.TELEMETRY.EVENTS
170170
WHERE record_type = 'LOG'
171171
AND (record:severity_text IN ('INFO', 'WARN', 'ERROR', 'FATAL') or record:severity_text is NULL )
172-
AND object_name ILIKE '%test\\_obj\\_with\\_underscore%'
172+
AND object_name ILIKE '%test\_obj\_with\_underscore%'
173173

174174
ORDER BY timestamp;
175175
'''

tests/logs/test_logs.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ def test_partial_match_query_construction(
122122
assert queries[0] == snapshot
123123

124124

125-
@pytest.mark.parametrize(
126-
"object_name", ["test_obj_with_underscore", "test_obj_with_percent"]
127-
)
125+
@pytest.mark.parametrize("object_name", ["test_obj_with_underscore", '"test%obj"'])
128126
def test_partial_match_with_like_wildcards(
129127
mock_connect, mock_ctx, runner, snapshot, object_name
130128
):

0 commit comments

Comments
 (0)