Skip to content

Commit 906f1ed

Browse files
Snow 2106457 fix queries time filter timing out (#2297)
* convert timestamp to integer * integration tests * fix unit tests * fix integration tests
1 parent 2b62eb0 commit 906f1ed

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/snowflake/cli/_plugins/sql/snowsql_commands.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class QueriesCommand(SnowSQLCommand):
5252
amount: int = 25
5353
user: str | None = None
5454
warehouse: str | None = None
55-
start_timestamp_ms: float | None = None
56-
end_timestamp_ms: float | None = None
55+
start_timestamp_ms: int | None = None
56+
end_timestamp_ms: int | None = None
5757
duration: str | None = None
5858
stmt_type: str | None = None
5959
status: str | None = None
@@ -81,8 +81,8 @@ def _execute_help(self):
8181
"datetime in ISO format (for example YYYY-MM-DDTHH:mm:ss.sss)",
8282
"any",
8383
],
84-
["start", "timestamp in milliseconds", "any"],
85-
["end", "timestamp in milliseconds", "any"],
84+
["start", "timestamp in milliseconds (integer)", "any"],
85+
["end", "timestamp in milliseconds (integer)", "any"],
8686
["type", "string", "any"],
8787
["duration", "time in milliseconds", "any"],
8888
["session", "No arguments", "any"],
@@ -147,15 +147,15 @@ def from_args(cls, args: List[str], kwargs: Dict[str, Any]) -> CompileCommandRes
147147
start_timestamp_ms = kwargs.pop("start", None)
148148
if start_timestamp_ms:
149149
try:
150-
start_timestamp_ms = float(start_timestamp_ms)
150+
start_timestamp_ms = int(start_timestamp_ms)
151151
except ValueError:
152152
return CompileCommandResult(
153153
error_message=f"Invalid argument passed to 'start' filter: {start_timestamp_ms}"
154154
)
155155
end_timestamp_ms = kwargs.pop("end", None)
156156
if end_timestamp_ms:
157157
try:
158-
end_timestamp_ms = float(end_timestamp_ms)
158+
end_timestamp_ms = int(end_timestamp_ms)
159159
except ValueError:
160160
return CompileCommandResult(
161161
error_message=f"Invalid argument passed to 'end' filter: {end_timestamp_ms}"
@@ -169,7 +169,7 @@ def from_args(cls, args: List[str], kwargs: Dict[str, Any]) -> CompileCommandRes
169169
)
170170
try:
171171
seconds = datetime.fromisoformat(start_date).timestamp()
172-
start_timestamp_ms = seconds * 1000 # convert to milliseconds
172+
start_timestamp_ms = int(seconds * 1000) # convert to milliseconds
173173
except ValueError:
174174
return CompileCommandResult(
175175
error_message=f"Invalid date format passed to 'start_date' filter: {start_date}"
@@ -182,7 +182,7 @@ def from_args(cls, args: List[str], kwargs: Dict[str, Any]) -> CompileCommandRes
182182
)
183183
try:
184184
seconds = datetime.fromisoformat(end_date).timestamp()
185-
end_timestamp_ms = seconds * 1000 # convert to milliseconds
185+
end_timestamp_ms = int(seconds * 1000) # convert to milliseconds
186186
except ValueError:
187187
return CompileCommandResult(
188188
error_message=f"Invalid date format passed to 'end_date' filter: {end_date}"

tests/sql/test_snowsql_commands.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def test_queries_from_args():
119119
amount=3,
120120
user="user",
121121
warehouse="warehouse",
122-
start_timestamp_ms=1234.0,
123-
end_timestamp_ms=5678.0,
122+
start_timestamp_ms=1234,
123+
end_timestamp_ms=5678,
124124
duration="200",
125125
stmt_type="INSERT",
126126
status="RUNNING",
@@ -137,7 +137,7 @@ def test_queries_from_args():
137137
},
138138
) == CompileCommandResult(
139139
command=QueriesCommand(
140-
start_timestamp_ms=1746403200000.0, end_timestamp_ms=1746403201000.0
140+
start_timestamp_ms=1746403200000, end_timestamp_ms=1746403201000
141141
)
142142
)
143143

@@ -248,16 +248,16 @@ def test_queries_execute(mock_print, mock_time, mock_ctx, current_session):
248248
amount=3,
249249
user="user",
250250
warehouse="warehouse",
251-
start_timestamp_ms=2345.0,
252-
end_timestamp_ms=6789.0,
251+
start_timestamp_ms=2345,
252+
end_timestamp_ms=6789,
253253
duration="200",
254254
stmt_type="INSERT",
255255
status="RUNNING",
256256
).execute(ctx)
257257

258258
expected_url = (
259259
"/monitoring/queries?_dc=mocked_time&includeDDL=false&max=3&user=user&wh=warehouse"
260-
"&start=2345.0&end=6789.0&min_duration=200"
260+
"&start=2345&end=6789&min_duration=200"
261261
f"{'&session_id=mocked_session_id' if current_session else ''}"
262262
"&subset=RUNNING&stmt_type=INSERT"
263263
)

tests_integration/sql/__snapshots__/test_snowsql_commands.ambr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
| | YYYY-MM-DDTHH:mm:ss.sss) | |
1313
| end_date | datetime in ISO format (for example | any |
1414
| | YYYY-MM-DDTHH:mm:ss.sss) | |
15-
| start | timestamp in milliseconds | any |
16-
| end | timestamp in milliseconds | any |
15+
| start | timestamp in milliseconds (integer) | any |
16+
| end | timestamp in milliseconds (integer) | any |
1717
| type | string | any |
1818
| duration | time in milliseconds | any |
1919
| session | No arguments | any |

0 commit comments

Comments
 (0)