aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/sql2yql/test_sql2yql.py
diff options
context:
space:
mode:
authorudovichenko-r <udovichenko-r@yandex-team.com>2024-11-19 19:21:17 +0300
committerudovichenko-r <udovichenko-r@yandex-team.com>2024-11-19 19:32:13 +0300
commit321925491e7ee4c1fddd0294839f35d2104d637d (patch)
tree44e52a209154e8cb86f653ee059f42d5326faec3 /yql/essentials/tests/sql/sql2yql/test_sql2yql.py
parentee98714b4bafd7ac4bc0b68e563b752cbdb7af52 (diff)
downloadydb-321925491e7ee4c1fddd0294839f35d2104d637d.tar.gz
YQL-19206 Move contrib/ydb/library/yql/tests/sql/sql2yql -> yql/essentials/tests/sql/sql2yql
commit_hash:137ab446f8ed4df274d02b251cbe5e2bb08c8194
Diffstat (limited to 'yql/essentials/tests/sql/sql2yql/test_sql2yql.py')
-rw-r--r--yql/essentials/tests/sql/sql2yql/test_sql2yql.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/yql/essentials/tests/sql/sql2yql/test_sql2yql.py b/yql/essentials/tests/sql/sql2yql/test_sql2yql.py
new file mode 100644
index 0000000000..59669e66a3
--- /dev/null
+++ b/yql/essentials/tests/sql/sql2yql/test_sql2yql.py
@@ -0,0 +1,64 @@
+import os
+
+import yatest.common
+
+from test_utils import pytest_generate_tests_by_template, DATA_PATH, SQLRUN_PATH, SQL_FLAGS
+
+
+def pytest_generate_tests(metafunc):
+ return pytest_generate_tests_by_template('.sql', metafunc)
+
+
+def get_sql2yql_cmd(suite, case, case_file, out_dir, ansi_lexer, test_format, test_double_format):
+ cmd = [
+ SQLRUN_PATH,
+ case_file,
+ '--syntax-version=1',
+ '--test-antlr4',
+ ]
+
+ if ansi_lexer:
+ cmd.append('--ansi-lexer')
+ if test_format:
+ cmd.append('--test-format')
+ cmd.append('--format-output=%s' % os.path.join(out_dir, 'formatted.sql'))
+ if test_double_format:
+ cmd.append('--test-double-format')
+ else:
+ cmd.append('--yql')
+ cmd.append('--output=%s' % os.path.join(out_dir, 'sql.yql'))
+ if suite == 'kikimr':
+ cmd.append('--cluster=plato@kikimr')
+ if suite == 'rtmr':
+ cmd.append('--cluster=plato@rtmr')
+ if case.startswith('solomon'):
+ cmd.append('--cluster=local_solomon@solomon')
+
+ if suite == 'rtmr_ydb':
+ cmd.append('--cluster=plato@rtmr')
+ cmd.append('--cluster=local@kikimr')
+ if suite == 'streaming':
+ cmd.append('--cluster=pq@pq')
+ cmd.append('--cluster=solomon@solomon')
+ if suite == 'solomon':
+ cmd.append('--cluster=local_solomon@solomon')
+
+ if SQL_FLAGS:
+ cmd.append('--flags=%s' % ','.join(SQL_FLAGS))
+
+ return cmd
+
+
+def test(suite, case, tmpdir):
+ files = []
+ # case can contain slash because of nested suites
+ out_dir = tmpdir.mkdir(suite).mkdir(case.replace('/', '_')).dirname
+ case_file = os.path.join(DATA_PATH, suite, '%s.sql' % case)
+ with open(case_file, 'r') as f:
+ content = f.read()
+ ansi_lexer = 'ansi_lexer' in content
+ cmd = get_sql2yql_cmd(suite, case, case_file, out_dir, ansi_lexer, test_format=False, test_double_format=False)
+ yatest.common.process.execute(cmd, env={'YQL_DETERMINISTIC_MODE': '1'})
+ files.append(os.path.join(out_dir, 'sql.yql'))
+
+ return [yatest.common.canonical_file(file_name) for file_name in files]