Skip to content

Commit

Permalink
validate & lineage modes in dqrun (ydb-platform#1290)
Browse files Browse the repository at this point in the history
* init

* fix
  • Loading branch information
vitstn authored Jan 25, 2024
1 parent 83ca59e commit 2547396
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions ydb/library/yql/tools/dqrun/dqrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ struct TRunOptions {
TString User;
TMaybe<TString> BindingsFile;
NYson::EYsonFormat ResultsFormat;
bool ValidateOnly = false;
bool LineageOnly = false;
IOutputStream* LineageStream = nullptr;
bool OptimizeOnly = false;
bool PeepholeOnly = false;
bool TraceOpt = false;
Expand Down Expand Up @@ -334,7 +337,14 @@ int RunProgram(TProgramPtr program, const TRunOptions& options, const THashMap<T
}

TProgram::TStatus status = TProgram::TStatus::Error;
if (options.OptimizeOnly) {
if (options.ValidateOnly) {
Cout << "Validate program..." << Endl;
status = program->Validate(options.User);
} else if (options.LineageOnly) {
Cout << "Calculate lineage..." << Endl;
auto config = TOptPipelineConfigurator(program, options.PrintPlan, options.TracePlan);
status = program->LineageWithConfig(options.User, config);
} else if (options.OptimizeOnly) {
Cout << "Optimize program..." << Endl;
auto config = TOptPipelineConfigurator(program, options.PrintPlan, options.TracePlan);
status = program->OptimizeWithConfig(options.User, config);
Expand All @@ -350,7 +360,7 @@ int RunProgram(TProgramPtr program, const TRunOptions& options, const THashMap<T
}
return 1;
}
program->Print(options.ExprOut, options.TracePlan);
program->Print(options.ExprOut, (options.ValidateOnly || options.LineageOnly) ? nullptr : options.TracePlan);

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

if (options.LineageStream) {
if (auto st = program->GetLineage()) {
TStringInput in(*st);
NYson::ReformatYsonStream(&in, options.LineageStream, NYson::EYsonFormat::Pretty);
}
}

if (options.StatisticsStream) {
if (auto st = program->GetStatistics(true)) {
TStringInput in(*st);
Expand Down Expand Up @@ -463,6 +480,14 @@ int RunMain(int argc, const char* argv[])
opts.AddLongOption("udfs-dir", "Load all shared libraries with UDFs found"
" in given directory")
.StoreResult(&udfsDir);
opts.AddLongOption("validate", "validate expression")
.Optional()
.NoArgument()
.SetFlag(&runOptions.ValidateOnly);
opts.AddLongOption("lineage", "lineage expression")
.Optional()
.NoArgument()
.SetFlag(&runOptions.LineageOnly);
opts.AddLongOption('O', "optimize", "optimize expression")
.Optional()
.NoArgument()
Expand Down Expand Up @@ -911,6 +936,10 @@ int RunMain(int argc, const char* argv[])
}
}

if (runOptions.LineageOnly) {
runOptions.LineageStream = &Cout;
}

int result = RunProgram(std::move(program), runOptions, clusters);
if (res.Has("metrics")) {
NProto::TMetricsRegistrySnapshot snapshot;
Expand Down

0 comments on commit 2547396

Please sign in to comment.