Skip to content

Commit fb94f5f

Browse files
authored
Merge a4eb00c into 3204f33
2 parents 3204f33 + a4eb00c commit fb94f5f

File tree

8 files changed

+83
-8
lines changed

8 files changed

+83
-8
lines changed

ydb/library/yql/providers/config/yql_config_provider.cpp

+42-8
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ namespace {
168168
for (auto& arg: flag.GetArgs()) {
169169
args.push_back(arg);
170170
}
171-
if (!ApplyFlag(pos, flag.GetName(), args, ctx)) {
171+
if (!ApplyFlag(pos, flag.GetName(), args, ctx, 0)) {
172172
return false;
173173
}
174174
}
@@ -260,15 +260,23 @@ namespace {
260260
for (size_t i = 3; i < node->ChildrenSize(); ++i) {
261261
if (node->Child(i)->IsCallable("EvaluateAtom")) {
262262
hasPendingEvaluations = true;
263-
return res;
263+
break;
264264
}
265265
if (!EnsureAtom(*node->Child(i), ctx)) {
266266
return {};
267267
}
268268
args.push_back(node->Child(i)->Content());
269269
}
270270

271-
if (!ApplyFlag(ctx.GetPosition(node->Child(2)->Pos()), command, args, ctx)) {
271+
if (hasPendingEvaluations) {
272+
if (!ValidateEvaluation(command, *node, ctx)) {
273+
return {};
274+
}
275+
276+
return res;
277+
}
278+
279+
if (!ApplyFlag(ctx.GetPosition(node->Child(2)->Pos()), command, args, ctx, node->UniqueId())) {
272280
return {};
273281
}
274282

@@ -460,7 +468,30 @@ namespace {
460468
return true;
461469
}
462470

463-
bool ApplyFlag(const TPosition& pos, const TStringBuf name, const TVector<TStringBuf>& args, TExprContext& ctx) {
471+
bool ValidateEvaluation(const TStringBuf name, const TExprNode& node, TExprContext& ctx) {
472+
if (name == "AddFileByUrl" || name == "AddFolderByUrl") {
473+
if (node.ChildrenSize() < 4) {
474+
ctx.AddError(TIssue(ctx.GetPosition(node.Pos()), TStringBuilder() << "Expected at least 4 arguments, but got " << node.ChildrenSize()));
475+
return false;
476+
}
477+
478+
if (node.Child(3)->IsCallable("EvaluateAtom")) {
479+
return true;
480+
}
481+
482+
if (!PendingEvaluationFiles.insert({TString(node.Child(3)->Content()), node.UniqueId()}).second) {
483+
ctx.AddError(TIssue(ctx.GetPosition(node.Pos()), TStringBuilder() << "Detected evaluation cycle for file: " << node.Child(3)->Content()));
484+
return false;
485+
}
486+
487+
return true;
488+
} else {
489+
return true;
490+
}
491+
}
492+
493+
bool ApplyFlag(const TPosition& pos, const TStringBuf name, const TVector<TStringBuf>& args, TExprContext& ctx,
494+
ui64 nodeUniqueId) {
464495
if (!IsSettingAllowed(pos, name, ctx)) {
465496
return false;
466497
}
@@ -474,15 +505,15 @@ namespace {
474505
return false;
475506
}
476507
} else if (name == "AddFileByUrl") {
477-
if (!AddFileByUrl(pos, args, ctx)) {
508+
if (!AddFileByUrl(pos, args, ctx, nodeUniqueId)) {
478509
return false;
479510
}
480511
} else if (name == "SetFileOption") {
481512
if (!SetFileOption(pos, args, ctx)) {
482513
return false;
483514
}
484515
} else if (name == "AddFolderByUrl") {
485-
if (!AddFolderByUrl(pos, args, ctx)) {
516+
if (!AddFolderByUrl(pos, args, ctx, nodeUniqueId)) {
486517
return false;
487518
}
488519
} else if (name == "SetPackageVersion") {
@@ -985,12 +1016,13 @@ namespace {
9851016
return true;
9861017
}
9871018

988-
bool AddFileByUrl(const TPosition& pos, const TVector<TStringBuf>& args, TExprContext& ctx) {
1019+
bool AddFileByUrl(const TPosition& pos, const TVector<TStringBuf>& args, TExprContext& ctx, ui64 nodeUniqueId) {
9891020
if (args.size() < 2 || args.size() > 3) {
9901021
ctx.AddError(TIssue(pos, TStringBuilder() << "Expected 2 or 3 arguments, but got " << args.size()));
9911022
return false;
9921023
}
9931024

1025+
PendingEvaluationFiles.erase({TString(args[0]),nodeUniqueId});
9941026
TStringBuf token = args.size() == 3 ? args[2] : TStringBuf();
9951027
if (token) {
9961028
if (auto cred = Types.Credentials->FindCredential(token)) {
@@ -1104,12 +1136,13 @@ namespace {
11041136
return url;
11051137
}
11061138

1107-
bool AddFolderByUrl(const TPosition& pos, const TVector<TStringBuf>& args, TExprContext& ctx) {
1139+
bool AddFolderByUrl(const TPosition& pos, const TVector<TStringBuf>& args, TExprContext& ctx, ui64 nodeUniqueId) {
11081140
if (args.size() < 2 || args.size() > 3) {
11091141
ctx.AddError(TIssue(pos, TStringBuilder() << "Expected 2 or 3 arguments, but got " << args.size()));
11101142
return false;
11111143
}
11121144

1145+
PendingEvaluationFiles.erase({TString(args[0]),nodeUniqueId});
11131146
TStringBuf token = args.size() == 3 ? args[2] : TStringBuf();
11141147
if (token) {
11151148
if (auto cred = Types.Credentials->FindCredential(token)) {
@@ -1206,6 +1239,7 @@ namespace {
12061239
TString Username;
12071240
const TAllowSettingPolicy Policy;
12081241
TOperationStatistics Statistics;
1242+
THashSet<std::pair<TString, ui64>> PendingEvaluationFiles;
12091243
};
12101244
}
12111245

ydb/library/yql/tests/sql/dq_file/part8/canondata/result.json

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
}
2222
],
2323
"test.test[action-evaluate_pure--Results]": [],
24+
"test.test[action-file_cycle--Results]": [
25+
{
26+
"uri": "file://test.test_action-file_cycle--Results_/extracted"
27+
}
28+
],
2429
"test.test[action-nested_eval-default.txt-Analyze]": [
2530
{
2631
"checksum": "b4dd508a329723c74293d80f0278c705",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<tmp_path>/program.sql:<main>: Error: Pre type annotation
2+
3+
<tmp_path>/program.sql:<main>:2:18: Error: Detected evaluation cycle for file: f
4+
pragma file("f", $p);
5+
^

ydb/library/yql/tests/sql/sql2yql/canondata/result.json

+14
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,13 @@
412412
"uri": "https://{canondata_backend}/1936947/659b615f15086142a8960946dabd06b519d43335/resource.tar.gz#test_sql2yql.test_action-export_action_/sql.yql"
413413
}
414414
],
415+
"test_sql2yql.test[action-file_cycle]": [
416+
{
417+
"checksum": "095c2c315ba26037554c056a02f5af05",
418+
"size": 343,
419+
"uri": "https://{canondata_backend}/1871002/4d084a25cea0c62bd09f3c9e9e7c2b56d112c5b1/resource.tar.gz#test_sql2yql.test_action-file_cycle_/sql.yql"
420+
}
421+
],
415422
"test_sql2yql.test[action-inline_action]": [
416423
{
417424
"checksum": "d019514b3fd1f8a7c0f9d37db4231b93",
@@ -17891,6 +17898,13 @@
1789117898
"uri": "https://{canondata_backend}/1871102/17992aa919577eec0f31ef167084ab70f41ccc80/resource.tar.gz#test_sql_format.test_action-export_action_/formatted.sql"
1789217899
}
1789317900
],
17901+
"test_sql_format.test[action-file_cycle]": [
17902+
{
17903+
"checksum": "5476df82092007027246993752e24f68",
17904+
"size": 45,
17905+
"uri": "https://{canondata_backend}/1871002/4d084a25cea0c62bd09f3c9e9e7c2b56d112c5b1/resource.tar.gz#test_sql_format.test_action-file_cycle_/formatted.sql"
17906+
}
17907+
],
1789417908
"test_sql_format.test[action-inline_action]": [
1789517909
{
1789617910
"checksum": "7da554999ea3520183678c730ae2fffb",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
xfail
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$p=FileContent("f");
2+
pragma file("f", $p);
3+

ydb/library/yql/tests/sql/yt_native_file/part8/canondata/result.json

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
"uri": "https://{canondata_backend}/1900335/4871e48d29e4933514d3ed0c9c5d19de571eda1f/resource.tar.gz#test.test_action-evaluate_pure--Results_/results.txt"
2121
}
2222
],
23+
"test.test[action-file_cycle--Debug]": [],
24+
"test.test[action-file_cycle--Plan]": [],
25+
"test.test[action-file_cycle--Results]": [
26+
{
27+
"uri": "file://test.test_action-file_cycle--Results_/extracted"
28+
}
29+
],
2330
"test.test[action-nested_eval-default.txt-Debug]": [
2431
{
2532
"checksum": "79af7d3cdd20c4123718aae10c3202d7",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<tmp_path>/program.sql:<main>: Error: Pre type annotation
2+
3+
<tmp_path>/program.sql:<main>:2:18: Error: Detected evaluation cycle for file: f
4+
pragma file("f", $p);
5+
^

0 commit comments

Comments
 (0)