Skip to content

Commit 02d7e00

Browse files
authored
YQ-2738 add integration tests for YT in KQP (#3150)
1 parent a178bc5 commit 02d7e00

File tree

74 files changed

+6256
-17
lines changed

Some content is hidden

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

74 files changed

+6256
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FeatureFlags {
2+
EnableExternalDataSources: true
3+
EnableScriptExecutionOperations: true
4+
}
5+
6+
QueryServiceConfig {
7+
FileStorage {
8+
MaxFiles: 1000
9+
MaxSizeMb: 512
10+
RetryCount: 3
11+
Threads: 2
12+
}
13+
14+
Yt {
15+
DefaultSettings {
16+
Name: "InferSchema"
17+
Value: "1"
18+
}
19+
DefaultSettings {
20+
Name: "_EnableYtPartitioning"
21+
Value: "true"
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE OBJECT yt_token (TYPE SECRET) WITH (value = "token");
2+
3+
CREATE EXTERNAL DATA SOURCE plato WITH (
4+
SOURCE_TYPE="YT",
5+
LOCATION="localhost",
6+
AUTH_METHOD="TOKEN",
7+
TOKEN_SECRET_NAME="yt_token"
8+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import os
2+
3+
import yatest.common
4+
5+
import yql_utils
6+
7+
8+
class KqpRun(object):
9+
def __init__(self, udfs_dir=None):
10+
self.kqprun_binary = yql_utils.yql_binary_path('ydb/tests/tools/kqprun/kqprun')
11+
12+
self.config_file = yql_utils.yql_source_path(os.path.join('ydb/library/yql/cfg/tests', 'kqprun_config.conf'))
13+
self.scheme_file = yql_utils.yql_source_path(os.path.join('ydb/library/yql/cfg/tests', 'kqprun_scheme.sql'))
14+
15+
self.res_dir = yql_utils.get_yql_dir(prefix='kqprun_')
16+
17+
if udfs_dir is None:
18+
self.udfs_dir = yql_utils.get_udfs_path()
19+
else:
20+
self.udfs_dir = udfs_dir
21+
22+
def __res_file_path(self, name):
23+
return os.path.join(self.res_dir, name)
24+
25+
def yql_exec(self, program=None, program_file=None, verbose=False, check_error=True, tables=None):
26+
udfs_dir = self.udfs_dir
27+
28+
config_file = self.config_file
29+
program_file = yql_utils.prepare_program(program, program_file, self.res_dir, ext='sql')[1]
30+
scheme_file = self.scheme_file
31+
32+
results_file = self.__res_file_path('results.txt')
33+
log_file = self.__res_file_path('log.txt')
34+
35+
cmd = self.kqprun_binary + ' '
36+
37+
cmd += '--emulate-yt ' \
38+
'--clear-execution ' \
39+
'--exclude-linked-udfs ' \
40+
'--app-config=%(config_file)s ' \
41+
'--script-query=%(program_file)s ' \
42+
'--scheme-query=%(scheme_file)s ' \
43+
'--result-file=%(results_file)s ' \
44+
'--log-file=%(log_file)s ' \
45+
'--udfs-dir=%(udfs_dir)s ' \
46+
'--result-rows-limit 0 ' % locals()
47+
48+
if tables is not None:
49+
for table in tables:
50+
cmd += '--table=yt.Root/%s@%s ' % (table.full_name, table.yqlrun_file)
51+
52+
proc_result = yatest.common.process.execute(cmd.strip().split(), check_exit_code=False, cwd=self.res_dir)
53+
if proc_result.exit_code != 0 and check_error:
54+
assert 0, \
55+
'Command\n%(command)s\n finished with exit code %(code)d, stderr:\n\n%(stderr)s\n\nlog file:\n%(log_file)s' % {
56+
'command': cmd,
57+
'code': proc_result.exit_code,
58+
'stderr': proc_result.std_err,
59+
'log_file': yql_utils.read_res_file(log_file)[1]
60+
}
61+
62+
results, log_results = yql_utils.read_res_file(results_file)
63+
err, log_err = yql_utils.read_res_file(log_file)
64+
65+
if verbose:
66+
yql_utils.log('PROGRAM:')
67+
yql_utils.log(program)
68+
yql_utils.log('RESULTS:')
69+
yql_utils.log(log_results)
70+
yql_utils.log('ERROR:')
71+
yql_utils.log(log_err)
72+
73+
return yql_utils.YQLExecResult(
74+
proc_result.std_out,
75+
yql_utils.normalize_source_code_path(err.replace(self.res_dir, '<tmp_path>')),
76+
results,
77+
results_file,
78+
None,
79+
None,
80+
None,
81+
None,
82+
program,
83+
proc_result,
84+
None
85+
)

ydb/library/yql/tests/common/test_framework/ya.make

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ PY23_LIBRARY()
22

33
PY_SRCS(
44
TOP_LEVEL
5+
kqprun.py
56
yql_utils.py
67
yql_ports.py
78
yqlrun.py

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

+26-11
Original file line numberDiff line numberDiff line change
@@ -41,40 +41,55 @@ def get_gateways_config(http_files, yql_http_file_server, force_blocks=False, is
4141
return config
4242

4343

44-
def run_file_no_cache(provider, suite, case, cfg, config, yql_http_file_server, yqlrun_binary=None, extra_args=[], force_blocks=False):
44+
def is_hybrid(provider):
45+
return provider == 'hybrid'
46+
47+
48+
def check_provider(provider, config):
4549
if provider not in get_supported_providers(config):
4650
pytest.skip('%s provider is not supported here' % provider)
4751

52+
53+
def get_sql_query(provider, suite, case, config):
4854
pragmas = get_pragmas(config)
4955

5056
if get_param('TARGET_PLATFORM'):
5157
if "yson" in case or "regexp" in case or "match" in case:
5258
pytest.skip('yson/match/regexp is not supported on non-default target platform')
5359

54-
xfail = is_xfail(config)
55-
if get_param('TARGET_PLATFORM') and xfail:
60+
if get_param('TARGET_PLATFORM') and is_xfail(config):
5661
pytest.skip('xfail is not supported on non-default target platform')
5762

58-
in_tables, out_tables = get_tables(suite, config, DATA_PATH, def_attr=KSV_ATTR)
59-
files = get_files(suite, config, DATA_PATH)
60-
http_files = get_http_files(suite, config, DATA_PATH)
61-
http_files_urls = yql_http_file_server.register_files({}, http_files)
62-
6363
program_sql = os.path.join(DATA_PATH, suite, '%s.sql' % case)
64-
is_hybrid = provider == 'hybrid'
6564

6665
with codecs.open(program_sql, encoding='utf-8') as program_file_descr:
6766
sql_query = program_file_descr.read()
6867
if get_param('TARGET_PLATFORM'):
6968
if "Yson::" in sql_query:
7069
pytest.skip('yson udf is not supported on non-default target platform')
71-
if (provider + 'file can not' in sql_query) or (is_hybrid and ('ytfile can not' in sql_query)):
70+
if (provider + 'file can not' in sql_query) or (is_hybrid(provider) and ('ytfile can not' in sql_query)):
7271
pytest.skip(provider + ' can not execute this')
7372

7473
pragmas.append(sql_query)
7574
sql_query = ';\n'.join(pragmas)
7675
if 'Python' in sql_query or 'Javascript' in sql_query:
7776
pytest.skip('ScriptUdf')
77+
78+
return sql_query
79+
80+
81+
def run_file_no_cache(provider, suite, case, cfg, config, yql_http_file_server, yqlrun_binary=None, extra_args=[], force_blocks=False):
82+
check_provider(provider, config)
83+
84+
sql_query = get_sql_query(provider, suite, case, config)
85+
86+
xfail = is_xfail(config)
87+
88+
in_tables, out_tables = get_tables(suite, config, DATA_PATH, def_attr=KSV_ATTR)
89+
files = get_files(suite, config, DATA_PATH)
90+
http_files = get_http_files(suite, config, DATA_PATH)
91+
http_files_urls = yql_http_file_server.register_files({}, http_files)
92+
7893
for table in in_tables:
7994
if cyson.loads(table.attr).get("type") == "document":
8095
content = table.content
@@ -89,7 +104,7 @@ def run_file_no_cache(provider, suite, case, cfg, config, yql_http_file_server,
89104
prov=provider,
90105
keep_temp=not re.search(r"yt\.ReleaseTempData", sql_query),
91106
binary=yqlrun_binary,
92-
gateway_config=get_gateways_config(http_files, yql_http_file_server, force_blocks=force_blocks, is_hybrid=is_hybrid),
107+
gateway_config=get_gateways_config(http_files, yql_http_file_server, force_blocks=force_blocks, is_hybrid=is_hybrid(provider)),
93108
extra_args=extra_args,
94109
udfs_dir=yql_binary_path('ydb/library/yql/tests/common/test_framework/udfs_deps')
95110
)

ydb/tests/fq/ya.make

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ RECURSE_FOR_TESTS(
99
restarts
1010
s3
1111
yds
12+
yt
1213
)

ydb/tests/fq/yt/kqp_yt_file.make

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
DEPENDS(
18+
ydb/library/yql/tests/common/test_framework/udfs_deps
19+
ydb/tests/tools/kqprun
20+
)
21+
22+
DATA(
23+
arcadia/ydb/library/yql/cfg/tests
24+
arcadia/ydb/library/yql/tests/sql
25+
arcadia/ydb/tests/fq/yt
26+
)
27+
28+
PEERDIR(
29+
ydb/library/yql/tests/common/test_framework
30+
)
31+
32+
NO_CHECK_IMPORTS()
33+
34+
REQUIREMENTS(ram:20)
35+
36+
END()

0 commit comments

Comments
 (0)