1
1
#include " src/kqp_runner.h"
2
2
3
- #include < cstdio>
4
-
5
3
#include < contrib/libs/protobuf/src/google/protobuf/text_format.h>
6
4
7
5
#include < library/cpp/colorizer/colors.h>
15
13
16
14
#include < ydb/library/aclib/aclib.h>
17
15
#include < ydb/library/yaml_config/yaml_config.h>
16
+
18
17
#include < yql/essentials/minikql/invoke_builtins/mkql_builtins.h>
18
+ #include < yql/essentials/public/udf/udf_static_registry.h>
19
+
19
20
#include < yt/yql/providers/yt/gateway/file/yql_yt_file.h>
20
21
#include < yt/yql/providers/yt/gateway/file/yql_yt_file_comp_nodes.h>
21
22
#include < yt/yql/providers/yt/lib/yt_download/yt_download.h>
22
- #include < yql/essentials/public/udf/udf_static_registry.h>
23
23
24
24
25
25
namespace NKqpRun {
@@ -135,7 +135,7 @@ struct TExecutionOptions {
135
135
void ValidateOptionsSizes (const TRunnerOptions& runnerOptions) const {
136
136
const auto checker = [numberQueries = ScriptQueries.size ()](size_t checkSize, const TString& optionName) {
137
137
if (checkSize > numberQueries) {
138
- ythrow yexception () << " Too many " << optionName << " . Specified " << checkSize << " , when number of queries is " << numberQueries;
138
+ ythrow yexception () << " Too many " << optionName << " . Specified " << checkSize << " , when number of script queries is " << numberQueries;
139
139
}
140
140
};
141
141
@@ -431,6 +431,9 @@ class TMain : public TMainClassArgs {
431
431
bool ExcludeLinkedUdfs = false ;
432
432
bool EmulateYt = false ;
433
433
434
+ std::optional<NActors::NLog::EPriority> DefaultLogPriority;
435
+ std::unordered_map<NKikimrServices::EServiceKikimr, NActors::NLog::EPriority> LogPriorities;
436
+
434
437
static TString LoadFile (const TString& file) {
435
438
return TFileInput (file).ReadAll ();
436
439
}
@@ -466,6 +469,10 @@ class TMain : public TMainClassArgs {
466
469
return choices;
467
470
}
468
471
472
+ bool Contains (const TString& choice) const {
473
+ return ChoicesMap.contains (choice);
474
+ }
475
+
469
476
private:
470
477
const std::map<TString, TResult> ChoicesMap;
471
478
};
@@ -483,11 +490,13 @@ class TMain : public TMainClassArgs {
483
490
.Handler1 ([this ](const NLastGetopt::TOptsParser* option) {
484
491
ExecutionOptions.SchemeQuery = LoadFile (option->CurVal ());
485
492
});
493
+
486
494
options.AddLongOption (' p' , " script-query" , " Script query to execute (typically DML query)" )
487
495
.RequiredArgument (" file" )
488
496
.Handler1 ([this ](const NLastGetopt::TOptsParser* option) {
489
497
ExecutionOptions.ScriptQueries .emplace_back (LoadFile (option->CurVal ()));
490
498
});
499
+
491
500
options.AddLongOption (" templates" , " Enable templates for -s and -p queries, such as ${YQL_TOKEN} and ${QUERY_ID}" )
492
501
.NoArgument ()
493
502
.SetFlag (&ExecutionOptions.UseTemplates );
@@ -499,10 +508,10 @@ class TMain : public TMainClassArgs {
499
508
TStringBuf filePath;
500
509
TStringBuf (option->CurVal ()).Split (' @' , tableName, filePath);
501
510
if (tableName.empty () || filePath.empty ()) {
502
- ythrow yexception () << " Incorrect table mapping, expected form table@file, e.g. yt.Root/plato.Input@input.txt" ;
511
+ ythrow yexception () << " Incorrect table mapping, expected form table@file, e. g. yt.Root/plato.Input@input.txt" ;
503
512
}
504
513
if (TablesMapping.contains (tableName)) {
505
- ythrow yexception () << " Got duplicate table name: " << tableName;
514
+ ythrow yexception () << " Got duplicated table name: " << tableName;
506
515
}
507
516
TablesMapping[tableName] = filePath;
508
517
});
@@ -523,9 +532,11 @@ class TMain : public TMainClassArgs {
523
532
options.AddLongOption (' u' , " udf" , " Load shared library with UDF by given path" )
524
533
.RequiredArgument (" file" )
525
534
.EmplaceTo (&UdfsPaths);
535
+
526
536
options.AddLongOption (" udfs-dir" , " Load all shared libraries with UDFs found in given directory" )
527
537
.RequiredArgument (" directory" )
528
538
.StoreResult (&UdfsDirectory);
539
+
529
540
options.AddLongOption (" exclude-linked-udfs" , " Exclude linked udfs when same udf passed from -u or --udfs-dir" )
530
541
.NoArgument ()
531
542
.SetFlag (&ExcludeLinkedUdfs);
@@ -540,13 +551,51 @@ class TMain : public TMainClassArgs {
540
551
std::remove (file.c_str ());
541
552
}
542
553
});
554
+
555
+ TChoices<NActors::NLog::EPriority> logPriority ({
556
+ {" emerg" , NActors::NLog::EPriority::PRI_EMERG},
557
+ {" alert" , NActors::NLog::EPriority::PRI_ALERT},
558
+ {" crit" , NActors::NLog::EPriority::PRI_CRIT},
559
+ {" error" , NActors::NLog::EPriority::PRI_ERROR},
560
+ {" warn" , NActors::NLog::EPriority::PRI_WARN},
561
+ {" notice" , NActors::NLog::EPriority::PRI_NOTICE},
562
+ {" info" , NActors::NLog::EPriority::PRI_INFO},
563
+ {" debug" , NActors::NLog::EPriority::PRI_DEBUG},
564
+ {" trace" , NActors::NLog::EPriority::PRI_TRACE},
565
+ });
566
+ options.AddLongOption (" log-default" , " Default log priority" )
567
+ .RequiredArgument (" priority" )
568
+ .Choices (logPriority.GetChoices ())
569
+ .StoreMappedResultT <TString>(&DefaultLogPriority, logPriority);
570
+
571
+ options.AddLongOption (" log" , " Component log priority in format <component>=<priority> (e. g. KQP_YQL=trace)" )
572
+ .RequiredArgument (" component priority" )
573
+ .Handler1 ([this , logPriority](const NLastGetopt::TOptsParser* option) {
574
+ TStringBuf component;
575
+ TStringBuf priority;
576
+ TStringBuf (option->CurVal ()).Split (' =' , component, priority);
577
+ if (component.empty () || priority.empty ()) {
578
+ ythrow yexception () << " Incorrect log setting, expected form component=priority, e. g. KQP_YQL=trace" ;
579
+ }
580
+
581
+ const auto service = GetLogService (TString (component));
582
+ if (LogPriorities.contains (service)) {
583
+ ythrow yexception () << " Got duplicated log service name: " << component;
584
+ }
585
+
586
+ if (!logPriority.Contains (TString (priority))) {
587
+ ythrow yexception () << " Incorrect log priority: " << priority;
588
+ }
589
+ LogPriorities[service] = logPriority (TString (priority));
590
+ });
591
+
543
592
TChoices<TRunnerOptions::ETraceOptType> traceOpt ({
544
593
{" all" , TRunnerOptions::ETraceOptType::All},
545
594
{" scheme" , TRunnerOptions::ETraceOptType::Scheme},
546
595
{" script" , TRunnerOptions::ETraceOptType::Script},
547
596
{" disabled" , TRunnerOptions::ETraceOptType::Disabled}
548
597
});
549
- options.AddLongOption (' T' , " trace-opt" , " print AST in the begin of each transformation (use script@<query id> for tracing one -p query)" )
598
+ options.AddLongOption (' T' , " trace-opt" , " Print AST in the begin of each transformation (use script@<query id> for tracing one -p query)" )
550
599
.RequiredArgument (" trace-opt-query" )
551
600
.DefaultValue (" disabled" )
552
601
.Choices (traceOpt.GetChoices ())
@@ -555,9 +604,11 @@ class TMain : public TMainClassArgs {
555
604
RunnerOptions.YdbSettings .TraceOptEnabled = traceOptType != NKqpRun::TRunnerOptions::ETraceOptType::Disabled;
556
605
return traceOptType;
557
606
});
558
- options.AddLongOption (' I' , " trace-opt-index" , " index of -p query to use --trace-opt, starts from zero" )
607
+
608
+ options.AddLongOption (' I' , " trace-opt-index" , " Index of -p query to use --trace-opt, starts from zero" )
559
609
.RequiredArgument (" uint" )
560
610
.StoreResult (&RunnerOptions.TraceOptScriptId );
611
+
561
612
options.AddLongOption (" trace-id" , " Trace id for -p queries" )
562
613
.RequiredArgument (" id" )
563
614
.EmplaceTo (&ExecutionOptions.TraceIds );
@@ -566,10 +617,12 @@ class TMain : public TMainClassArgs {
566
617
.RequiredArgument (" file" )
567
618
.DefaultValue (" -" )
568
619
.StoreMappedResultT <TString>(&RunnerOptions.ResultOutput , &GetDefaultOutput);
620
+
569
621
options.AddLongOption (' L' , " result-rows-limit" , " Rows limit for script execution results" )
570
622
.RequiredArgument (" uint" )
571
623
.DefaultValue (0 )
572
624
.StoreResult (&ExecutionOptions.ResultsRowsLimit );
625
+
573
626
TChoices<TRunnerOptions::EResultOutputFormat> resultFormat ({
574
627
{" rows" , TRunnerOptions::EResultOutputFormat::RowsJson},
575
628
{" full-json" , TRunnerOptions::EResultOutputFormat::FullJson},
@@ -596,6 +649,7 @@ class TMain : public TMainClassArgs {
596
649
.Handler1 ([this ](const NLastGetopt::TOptsParser* option) {
597
650
RunnerOptions.ScriptQueryPlanOutputs .emplace_back (GetDefaultOutput (TString (option->CurValOrDef ())));
598
651
});
652
+
599
653
options.AddLongOption (" script-statistics" , " File with script inprogress statistics" )
600
654
.RequiredArgument (" file" )
601
655
.Handler1 ([this ](const NLastGetopt::TOptsParser* option) {
@@ -605,6 +659,7 @@ class TMain : public TMainClassArgs {
605
659
}
606
660
RunnerOptions.InProgressStatisticsOutputFiles .emplace_back (file);
607
661
});
662
+
608
663
TChoices<NYdb::NConsoleClient::EDataFormat> planFormat ({
609
664
{" pretty" , NYdb::NConsoleClient::EDataFormat::Pretty},
610
665
{" table" , NYdb::NConsoleClient::EDataFormat::PrettyTable},
@@ -641,19 +696,21 @@ class TMain : public TMainClassArgs {
641
696
TString choice (option->CurValOrDef ());
642
697
ExecutionOptions.ExecutionCases .emplace_back (executionCase (choice));
643
698
});
699
+
644
700
options.AddLongOption (" inflight-limit" , " In flight limit for async queries (use 0 for unlimited)" )
645
701
.RequiredArgument (" uint" )
646
702
.DefaultValue (0 )
647
703
.StoreResult (&RunnerOptions.YdbSettings .AsyncQueriesSettings .InFlightLimit );
648
- TChoices<TAsyncQueriesSettings::EVerbose> verbose ({
649
- {" each-query" , TAsyncQueriesSettings::EVerbose::EachQuery},
650
- {" final" , TAsyncQueriesSettings::EVerbose::Final}
651
- });
652
704
653
705
options.AddLongOption (" verbose" , " Common verbose level (max level 2)" )
654
706
.RequiredArgument (" uint" )
655
707
.DefaultValue (1 )
656
708
.StoreResult (&RunnerOptions.YdbSettings .VerboseLevel );
709
+
710
+ TChoices<TAsyncQueriesSettings::EVerbose> verbose ({
711
+ {" each-query" , TAsyncQueriesSettings::EVerbose::EachQuery},
712
+ {" final" , TAsyncQueriesSettings::EVerbose::Final}
713
+ });
657
714
options.AddLongOption (" async-verbose" , " Verbose type for async queries" )
658
715
.RequiredArgument (" type" )
659
716
.DefaultValue (" each-query" )
@@ -690,10 +747,12 @@ class TMain : public TMainClassArgs {
690
747
.RequiredArgument (" uint" )
691
748
.DefaultValue (ExecutionOptions.LoopCount )
692
749
.StoreResult (&ExecutionOptions.LoopCount );
750
+
693
751
options.AddLongOption (" loop-delay" , " Delay in milliseconds between loop steps" )
694
752
.RequiredArgument (" uint" )
695
753
.DefaultValue (0 )
696
754
.StoreMappedResultT <ui64>(&ExecutionOptions.LoopDelay , &TDuration::MilliSeconds<ui64>);
755
+
697
756
options.AddLongOption (" continue-after-fail" , " Don't not stop requests execution after fails" )
698
757
.NoArgument ()
699
758
.SetFlag (&ExecutionOptions.ContinueAfterFail );
@@ -803,12 +862,19 @@ class TMain : public TMainClassArgs {
803
862
804
863
RunnerOptions.YdbSettings .YqlToken = YqlToken;
805
864
RunnerOptions.YdbSettings .FunctionRegistry = CreateFunctionRegistry (UdfsDirectory, UdfsPaths, ExcludeLinkedUdfs).Get ();
865
+
866
+ auto & appConfig = RunnerOptions.YdbSettings .AppConfig ;
806
867
if (ExecutionOptions.ResultsRowsLimit ) {
807
- RunnerOptions.YdbSettings .AppConfig .MutableQueryServiceConfig ()->SetScriptResultRowsLimit (ExecutionOptions.ResultsRowsLimit );
868
+ appConfig.MutableQueryServiceConfig ()->SetScriptResultRowsLimit (ExecutionOptions.ResultsRowsLimit );
869
+ }
870
+
871
+ if (DefaultLogPriority) {
872
+ appConfig.MutableLogConfig ()->SetDefaultLevel (*DefaultLogPriority);
808
873
}
874
+ ModifyLogPriorities (LogPriorities, *appConfig.MutableLogConfig ());
809
875
810
876
if (EmulateYt) {
811
- const auto & fileStorageConfig = RunnerOptions. YdbSettings . AppConfig .GetQueryServiceConfig ().GetFileStorage ();
877
+ const auto & fileStorageConfig = appConfig .GetQueryServiceConfig ().GetFileStorage ();
812
878
auto fileStorage = WithAsync (CreateFileStorage (fileStorageConfig, {MakeYtDownloader (fileStorageConfig)}));
813
879
auto ytFileServices = NYql::NFile::TYtFileServices::Make (RunnerOptions.YdbSettings .FunctionRegistry .Get (), TablesMapping, fileStorage);
814
880
RunnerOptions.YdbSettings .YtGateway = NYql::CreateYtFileGateway (ytFileServices);
0 commit comments