Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1019480-sql-filter-nonsql-statements: strip comments from stream… #700

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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},
],
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need integration test for it? We could check what query we passed it in unit test

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With unit test we mock the connection and response.
Doing so will not test for server side error with invalid input.