Skip to content

Commit

Permalink
Refuse empty query text (#708)
Browse files Browse the repository at this point in the history
* Refuse empty query text

* flake8

* Fix tests
  • Loading branch information
Hor911 authored Dec 26, 2023
1 parent 52cce2c commit 6dc434a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 53 deletions.
2 changes: 1 addition & 1 deletion ydb/public/api/protos/draft/fq.proto
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ message QueryContent {
string name = 2 [(Ydb.length).le = 1024];
Acl acl = 3;
Limits limits = 4;
string text = 5 [(Ydb.length).le = 102400]; // The text of the query itself
string text = 5 [(Ydb.length).range = {min: 1, max: 102400}]; // The text of the query itself
bool automatic = 6; // Is used for queries that are created by automatic systems (robots, jdbc driver, ...)
string description = 7 [(Ydb.length).le = 10240]; // Description of the query, there can be any text
// Specified settings for query's executor
Expand Down
58 changes: 6 additions & 52 deletions ydb/tests/fq/http_api/test_http_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,58 +121,12 @@ def test_simple_analitycs_query(self):

def test_empty_query(self):
client = self.create_client()
result = client.create_query()
query_id = result.get("id")

wait_for_query_status(client, query_id, ["FAILED"])
query_json = client.get_query(query_id)
assert normalize_json(query_json) == {
"id": "xxxxxxxxxxxxxxxxxxxx",
"name": "",
"description": "",
"text": "",
"type": "ANALYTICS",
"status": "FAILED",
"issues": {
"message": "{ <main>: Error: Query failed with code ABORTED at ISOTIME subissue: "
"{ <main>: Error: Failed to parse query subissue: "
"{ <main>: Error: Parse Sql subissue: "
"{ <main>:1:0: Error: Unexpected token absence : cannot match to any predicted input... "
"} } } }",
"details": [
{
"message": "Query failed with code ABORTED at ISOTIME",
"severity": "ERROR",
"issues": [
{
"message": "Failed to parse query",
"severity": "ERROR",
"issues": [
{
"message": "Parse Sql",
"severity": "ERROR",
"issues": [
{
"position": {"row": 1},
"message": "Unexpected token absence : cannot match to any predicted input...\u000a",
"end_position": {"row": 1},
"severity": "ERROR",
"issues": []
}
]
}
]
}
]
}
]
},
"meta": {
"finished_at": "ISOTIME",
"started_at": "ISOTIME"
},
"result_sets": []
}
try:
result = client.create_query()
except Exception as e:
assert "\"message\":\"text\'s length is not in [1; 102400]" in e.args[0]
return
assert False

def test_warning(self):
client = self.create_client()
Expand Down
23 changes: 23 additions & 0 deletions ydb/tests/fq/s3/test_empty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pytest

import ydb.public.api.protos.draft.fq_pb2 as fq

from ydb.tests.tools.fq_runner.fq_client import FederatedQueryException
from ydb.tests.tools.fq_runner.kikimr_utils import yq_all


class TestS3(object):

@yq_all
@pytest.mark.parametrize("client", [{"folder_id": "my_folder"}], indirect=True)
def test_empty(self, kikimr, client):
try:
client.create_query("simple", "", type=fq.QueryContent.QueryType.ANALYTICS).result.query_id
except FederatedQueryException as e:
assert "message: \"text\\\'s length is not in [1; 102400]" in e.args[0]
return
assert False

1 change: 1 addition & 0 deletions ydb/tests/fq/s3/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ TEST_SRCS(
test_bindings.py
test_compressions.py
test_early_finish.py
test_empty.py
test_explicit_partitioning.py
test_format_setting.py
test_formats.py
Expand Down

0 comments on commit 6dc434a

Please sign in to comment.