Skip to content

Commit 96e41c5

Browse files
vitstnblinkov
authored andcommitted
YQL-19129 soft WITHOUT
commit_hash:563aebc32ae87bc18e5e3e38babc034e5e89e2c1
1 parent f392c83 commit 96e41c5

File tree

12 files changed

+84
-13
lines changed

12 files changed

+84
-13
lines changed

yql/essentials/docs/en/syntax/select/without.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# WITHOUT
22

3-
Excluding columns from the result of `SELECT *`.
3+
Excluding columns from the result of `SELECT *`. The `IF EXISTS` modifier does not throw an error for missing columns.
44

55
## Examples
66

77
```yql
88
SELECT * WITHOUT foo, bar FROM my_table;
9+
SELECT * WITHOUT IF EXISTS foo, bar FROM my_table;
910
```
1011

1112
```yql

yql/essentials/docs/ru/syntax/select/without.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# WITHOUT
22

3-
Исключение столбцов из результата запроса `SELECT *`.
3+
Исключение столбцов из результата запроса `SELECT *`. С модификатором `IF EXISTS` не выдается ошибки для отсуствующих столбцов.
44

55
## Примеры
66

77
```yql
88
SELECT * WITHOUT foo, bar FROM my_table;
9+
SELECT * WITHOUT IF EXISTS foo, bar FROM my_table;
910
```
1011

1112
```yql

yql/essentials/sql/v1/SQLv1.g.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ reduce_core:
397397
opt_set_quantifier: (ALL | DISTINCT)?;
398398

399399
select_core:
400-
(FROM join_source)? SELECT STREAM? opt_set_quantifier result_column (COMMA result_column)* COMMA? (WITHOUT without_column_list)? (FROM join_source)? (WHERE expr)?
400+
(FROM join_source)? SELECT STREAM? opt_set_quantifier result_column (COMMA result_column)* COMMA? (WITHOUT (IF EXISTS)? without_column_list)? (FROM join_source)? (WHERE expr)?
401401
group_by_clause? (HAVING expr)? window_clause? ext_order_by_clause?
402402
;
403403

yql/essentials/sql/v1/SQLv1Antlr4.g.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ reduce_core:
396396
opt_set_quantifier: (ALL | DISTINCT)?;
397397

398398
select_core:
399-
(FROM join_source)? SELECT STREAM? opt_set_quantifier result_column (COMMA result_column)* COMMA? (WITHOUT without_column_list)? (FROM join_source)? (WHERE expr)?
399+
(FROM join_source)? SELECT STREAM? opt_set_quantifier result_column (COMMA result_column)* COMMA? (WITHOUT (IF EXISTS)? without_column_list)? (FROM join_source)? (WHERE expr)?
400400
group_by_clause? (HAVING expr)? window_clause? ext_order_by_clause?
401401
;
402402

yql/essentials/sql/v1/format/sql_format_ut.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,8 @@ Y_UNIT_TEST(Select) {
858858
"SELECT\n\t*\nWITHOUT\n\ta,\n\tb\n;\n"},
859859
{"select * without a,",
860860
"SELECT\n\t*\nWITHOUT\n\ta,\n;\n"},
861+
{"select * without if exists a",
862+
"SELECT\n\t*\nWITHOUT IF EXISTS\n\ta\n;\n"},
861863
{"select 1 from user",
862864
"SELECT\n\t1\nFROM\n\tuser\n;\n"},
863865
{"select 1 from plato.user",

yql/essentials/sql/v1/select.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,7 @@ class TSelectCore: public IRealSource, public IComposableSource {
14891489
const TVector<TNodePtr>& terms,
14901490
bool distinct,
14911491
const TVector<TNodePtr>& without,
1492+
bool forceWithout,
14921493
bool selectStream,
14931494
const TWriteSettings& settings,
14941495
TColumnsSets&& uniqueSets,
@@ -1506,6 +1507,7 @@ class TSelectCore: public IRealSource, public IComposableSource {
15061507
, WinSpecs(winSpecs)
15071508
, Terms(terms)
15081509
, Without(without)
1510+
, ForceWithout(forceWithout)
15091511
, Distinct(distinct)
15101512
, LegacyHoppingWindowSpec(legacyHoppingWindowSpec)
15111513
, SelectStream(selectStream)
@@ -1924,7 +1926,7 @@ class TSelectCore: public IRealSource, public IComposableSource {
19241926
if (Source && Source->GetJoin()) {
19251927
name = DotJoin(*without->GetSourceName(), name);
19261928
}
1927-
terms = L(terms, Y("let", "row", Y("RemoveMember", "row", Q(name))));
1929+
terms = L(terms, Y("let", "row", Y(ForceWithout ? "ForceRemoveMember" : "RemoveMember", "row", Q(name))));
19281930
}
19291931
}
19301932

@@ -1941,7 +1943,7 @@ class TSelectCore: public IRealSource, public IComposableSource {
19411943
return new TSelectCore(Pos, Source->CloneSource(), CloneContainer(GroupByExpr),
19421944
CloneContainer(GroupBy), CompactGroupBy, GroupBySuffix, AssumeSorted, CloneContainer(OrderBy),
19431945
SafeClone(Having), CloneContainer(WinSpecs), SafeClone(LegacyHoppingWindowSpec),
1944-
CloneContainer(Terms), Distinct, Without, SelectStream, Settings, TColumnsSets(UniqueSets), TColumnsSets(DistinctSets));
1946+
CloneContainer(Terms), Distinct, Without, ForceWithout, SelectStream, Settings, TColumnsSets(UniqueSets), TColumnsSets(DistinctSets));
19451947
}
19461948

19471949
private:
@@ -2301,6 +2303,7 @@ class TSelectCore: public IRealSource, public IComposableSource {
23012303
TNodePtr CompositeTerms;
23022304
TVector<TNodePtr> Terms;
23032305
TVector<TNodePtr> Without;
2306+
const bool ForceWithout;
23042307
const bool Distinct;
23052308
bool OrderByInit = false;
23062309
TLegacyHoppingWindowSpecPtr LegacyHoppingWindowSpec;
@@ -2715,22 +2718,23 @@ TSourcePtr DoBuildSelectCore(
27152718
TVector<TNodePtr>&& terms,
27162719
bool distinct,
27172720
TVector<TNodePtr>&& without,
2721+
bool forceWithout,
27182722
bool selectStream,
27192723
const TWriteSettings& settings,
27202724
TColumnsSets&& uniqueSets,
27212725
TColumnsSets&& distinctSets
27222726
) {
27232727
if (groupBy.empty() || !groupBy.front()->ContentListPtr()) {
27242728
return new TSelectCore(pos, std::move(source), groupByExpr, groupBy, compactGroupBy, groupBySuffix, assumeSorted,
2725-
orderBy, having, winSpecs, legacyHoppingWindowSpec, terms, distinct, without, selectStream, settings, std::move(uniqueSets), std::move(distinctSets));
2729+
orderBy, having, winSpecs, legacyHoppingWindowSpec, terms, distinct, without, forceWithout, selectStream, settings, std::move(uniqueSets), std::move(distinctSets));
27262730
}
27272731
if (groupBy.size() == 1) {
27282732
/// actualy no big idea to use grouping function in this case (result allways 0)
27292733
auto contentPtr = groupBy.front()->ContentListPtr();
27302734
source = new TNestedProxySource(pos, *contentPtr, source);
27312735
return DoBuildSelectCore(ctx, pos, originalSource, source, groupByExpr, *contentPtr, compactGroupBy, groupBySuffix,
27322736
assumeSorted, orderBy, having, std::move(winSpecs),
2733-
legacyHoppingWindowSpec, std::move(terms), distinct, std::move(without), selectStream, settings, std::move(uniqueSets), std::move(distinctSets));
2737+
legacyHoppingWindowSpec, std::move(terms), distinct, std::move(without), forceWithout, selectStream, settings, std::move(uniqueSets), std::move(distinctSets));
27342738
}
27352739
/// \todo some smart merge logic, generalize common part of grouping (expr, flatten, etc)?
27362740
TIntrusivePtr<TCompositeSelect> compositeSelect = new TCompositeSelect(pos, std::move(source), originalSource->CloneSource(), settings);
@@ -2757,7 +2761,7 @@ TSourcePtr DoBuildSelectCore(
27572761
totalGroups += contentPtr->size();
27582762
TSelectCore* selectCore = new TSelectCore(pos, std::move(proxySource), CloneContainer(groupByExpr),
27592763
CloneContainer(*contentPtr), compactGroupBy, groupBySuffix, assumeSorted, orderBy, SafeClone(having), CloneContainer(winSpecs),
2760-
legacyHoppingWindowSpec, terms, distinct, without, selectStream, settings, TColumnsSets(uniqueSets), TColumnsSets(distinctSets));
2764+
legacyHoppingWindowSpec, terms, distinct, without, forceWithout, selectStream, settings, TColumnsSets(uniqueSets), TColumnsSets(distinctSets));
27612765
subselects.emplace_back(selectCore);
27622766
}
27632767
if (totalGroups > ctx.PragmaGroupByLimit) {
@@ -2786,14 +2790,15 @@ TSourcePtr BuildSelectCore(
27862790
TVector<TNodePtr>&& terms,
27872791
bool distinct,
27882792
TVector<TNodePtr>&& without,
2793+
bool forceWithout,
27892794
bool selectStream,
27902795
const TWriteSettings& settings,
27912796
TColumnsSets&& uniqueSets,
27922797
TColumnsSets&& distinctSets
27932798
)
27942799
{
27952800
return DoBuildSelectCore(ctx, pos, source, source, groupByExpr, groupBy, compactGroupBy, groupBySuffix, assumeSorted, orderBy,
2796-
having, std::move(winSpecs), legacyHoppingWindowSpec, std::move(terms), distinct, std::move(without), selectStream, settings, std::move(uniqueSets), std::move(distinctSets));
2801+
having, std::move(winSpecs), legacyHoppingWindowSpec, std::move(terms), distinct, std::move(without), forceWithout, selectStream, settings, std::move(uniqueSets), std::move(distinctSets));
27972802
}
27982803

27992804
class TUnion: public IRealSource {

yql/essentials/sql/v1/source.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ namespace NSQLTranslationV1 {
269269
TVector<TNodePtr>&& terms,
270270
bool distinct,
271271
TVector<TNodePtr>&& without,
272+
bool forceWithout,
272273
bool selectStream,
273274
const TWriteSettings& settings,
274275
TColumnsSets&& uniqueSets,

yql/essentials/sql/v1/sql_select.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,10 @@ TSourcePtr TSqlSelect::SelectCore(const TRule_select_core& node, const TWriteSet
10271027

10281028
const bool selectStream = node.HasBlock3();
10291029
TVector<TNodePtr> without;
1030+
bool forceWithout = false;
10301031
if (node.HasBlock8()) {
1031-
if (!ColumnList(without, node.GetBlock8().GetRule_without_column_list2())) {
1032+
forceWithout = node.GetBlock8().HasBlock2();
1033+
if (!ColumnList(without, node.GetBlock8().GetRule_without_column_list3())) {
10321034
return nullptr;
10331035
}
10341036
}
@@ -1167,7 +1169,7 @@ TSourcePtr TSqlSelect::SelectCore(const TRule_select_core& node, const TWriteSet
11671169
return nullptr;
11681170
}
11691171
return BuildSelectCore(Ctx, startPos, std::move(source), groupByExpr, groupBy, compactGroupBy, groupBySuffix, assumeSorted, orderBy, having,
1170-
std::move(windowSpec), legacyHoppingWindowSpec, std::move(terms), distinct, std::move(without), selectStream, settings, std::move(uniqueSets), std::move(distinctSets));
1172+
std::move(windowSpec), legacyHoppingWindowSpec, std::move(terms), distinct, std::move(without), forceWithout, selectStream, settings, std::move(uniqueSets), std::move(distinctSets));
11711173
}
11721174

11731175
bool TSqlSelect::WindowDefinition(const TRule_window_definition& rule, TWinSpecs& winSpecs) {
@@ -1421,14 +1423,15 @@ TSourcePtr TSqlSelect::Build(const TRule& node, TPosition pos, TSelectKindResult
14211423
TLegacyHoppingWindowSpecPtr legacyHoppingWindowSpec;
14221424
bool distinct = false;
14231425
TVector<TNodePtr> without;
1426+
bool forceWithout = false;
14241427
bool stream = false;
14251428

14261429
TVector<TNodePtr> terms;
14271430
terms.push_back(BuildColumn(unionPos, "*", ""));
14281431

14291432
result = BuildSelectCore(Ctx, unionPos, std::move(result), groupByExpr, groupBy, compactGroupBy, groupBySuffix,
14301433
assumeOrderBy, orderBy, having, std::move(winSpecs), legacyHoppingWindowSpec, std::move(terms),
1431-
distinct, std::move(without), stream, outermostSettings, {}, {});
1434+
distinct, std::move(without), forceWithout, stream, outermostSettings, {}, {});
14321435

14331436
result = BuildSelect(unionPos, std::move(result), skipTake);
14341437
} else if (skipTake) {

yql/essentials/tests/sql/minirun/part0/canondata/result.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,20 @@
13451345
"uri": "https://{canondata_backend}/1946324/42941f53c7bc2748dcbf9469a617a6dd3e805076/resource.tar.gz#test.test_select-id_xor-default.txt-Results_/results.txt"
13461346
}
13471347
],
1348+
"test.test[select-without_if_exists-default.txt-Debug]": [
1349+
{
1350+
"checksum": "ea7d283945e2e1b87cb08073282a19e7",
1351+
"size": 301,
1352+
"uri": "https://{canondata_backend}/1809005/3d9ba2209e199d535bc6bbb3c259c9d955a3f50c/resource.tar.gz#test.test_select-without_if_exists-default.txt-Debug_/opt.yql"
1353+
}
1354+
],
1355+
"test.test[select-without_if_exists-default.txt-Results]": [
1356+
{
1357+
"checksum": "54766486c34ebb7876ebb3d362dc96f9",
1358+
"size": 1663,
1359+
"uri": "https://{canondata_backend}/1809005/3d9ba2209e199d535bc6bbb3c259c9d955a3f50c/resource.tar.gz#test.test_select-without_if_exists-default.txt-Results_/results.txt"
1360+
}
1361+
],
13481362
"test.test[udf-udf_with_settings--Debug]": [
13491363
{
13501364
"checksum": "a7b364b692c35af7b468f42ab6a7b43f",

yql/essentials/tests/sql/sql2yql/canondata/result.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6922,6 +6922,13 @@
69226922
"uri": "https://{canondata_backend}/1903280/03a80e4eaf2d24e0b4fad2e65ee62b19b904eb3c/resource.tar.gz#test_sql2yql.test_select-values_/sql.yql"
69236923
}
69246924
],
6925+
"test_sql2yql.test[select-without_if_exists]": [
6926+
{
6927+
"checksum": "698deee923ae5f88185130a30121b741",
6928+
"size": 3065,
6929+
"uri": "https://{canondata_backend}/1937492/efb17561a1a79f7d31fb758358c23c28314c8d60/resource.tar.gz#test_sql2yql.test_select-without_if_exists_/sql.yql"
6930+
}
6931+
],
69256932
"test_sql2yql.test[seq_mode-shared_named_expr]": [
69266933
{
69276934
"checksum": "7f16d29d01ed38006249f8a6df896d89",
@@ -10755,6 +10762,11 @@
1075510762
"uri": "file://test_sql_format.test_select-values_/formatted.sql"
1075610763
}
1075710764
],
10765+
"test_sql_format.test[select-without_if_exists]": [
10766+
{
10767+
"uri": "file://test_sql_format.test_select-without_if_exists_/formatted.sql"
10768+
}
10769+
],
1075810770
"test_sql_format.test[seq_mode-shared_named_expr]": [
1075910771
{
1076010772
"uri": "file://test_sql_format.test_seq_mode-shared_named_expr_/formatted.sql"

0 commit comments

Comments
 (0)