@@ -88,9 +88,6 @@ struct TExecutionOptions {
8888
8989 TRequestOptions GetSchemeQueryOptions () const {
9090 TString sql = SchemeQuery;
91- if (UseTemplates) {
92- ReplaceYqlTokenTemplate (sql);
93- }
9491
9592 return {
9693 .Query = sql,
@@ -108,7 +105,6 @@ struct TExecutionOptions {
108105
109106 TString sql = ScriptQueries[index];
110107 if (UseTemplates) {
111- ReplaceYqlTokenTemplate (sql);
112108 SubstGlobal (sql, " ${QUERY_ID}" , ToString (queryId));
113109 }
114110
@@ -271,16 +267,6 @@ struct TExecutionOptions {
271267 ythrow yexception () << " Cannot format storage without real PDisks, please use --storage-path" ;
272268 }
273269 }
274-
275- private:
276- static void ReplaceYqlTokenTemplate (TString& sql) {
277- const TString variableName = TStringBuilder () << " ${" << YQL_TOKEN_VARIABLE << " }" ;
278- if (const TString& yqlToken = GetEnv (YQL_TOKEN_VARIABLE)) {
279- SubstGlobal (sql, variableName, yqlToken);
280- } else if (sql.Contains (variableName)) {
281- ythrow yexception () << " Failed to replace ${YQL_TOKEN} template, please specify YQL_TOKEN environment variable\n " ;
282- }
283- }
284270};
285271
286272
@@ -446,6 +432,7 @@ class TMain : public TMainClassArgs {
446432 TExecutionOptions ExecutionOptions;
447433 TRunnerOptions RunnerOptions;
448434
435+ std::unordered_map<TString, TString> Templates;
449436 THashMap<TString, TString> TablesMapping;
450437 TVector<TString> UdfsPaths;
451438 TString UdfsDirectory;
@@ -537,6 +524,31 @@ class TMain : public TMainClassArgs {
537524 .NoArgument ()
538525 .SetFlag (&ExecutionOptions.UseTemplates );
539526
527+ options.AddLongOption (" var-template" , " Add template from environment variables or file for -s and -p queries (use variable@file for files)" )
528+ .RequiredArgument (" variable" )
529+ .Handler1 ([this ](const NLastGetopt::TOptsParser* option) {
530+ TStringBuf variable;
531+ TStringBuf filePath;
532+ TStringBuf (option->CurVal ()).Split (' @' , variable, filePath);
533+ if (variable.empty ()) {
534+ ythrow yexception () << " Variable name should not be empty" ;
535+ }
536+
537+ TString value;
538+ if (!filePath.empty ()) {
539+ value = LoadFile (TString (filePath));
540+ } else {
541+ value = GetEnv (TString (variable));
542+ if (!value) {
543+ ythrow yexception () << " Invalid env template, can not find value for variable '" << variable << " '" ;
544+ }
545+ }
546+
547+ if (!Templates.emplace (variable, value).second ) {
548+ ythrow yexception () << " Got duplicated template variable name '" << variable << " '" ;
549+ }
550+ });
551+
540552 options.AddLongOption (' t' , " table" , " File with input table (can be used by YT with -E flag), table@file" )
541553 .RequiredArgument (" table@file" )
542554 .Handler1 ([this ](const NLastGetopt::TOptsParser* option) {
@@ -845,6 +857,11 @@ class TMain : public TMainClassArgs {
845857 .NoArgument ()
846858 .SetFlag (&EmulateYt);
847859
860+ options.AddLongOption (' H' , " health-check" , " Level of health check before start (max level 2)" )
861+ .RequiredArgument (" uint" )
862+ .DefaultValue (1 )
863+ .StoreResult (&RunnerOptions.YdbSettings .HealthCheckLevel );
864+
848865 options.AddLongOption (" domain" , " Test cluster domain name" )
849866 .RequiredArgument (" name" )
850867 .DefaultValue (RunnerOptions.YdbSettings .DomainName )
@@ -862,9 +879,8 @@ class TMain : public TMainClassArgs {
862879 .RequiredArgument (" path" )
863880 .InsertTo (&RunnerOptions.YdbSettings .ServerlessTenants );
864881
865- options.AddLongOption (" storage-size" , " Domain storage size in gigabytes" )
882+ options.AddLongOption (" storage-size" , " Domain storage size in gigabytes (32 GiB by default) " )
866883 .RequiredArgument (" uint" )
867- .DefaultValue (32 )
868884 .StoreMappedResultT <ui32>(&RunnerOptions.YdbSettings .DiskSize , [](ui32 diskSize) {
869885 return static_cast <ui64>(diskSize) << 30 ;
870886 });
@@ -898,6 +914,11 @@ class TMain : public TMainClassArgs {
898914 int DoRun (NLastGetopt::TOptsParseResult&&) override {
899915 ExecutionOptions.Validate (RunnerOptions);
900916
917+ ReplaceTemplates (ExecutionOptions.SchemeQuery );
918+ for (auto & sql : ExecutionOptions.ScriptQueries ) {
919+ ReplaceTemplates (sql);
920+ }
921+
901922 RunnerOptions.YdbSettings .YqlToken = YqlToken;
902923 RunnerOptions.YdbSettings .FunctionRegistry = CreateFunctionRegistry (UdfsDirectory, UdfsPaths, ExcludeLinkedUdfs).Get ();
903924
@@ -943,6 +964,21 @@ class TMain : public TMainClassArgs {
943964
944965 return 0 ;
945966 }
967+
968+ private:
969+ void ReplaceTemplates (TString& sql) const {
970+ for (const auto & [variable, value] : Templates) {
971+ SubstGlobal (sql, TStringBuilder () << " ${" << variable <<" }" , value);
972+ }
973+ if (ExecutionOptions.UseTemplates ) {
974+ const TString tokenVariableName = TStringBuilder () << " ${" << YQL_TOKEN_VARIABLE << " }" ;
975+ if (const TString& yqlToken = GetEnv (YQL_TOKEN_VARIABLE)) {
976+ SubstGlobal (sql, tokenVariableName, yqlToken);
977+ } else if (sql.Contains (tokenVariableName)) {
978+ ythrow yexception () << " Failed to replace ${YQL_TOKEN} template, please specify YQL_TOKEN environment variable" ;
979+ }
980+ }
981+ }
946982};
947983
948984
@@ -972,7 +1008,7 @@ void FloatingPointExceptionHandler(int) {
9721008
9731009 Cerr << colors.Red () << " ======= floating point exception call stack ========" << colors.Default () << Endl;
9741010 FormatBackTrace (&Cerr);
975- Cerr << colors.Red () << " ==============================================" << colors.Default () << Endl;
1011+ Cerr << colors.Red () << " ==================================================== " << colors.Default () << Endl;
9761012
9771013 abort ();
9781014}
0 commit comments