Skip to content

Commit

Permalink
SNOW-1019480-sql-filter-nonsql-statements: strip comments from stream… (
Browse files Browse the repository at this point in the history
#700)

* SNOW-1019480-sql-filter-nonsql-statements: strip comments from streamed queries
  • Loading branch information
sfc-gh-mraba authored Jan 31, 2024
1 parent c023e5c commit 5e0052b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/snowflake/cli/plugins/sql/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@ def execute(
elif file:
query = file.read_text()

single_statement = len(list(split_statements(StringIO(query)))) == 1
return single_statement, self._execute_string(query)
statements = tuple(
statement
for statement, _ in split_statements(StringIO(query), remove_comments=True)
)
single_statement = len(statements) == 1

return single_statement, self._execute_string("\n".join(statements))
12 changes: 12 additions & 0 deletions tests_integration/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,15 @@ def _log(
assert query_0 == "13"
assert time_1 - time_0 >= 10.0
assert "waited 10 seconds" in query_1


@pytest.mark.integration
def test_trailing_comments_queries(runner, snowflake_session, test_root_path):
trailin_comment_query = "select 1;\n\n-- trailing comment\n"
result = runner.invoke_with_connection_json(["sql", "-q", trailin_comment_query])
assert result.exit_code == 0
assert result.json == [
[
{"1": 1},
],
]

0 comments on commit 5e0052b

Please sign in to comment.