Skip to content

Commit 2547396

Browse files
authored
validate & lineage modes in dqrun (#1290)
* init * fix
1 parent 83ca59e commit 2547396

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

ydb/library/yql/tools/dqrun/dqrun.cpp

+31-2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ struct TRunOptions {
106106
TString User;
107107
TMaybe<TString> BindingsFile;
108108
NYson::EYsonFormat ResultsFormat;
109+
bool ValidateOnly = false;
110+
bool LineageOnly = false;
111+
IOutputStream* LineageStream = nullptr;
109112
bool OptimizeOnly = false;
110113
bool PeepholeOnly = false;
111114
bool TraceOpt = false;
@@ -334,7 +337,14 @@ int RunProgram(TProgramPtr program, const TRunOptions& options, const THashMap<T
334337
}
335338

336339
TProgram::TStatus status = TProgram::TStatus::Error;
337-
if (options.OptimizeOnly) {
340+
if (options.ValidateOnly) {
341+
Cout << "Validate program..." << Endl;
342+
status = program->Validate(options.User);
343+
} else if (options.LineageOnly) {
344+
Cout << "Calculate lineage..." << Endl;
345+
auto config = TOptPipelineConfigurator(program, options.PrintPlan, options.TracePlan);
346+
status = program->LineageWithConfig(options.User, config);
347+
} else if (options.OptimizeOnly) {
338348
Cout << "Optimize program..." << Endl;
339349
auto config = TOptPipelineConfigurator(program, options.PrintPlan, options.TracePlan);
340350
status = program->OptimizeWithConfig(options.User, config);
@@ -350,7 +360,7 @@ int RunProgram(TProgramPtr program, const TRunOptions& options, const THashMap<T
350360
}
351361
return 1;
352362
}
353-
program->Print(options.ExprOut, options.TracePlan);
363+
program->Print(options.ExprOut, (options.ValidateOnly || options.LineageOnly) ? nullptr : options.TracePlan);
354364

355365
Cout << "Getting results..." << Endl;
356366
if (program->HasResults()) {
@@ -363,6 +373,13 @@ int RunProgram(TProgramPtr program, const TRunOptions& options, const THashMap<T
363373
yson.OnEndList();
364374
}
365375

376+
if (options.LineageStream) {
377+
if (auto st = program->GetLineage()) {
378+
TStringInput in(*st);
379+
NYson::ReformatYsonStream(&in, options.LineageStream, NYson::EYsonFormat::Pretty);
380+
}
381+
}
382+
366383
if (options.StatisticsStream) {
367384
if (auto st = program->GetStatistics(true)) {
368385
TStringInput in(*st);
@@ -463,6 +480,14 @@ int RunMain(int argc, const char* argv[])
463480
opts.AddLongOption("udfs-dir", "Load all shared libraries with UDFs found"
464481
" in given directory")
465482
.StoreResult(&udfsDir);
483+
opts.AddLongOption("validate", "validate expression")
484+
.Optional()
485+
.NoArgument()
486+
.SetFlag(&runOptions.ValidateOnly);
487+
opts.AddLongOption("lineage", "lineage expression")
488+
.Optional()
489+
.NoArgument()
490+
.SetFlag(&runOptions.LineageOnly);
466491
opts.AddLongOption('O', "optimize", "optimize expression")
467492
.Optional()
468493
.NoArgument()
@@ -911,6 +936,10 @@ int RunMain(int argc, const char* argv[])
911936
}
912937
}
913938

939+
if (runOptions.LineageOnly) {
940+
runOptions.LineageStream = &Cout;
941+
}
942+
914943
int result = RunProgram(std::move(program), runOptions, clusters);
915944
if (res.Has("metrics")) {
916945
NProto::TMetricsRegistrySnapshot snapshot;

0 commit comments

Comments
 (0)