Skip to content

Commit 0a8e48a

Browse files
committed
YQL-19864 sql flag + test with explicit flag & by version
commit_hash:902cfa0c1b574c1addb5df96a4b38c792ae82258
1 parent 7d1f3b5 commit 0a8e48a

File tree

19 files changed

+149
-16
lines changed

19 files changed

+149
-16
lines changed

yql/essentials/data/language/pragmas_opensource.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

yql/essentials/sql/v1/context.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ THashMap<TStringBuf, TPragmaField> CTX_PRAGMA_FIELDS = {
6969
{"EmitUnionMerge", &TContext::EmitUnionMerge},
7070
{"SeqMode", &TContext::SeqMode},
7171
{"DistinctOverKeys", &TContext::DistinctOverKeys},
72+
{"GroupByExprAfterWhere", &TContext::GroupByExprAfterWhere},
7273
};
7374

7475
typedef TMaybe<bool> TContext::*TPragmaMaybeField;
@@ -104,6 +105,10 @@ TContext::TContext(const TLexers& lexers, const TParsers& parsers,
104105
, WarningPolicy(settings.IsReplay)
105106
, BlockEngineEnable(Settings.BlockDefaultAuto->Allow())
106107
{
108+
if (settings.LangVer >= MakeLangVersion(2025, 2)) {
109+
GroupByExprAfterWhere = true;
110+
}
111+
107112
for (auto lib : settings.Libraries) {
108113
Libraries.emplace(lib, TLibraryStuff());
109114
}

yql/essentials/sql/v1/context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ namespace NSQLTranslationV1 {
373373
bool DistinctOverWindow = false;
374374
bool SeqMode = false;
375375
bool DistinctOverKeys = false;
376+
bool GroupByExprAfterWhere = false;
376377
bool EmitUnionMerge = false;
377378
TVector<size_t> ForAllStatementsParts;
378379

yql/essentials/sql/v1/select.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,11 @@ class TSelectCore: public IRealSource, public IComposableSource {
17441744
if (Flatten) {
17451745
block = L(block, Y("let", "core", Y(ordered ? "OrderedFlatMap" : "FlatMap", "core", BuildLambda(Pos, Y("row"), Flatten, "res"))));
17461746
}
1747+
if (ctx.GroupByExprAfterWhere) {
1748+
if (auto filter = Source->BuildFilter(ctx, "core"); filter) {
1749+
block = L(block, Y("let", "core", filter));
1750+
}
1751+
}
17471752
if (PreaggregatedMap) {
17481753
block = L(block, Y("let", "core", PreaggregatedMap));
17491754
if (Source->IsCompositeSource() && !Columns.QualifiedAll) {
@@ -1752,9 +1757,10 @@ class TSelectCore: public IRealSource, public IComposableSource {
17521757
} else if (Source->IsCompositeSource() && !Columns.QualifiedAll) {
17531758
block = L(block, Y("let", "origcore", "core"));
17541759
}
1755-
auto filter = Source->BuildFilter(ctx, "core");
1756-
if (filter) {
1757-
block = L(block, Y("let", "core", filter));
1760+
if (!ctx.GroupByExprAfterWhere) {
1761+
if (auto filter = Source->BuildFilter(ctx, "core"); filter) {
1762+
block = L(block, Y("let", "core", filter));
1763+
}
17581764
}
17591765
if (Aggregate) {
17601766
block = L(block, Y("let", "core", Aggregate));

yql/essentials/sql/v1/sql_query.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,6 +3393,12 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
33933393
} else if (normalizedPragma == "disabledistinctoverkeys") {
33943394
Ctx.DistinctOverKeys = false;
33953395
Ctx.IncrementMonCounter("sql_pragma", "DisableDistinctOverKeys");
3396+
} else if (normalizedPragma == "groupbyexprafterwhere") {
3397+
Ctx.GroupByExprAfterWhere = true;
3398+
Ctx.IncrementMonCounter("sql_pragma", "GroupByExprAfterWhere");
3399+
} else if (normalizedPragma == "disablegroupbyexprafterwhere") {
3400+
Ctx.GroupByExprAfterWhere = false;
3401+
Ctx.IncrementMonCounter("sql_pragma", "DisableGroupByExprAfterWhere");
33963402
} else if (normalizedPragma == "engine") {
33973403
Ctx.IncrementMonCounter("sql_pragma", "Engine");
33983404

yql/essentials/tests/common/test_framework/test_file_common.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def get_sql_query(provider, suite, case, config, data_path=None, template='.sql'
8888

8989
def run_file_no_cache(provider, suite, case, cfg, config, yql_http_file_server,
9090
yqlrun_binary=None, extra_args=[], force_blocks=False, allow_llvm=True, data_path=None,
91-
run_sql=True, cfg_postprocess=None):
91+
run_sql=True, cfg_postprocess=None, langver=None):
9292
check_provider(provider, config)
9393

9494
sql_query = get_sql_query(provider, suite, case, config, data_path, template='.sql' if run_sql else '.yqls')
@@ -119,7 +119,8 @@ def run_file_no_cache(provider, suite, case, cfg, config, yql_http_file_server,
119119
gateway_config=get_gateways_config(http_files, yql_http_file_server, force_blocks=force_blocks, is_hybrid=is_hybrid(provider), allow_llvm=allow_llvm,
120120
postprocess_func=cfg_postprocess),
121121
extra_args=extra_args,
122-
udfs_dir=yql_binary_path('yql/essentials/tests/common/test_framework/udfs_deps')
122+
udfs_dir=yql_binary_path('yql/essentials/tests/common/test_framework/udfs_deps'),
123+
langver=langver
123124
)
124125

125126
res, tables_res = execute(
@@ -156,12 +157,14 @@ def run_file_no_cache(provider, suite, case, cfg, config, yql_http_file_server,
156157

157158

158159
def run_file(provider, suite, case, cfg, config, yql_http_file_server, yqlrun_binary=None,
159-
extra_args=[], force_blocks=False, allow_llvm=True, data_path=None, run_sql=True, cfg_postprocess=None):
160+
extra_args=[], force_blocks=False, allow_llvm=True, data_path=None, run_sql=True,
161+
cfg_postprocess=None, langver=None):
160162
if (suite, case, cfg) not in run_file.cache:
161163
run_file.cache[(suite, case, cfg)] = \
162164
run_file_no_cache(provider, suite, case, cfg, config, yql_http_file_server,
163165
yqlrun_binary, extra_args, force_blocks=force_blocks, allow_llvm=allow_llvm,
164-
data_path=data_path, run_sql=run_sql, cfg_postprocess=cfg_postprocess)
166+
data_path=data_path, run_sql=run_sql, cfg_postprocess=cfg_postprocess,
167+
langver=langver)
165168

166169
return run_file.cache[(suite, case, cfg)]
167170

yql/essentials/tests/common/test_framework/test_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def validate_cfg(result):
144144
"yt_file",
145145
"os",
146146
"param",
147+
"langver",
147148
), "Unknown command in .cfg: %s" % (r[0])
148149

149150

yql/essentials/tests/common/test_framework/yql_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,13 @@ def is_xfail(cfg):
496496
return False
497497

498498

499+
def get_langver(cfg):
500+
for item in cfg:
501+
if item[0] == 'langver':
502+
return item[1]
503+
return None
504+
505+
499506
def is_skip_forceblocks(cfg):
500507
for item in cfg:
501508
if item[0] == 'skip_forceblocks':

yql/essentials/tests/common/test_framework/yqlrun.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
class YQLRun(object):
2727

28-
def __init__(self, udfs_dir=None, prov='yt', use_sql2yql=False, keep_temp=True, binary=None, gateway_config=None, fs_config=None, extra_args=[], cfg_dir=None, support_udfs=True):
28+
def __init__(self, udfs_dir=None, prov='yt', use_sql2yql=False, keep_temp=True, binary=None, gateway_config=None,
29+
fs_config=None, extra_args=[], cfg_dir=None, support_udfs=True, langver=None):
2930
if binary is None:
3031
self.yqlrun_binary = yql_utils.yql_binary_path(os.getenv('YQL_YQLRUN_PATH') or 'yql/tools/yqlrun/yqlrun')
3132
else:
@@ -80,6 +81,8 @@ def __init__(self, udfs_dir=None, prov='yt', use_sql2yql=False, keep_temp=True,
8081
flags = yql_utils.get_param('SQL_FLAGS').split(',')
8182
self.gateway_config.SqlCore.TranslationFlags.extend(flags)
8283

84+
self.langver = langver
85+
8386
def yql_exec(self, program=None, program_file=None, files=None, urls=None,
8487
run_sql=False, verbose=False, check_error=True, tables=None, pretty_plan=True,
8588
wait=True, parameters={}, extra_env={}, require_udf_resolver=False, scan_udfs=True):
@@ -173,6 +176,9 @@ def res_file_path(name):
173176
if ansi_lexer:
174177
cmd += '--ansi-lexer '
175178

179+
if self.langver is not None:
180+
cmd += '--langver=%s ' % (self.langver,)
181+
176182
if self.keep_temp and prov != 'pure':
177183
cmd += '--keep-temp '
178184

yql/essentials/tests/s-expressions/minirun/pure.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
KSV_ATTR, yql_binary_path, is_xfail, is_canonize_peephole, is_peephole_use_blocks, is_canonize_lineage, \
1010
is_skip_forceblocks, get_param, normalize_source_code_path, replace_vals, get_gateway_cfg_suffix, \
1111
do_custom_query_check, stable_result_file, stable_table_file, is_with_final_result_issues, \
12-
normalize_result
12+
normalize_result, get_langver
1313
from yqlrun import YQLRun
1414

1515
from test_utils import get_config, get_parameters_json
1616
from test_file_common import run_file, run_file_no_cache, get_gateways_config, get_sql_query
1717

18+
DEFAULT_LANG_VER = '2025.01'
1819
ASTDIFF_PATH = yql_binary_path('yql/essentials/tools/astdiff/astdiff')
1920
MINIRUN_PATH = yql_binary_path('yql/essentials/tools/minirun/minirun')
2021
DATA_PATH = yatest.common.source_path('yql/essentials/tests/s-expressions/suites')
@@ -25,6 +26,9 @@ def run_test(suite, case, cfg, tmpdir, what, yql_http_file_server):
2526
pytest.skip('non-trivial gateways.conf')
2627

2728
config = get_config(suite, case, cfg, data_path=DATA_PATH)
29+
langver = get_langver(config)
30+
if langver is None:
31+
langver = DEFAULT_LANG_VER
2832

2933
xfail = is_xfail(config)
3034
if xfail and what != 'Results':
@@ -38,7 +42,8 @@ def run_test(suite, case, cfg, tmpdir, what, yql_http_file_server):
3842
if is_with_final_result_issues(config):
3943
extra_final_args += ['--with-final-issues']
4044
(res, tables_res) = run_file('pure', suite, case, cfg, config, yql_http_file_server, MINIRUN_PATH,
41-
extra_args=extra_final_args, allow_llvm=False, data_path=DATA_PATH, run_sql=False)
45+
extra_args=extra_final_args, allow_llvm=False, data_path=DATA_PATH,
46+
run_sql=False, langver=langver)
4247

4348
to_canonize = []
4449
assert not tables_res
@@ -72,7 +77,8 @@ def run_test(suite, case, cfg, tmpdir, what, yql_http_file_server):
7277
keep_temp=False,
7378
gateway_config=get_gateways_config(http_files, yql_http_file_server, allow_llvm=is_llvm),
7479
udfs_dir=yql_binary_path('yql/essentials/tests/common/test_framework/udfs_deps'),
75-
binary=MINIRUN_PATH
80+
binary=MINIRUN_PATH,
81+
langver=langver
7682
)
7783

7884
opt_res, opt_tables_res = execute(

0 commit comments

Comments
 (0)