Skip to content

Commit 851c8da

Browse files
authored
YQL-17284: Add hybtrid run for sql tests (#1602)
1 parent d4c45f7 commit 851c8da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+31522
-64
lines changed

ydb/library/yql/tests/common/test_framework/yql_utils.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def get_tables(suite, cfg, DATA_PATH, def_attr=None):
446446

447447

448448
def get_supported_providers(cfg):
449-
providers = 'yt', 'kikimr', 'dq'
449+
providers = 'yt', 'kikimr', 'dq', 'hybrid'
450450
for item in cfg:
451451
if item[0] == 'providers':
452452
providers = [i.strip() for i in ''.join(item[1:]).split(',')]
@@ -901,6 +901,21 @@ def pytest_get_current_part(path):
901901
return (current, 1 + maxpart)
902902

903903

904+
def normalize_result(res, sort):
905+
res = cyson.loads(res) if res else cyson.loads("[]")
906+
res = replace_vals(res)
907+
for r in res:
908+
for data in r['Write']:
909+
if sort and 'Data' in data:
910+
data['Data'] = sorted(data['Data'])
911+
if 'Ref' in data:
912+
data['Ref'] = []
913+
data['Truncated'] = True
914+
if 'Data' in data and len(data['Data']) == 0:
915+
del data['Data']
916+
return res
917+
918+
904919
class LoggingDowngrade(object):
905920

906921
def __init__(self, loggers, level=logging.CRITICAL):

ydb/library/yql/tests/sql/dq_file.py

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
import os
33
import pytest
44
import re
5-
import json
6-
import yql_utils
7-
import cyson
85

96
import yatest.common
10-
from yql_utils import execute_sql, get_tables, get_files, get_http_files, replace_vals, get_supported_providers, \
11-
KSV_ATTR, yql_binary_path, is_xfail, is_skip_forceblocks, get_param, normalize_source_code_path, dump_table_yson, \
12-
get_gateway_cfg_suffix, do_custom_query_check
13-
from yqlrun import YQLRun
7+
from yql_utils import get_supported_providers, yql_binary_path, is_xfail, is_skip_forceblocks, get_param, \
8+
normalize_source_code_path, dump_table_yson, get_gateway_cfg_suffix, do_custom_query_check, normalize_result
149

15-
from utils import get_config, get_parameters_json, DATA_PATH
10+
from utils import get_config, DATA_PATH
1611
from file_common import run_file, run_file_no_cache
1712

1813
ASTDIFF_PATH = yql_binary_path('ydb/library/yql/tools/astdiff/astdiff')
@@ -45,20 +40,6 @@ def run_test(suite, case, cfg, tmpdir, what, yql_http_file_server):
4540

4641
if what == 'Results' or force_blocks:
4742
if not xfail:
48-
def normalize_res(res, sort):
49-
res = cyson.loads(res) if res else cyson.loads("[]")
50-
res = replace_vals(res)
51-
for r in res:
52-
for data in r['Write']:
53-
if sort and 'Data' in data:
54-
data['Data'] = sorted(data['Data'])
55-
if 'Ref' in data:
56-
data['Ref'] = []
57-
data['Truncated'] = True
58-
if 'Data' in data and len(data['Data']) == 0:
59-
del data['Data']
60-
return res
61-
6243
program_sql = os.path.join(DATA_PATH, suite, '%s.sql' % case)
6344
with codecs.open(program_sql, encoding='utf-8') as program_file_descr:
6445
sql_query = program_file_descr.read()
@@ -68,7 +49,7 @@ def normalize_res(res, sort):
6849

6950
sort = not 'order' in sql_query.lower()
7051

71-
dq_res_yson = normalize_res(res.results, sort)
52+
dq_res_yson = normalize_result(res.results, sort)
7253

7354
if 'ytfile can not' in sql_query or 'yt' not in get_supported_providers(config):
7455
if force_blocks:
@@ -94,7 +75,7 @@ def normalize_res(res, sort):
9475

9576
if do_custom_query_check(yqlrun_res, sql_query):
9677
return None
97-
yqlrun_res_yson = normalize_res(yqlrun_res.results, sort)
78+
yqlrun_res_yson = normalize_result(yqlrun_res.results, sort)
9879

9980
# Compare results
10081
assert dq_res_yson == yqlrun_res_yson, 'RESULTS_DIFFER\n' \

ydb/library/yql/tests/sql/file_common.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from utils import get_config, get_parameters_json, DATA_PATH
1717

1818

19-
def get_gateways_config(http_files, yql_http_file_server, force_blocks=False):
19+
def get_gateways_config(http_files, yql_http_file_server, force_blocks=False, is_hybrid=False):
2020
config = None
2121

2222
if http_files or force_blocks:
@@ -29,6 +29,13 @@ def get_gateways_config(http_files, yql_http_file_server, force_blocks=False):
2929
config_message.SqlCore.TranslationFlags.extend(['EmitAggApply'])
3030
flags = config_message.YqlCore.Flags.add()
3131
flags.Name = 'UseBlocks'
32+
if is_hybrid:
33+
activate_hybrid = config_message.Yt.DefaultSettings.add()
34+
activate_hybrid.Name = "HybridDqExecution"
35+
activate_hybrid.Value = "1"
36+
deactivate_dq = config_message.Dq.DefaultSettings.add()
37+
deactivate_dq.Name = "AnalyzeQuery"
38+
deactivate_dq.Value = "0"
3239
config = text_format.MessageToString(config_message)
3340

3441
return config
@@ -54,13 +61,14 @@ def run_file_no_cache(provider, suite, case, cfg, config, yql_http_file_server,
5461
http_files_urls = yql_http_file_server.register_files({}, http_files)
5562

5663
program_sql = os.path.join(DATA_PATH, suite, '%s.sql' % case)
64+
is_hybrid = provider == 'hybrid'
5765

5866
with codecs.open(program_sql, encoding='utf-8') as program_file_descr:
5967
sql_query = program_file_descr.read()
6068
if get_param('TARGET_PLATFORM'):
6169
if "Yson::" in sql_query:
6270
pytest.skip('yson udf is not supported on non-default target platform')
63-
if provider + 'file can not' in sql_query:
71+
if (provider + 'file can not' in sql_query) or (is_hybrid and ('ytfile can not' in sql_query)):
6472
pytest.skip(provider + ' can not execute this')
6573

6674
pragmas.append(sql_query)
@@ -81,7 +89,7 @@ def run_file_no_cache(provider, suite, case, cfg, config, yql_http_file_server,
8189
prov=provider,
8290
keep_temp=not re.search(r"yt\.ReleaseTempData", sql_query),
8391
binary=yqlrun_binary,
84-
gateway_config=get_gateways_config(http_files, yql_http_file_server, force_blocks=force_blocks),
92+
gateway_config=get_gateways_config(http_files, yql_http_file_server, force_blocks=force_blocks, is_hybrid=is_hybrid),
8593
extra_args=extra_args,
8694
udfs_dir=yql_binary_path('ydb/library/yql/tests/common/test_framework/udfs_deps')
8795
)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
PY2TEST()
2+
3+
TEST_SRCS(
4+
test.py
5+
)
6+
7+
IF (SANITIZER_TYPE OR WITH_VALGRIND)
8+
TIMEOUT(1800)
9+
SIZE(LARGE)
10+
TAG(ya:fat sb:ttl=2)
11+
ELSE()
12+
TIMEOUT(600)
13+
SIZE(MEDIUM)
14+
TAG(sb:ttl=2)
15+
ENDIF()
16+
17+
FORK_TESTS()
18+
FORK_SUBTESTS()
19+
SPLIT_FACTOR(10)
20+
21+
DEPENDS(
22+
ydb/library/yql/tools/astdiff
23+
ydb/library/yql/tools/dqrun
24+
ydb/library/yql/tools/yqlrun
25+
ydb/library/yql/tests/common/test_framework/udfs_deps
26+
ydb/library/yql/udfs/test/test_import
27+
)
28+
DATA(
29+
arcadia/ydb/library/yql/tests/sql # python files
30+
arcadia/ydb/library/yql/mount
31+
arcadia/ydb/library/yql/cfg/tests
32+
)
33+
PEERDIR(
34+
ydb/library/yql/tests/common/test_framework
35+
library/python/testing/swag/lib
36+
)
37+
38+
NO_CHECK_IMPORTS()
39+
40+
REQUIREMENTS(
41+
ram:32
42+
)
43+
44+
IF (SANITIZER_TYPE == "memory")
45+
TAG(ya:not_autocheck) # YQL-15385
46+
ENDIF()
47+
48+
END()
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import codecs
2+
import os
3+
import pytest
4+
import re
5+
6+
import yatest.common
7+
8+
from yql_utils import replace_vals, yql_binary_path, is_xfail, get_param, \
9+
get_gateway_cfg_suffix, normalize_result
10+
11+
from utils import get_config, DATA_PATH
12+
from file_common import run_file, run_file_no_cache
13+
14+
ASTDIFF_PATH = yql_binary_path('ydb/library/yql/tools/astdiff/astdiff')
15+
DQRUN_PATH = yql_binary_path('ydb/library/yql/tools/dqrun/dqrun')
16+
17+
def run_test(suite, case, cfg, tmpdir, what, yql_http_file_server):
18+
if get_param('SQL_FLAGS'):
19+
if what == 'Debug' or what == 'Plan':
20+
pytest.skip('SKIP')
21+
22+
if get_gateway_cfg_suffix() != '' and what != 'Results':
23+
pytest.skip('non-trivial gateways.conf')
24+
25+
config = get_config(suite, case, cfg)
26+
xfail = is_xfail(config)
27+
if xfail and what != 'Results':
28+
pytest.skip('SKIP')
29+
30+
(res, tables_res) = run_file('hybrid', suite, case, cfg, config, yql_http_file_server, DQRUN_PATH, extra_args=["--emulate-yt", "--analyze-query"])
31+
32+
to_canonize = []
33+
34+
if what == 'Results':
35+
36+
program_sql = os.path.join(DATA_PATH, suite, '%s.sql' % case)
37+
with codecs.open(program_sql, encoding='utf-8') as program_file_descr:
38+
sql_query = program_file_descr.read()
39+
40+
# yqlrun run
41+
yqlrun_res, yqlrun_tables_res = run_file_no_cache('yt', suite, case, cfg, config, yql_http_file_server)
42+
hybrid_result_name = 'HYBRIDFILE'
43+
yqlrun_result_name = 'YQLRUN'
44+
45+
sort = not 'order' in sql_query.lower()
46+
hybrid_res_yson = normalize_result(res.results, sort)
47+
yqlrun_res_yson = normalize_result(yqlrun_res.results, sort)
48+
49+
# Compare results
50+
assert hybrid_res_yson == yqlrun_res_yson, 'RESULTS_DIFFER\n' \
51+
'%(hybrid_result_name)s result:\n %(hybrid_res_yson)s\n\n' \
52+
'%(yqlrun_result_name)s result:\n %(yqlrun_res_yson)s\n' % locals()
53+
return
54+
55+
if what == 'Plan':
56+
to_canonize = [yatest.common.canonical_file(res.plan_file)]
57+
58+
if what == 'Debug':
59+
with open(res.opt_file + "_patched", 'w') as f:
60+
f.write(re.sub(r"""("?_logical_id"?) '\d+""", r"""\1 '0""", res.opt).encode('utf-8'))
61+
to_canonize = [yatest.common.canonical_file(res.opt_file + "_patched", diff_tool=ASTDIFF_PATH)]
62+
63+
return to_canonize

0 commit comments

Comments
 (0)