@@ -52,14 +52,14 @@ class TKqpCompileActor : public TActorBootstrapped<TKqpCompileActor> {
52
52
TKqpDbCountersPtr dbCounters, std::optional<TKqpFederatedQuerySetup> federatedQuerySetup,
53
53
const TIntrusivePtr<TUserRequestContext>& userRequestContext,
54
54
NWilson::TTraceId traceId, TKqpTempTablesState::TConstPtr tempTablesState, bool collectFullDiagnostics,
55
- ECompileActorAction compileAction, TMaybe<TQueryAst> astResult )
55
+ bool perStatementResult, ECompileActorAction compileAction, TMaybe<TQueryAst> queryAst )
56
56
: Owner(owner)
57
57
, ModuleResolverState(moduleResolverState)
58
58
, Counters(counters)
59
59
, FederatedQuerySetup(federatedQuerySetup)
60
60
, Uid(uid)
61
61
, QueryId(queryId)
62
- , QueryRef(QueryId.Text, QueryId.QueryParameterTypes, astResult )
62
+ , QueryRef(QueryId.Text, QueryId.QueryParameterTypes, queryAst )
63
63
, UserToken(userToken)
64
64
, DbCounters(dbCounters)
65
65
, Config(MakeIntrusive<TKikimrConfiguration>())
@@ -70,8 +70,9 @@ class TKqpCompileActor : public TActorBootstrapped<TKqpCompileActor> {
70
70
, CompileActorSpan(TWilsonKqp::CompileActor, std::move(traceId), " CompileActor" )
71
71
, TempTablesState(std::move(tempTablesState))
72
72
, CollectFullDiagnostics(collectFullDiagnostics)
73
+ , PerStatementResult(perStatementResult)
73
74
, CompileAction(compileAction)
74
- , AstResult (std::move(astResult ))
75
+ , QueryAst (std::move(queryAst ))
75
76
{
76
77
Config->Init (kqpSettings->DefaultSettings .GetDefaultSettings (), QueryId.Cluster , kqpSettings->Settings , false );
77
78
@@ -127,26 +128,22 @@ class TKqpCompileActor : public TActorBootstrapped<TKqpCompileActor> {
127
128
}
128
129
129
130
private:
130
- void SetQueryAst (const TActorContext &ctx) {
131
- TString cluster = QueryId.Cluster ;
131
+
132
+ TVector<TQueryAst> GetAstStatements (const TActorContext &ctx) {
133
+ TString cluster = QueryId.Cluster ;
132
134
TString kqpTablePathPrefix = Config->_KqpTablePathPrefix .Get ().GetRef ();
133
135
ui16 kqpYqlSyntaxVersion = Config->_KqpYqlSyntaxVersion .Get ().GetRef ();
134
136
NSQLTranslation::EBindingsMode bindingsMode = Config->BindingsMode ;
135
137
bool isEnableExternalDataSources = AppData (ctx)->FeatureFlags .GetEnableExternalDataSources ();
136
138
bool isEnablePgConstsToParams = Config->EnablePgConstsToParams ;
139
+ bool perStatementExecution = Config->EnablePerStatementQueryExecution && PerStatementResult;
137
140
138
- auto astResult = ParseQuery (ConvertType (QueryId.Settings .QueryType ), QueryId.Settings .Syntax , QueryId.Text , QueryId.QueryParameterTypes , QueryId.IsSql (), cluster, kqpTablePathPrefix, kqpYqlSyntaxVersion, bindingsMode, isEnableExternalDataSources, isEnablePgConstsToParams);
139
- YQL_ENSURE (astResult.Ast );
140
- if (astResult.Ast ->IsOk ()) {
141
- AstResult = std::move (astResult);
142
- }
141
+ return ParseStatements (ConvertType (QueryId.Settings .QueryType ), QueryId.Settings .Syntax , QueryId.Text , QueryId.QueryParameterTypes , cluster, kqpTablePathPrefix, kqpYqlSyntaxVersion, bindingsMode, isEnableExternalDataSources, isEnablePgConstsToParams, QueryId.IsSql (), perStatementExecution);
143
142
}
144
143
145
144
void StartParsing (const TActorContext &ctx) {
146
- SetQueryAst (ctx);
147
-
148
145
Become (&TKqpCompileActor::CompileState);
149
- ReplyParseResult (ctx);
146
+ ReplyParseResult (ctx, GetAstStatements (ctx) );
150
147
}
151
148
152
149
void StartCompilation (const TActorContext &ctx) {
@@ -352,15 +349,38 @@ class TKqpCompileActor : public TActorBootstrapped<TKqpCompileActor> {
352
349
<< " , at state:" << state);
353
350
}
354
351
355
- void ReplyParseResult (const TActorContext &ctx) {
352
+ void ReplyParseResult (const TActorContext &ctx, TVector<TQueryAst>&& astStatements ) {
356
353
Y_UNUSED (ctx);
354
+
355
+ if (astStatements.empty ()) {
356
+ NYql::TIssue issue (NYql::TPosition (), " Parsing result of query is empty" );
357
+ ReplyError (Ydb::StatusIds::INTERNAL_ERROR, {issue});
358
+ return ;
359
+ }
360
+
361
+ for (size_t statementId = 0 ; statementId < astStatements.size (); ++statementId) {
362
+ if (!astStatements[statementId].Ast || !astStatements[statementId].Ast ->IsOk () || !astStatements[statementId].Ast ->Root ) {
363
+ ALOG_ERROR (NKikimrServices::KQP_COMPILE_ACTOR, " Get parsing result with error"
364
+ << " , self: " << SelfId ()
365
+ << " , owner: " << Owner
366
+ << " , statement id: " << statementId);
367
+
368
+ NYql::TIssue issue (NYql::TPosition (), " Error while parsing query." );
369
+ for (const auto & i : astStatements[statementId].Ast ->Issues ) {
370
+ issue.AddSubIssue (MakeIntrusive<NYql::TIssue>(i));
371
+ }
372
+
373
+ ReplyError (Ydb::StatusIds::INTERNAL_ERROR, {issue});
374
+ return ;
375
+ }
376
+ }
377
+
357
378
ALOG_DEBUG (NKikimrServices::KQP_COMPILE_ACTOR, " Send parsing result"
358
379
<< " , self: " << SelfId ()
359
380
<< " , owner: " << Owner
360
- << (AstResult && AstResult-> Ast -> IsOk () ? " , parsing is successful " : " , parsing is not successful " ));
381
+ << " , statements size : " << astStatements. size ( ));
361
382
362
- auto responseEv = MakeHolder<TEvKqp::TEvParseResponse>(QueryId, std::move (AstResult));
363
- AstResult = Nothing ();
383
+ auto responseEv = MakeHolder<TEvKqp::TEvParseResponse>(QueryId, std::move (astStatements));
364
384
Send (Owner, responseEv.Release ());
365
385
366
386
Counters->ReportCompileFinish (DbCounters);
@@ -379,8 +399,8 @@ class TKqpCompileActor : public TActorBootstrapped<TKqpCompileActor> {
379
399
KqpCompileResult->PreparedQuery = preparedQueryHolder;
380
400
KqpCompileResult->AllowCache = CanCacheQuery (KqpCompileResult->PreparedQuery ->GetPhysicalQuery ());
381
401
382
- if (AstResult ) {
383
- KqpCompileResult->Ast = AstResult ->Ast ;
402
+ if (QueryAst ) {
403
+ KqpCompileResult->Ast = QueryAst ->Ast ;
384
404
}
385
405
}
386
406
@@ -482,8 +502,9 @@ class TKqpCompileActor : public TActorBootstrapped<TKqpCompileActor> {
482
502
TKqpTempTablesState::TConstPtr TempTablesState;
483
503
bool CollectFullDiagnostics;
484
504
505
+ const bool PerStatementResult;
485
506
ECompileActorAction CompileAction;
486
- TMaybe<TQueryAst> AstResult ;
507
+ TMaybe<TQueryAst> QueryAst ;
487
508
};
488
509
489
510
void ApplyServiceConfig (TKikimrConfiguration& kqpConfig, const TTableServiceConfig& serviceConfig) {
@@ -512,6 +533,7 @@ void ApplyServiceConfig(TKikimrConfiguration& kqpConfig, const TTableServiceConf
512
533
kqpConfig.IndexAutoChooserMode = serviceConfig.GetIndexAutoChooseMode ();
513
534
kqpConfig.EnablePgConstsToParams = serviceConfig.GetEnablePgConstsToParams () && serviceConfig.GetEnableAstCache ();
514
535
kqpConfig.ExtractPredicateRangesLimit = serviceConfig.GetExtractPredicateRangesLimit ();
536
+ kqpConfig.EnablePerStatementQueryExecution = serviceConfig.GetEnablePerStatementQueryExecution ();
515
537
516
538
if (const auto limit = serviceConfig.GetResourceManager ().GetMkqlHeavyProgramMemoryLimit ()) {
517
539
kqpConfig._KqpYqlCombinerMemoryLimit = std::max (1_GB, limit - (limit >> 2U ));
@@ -527,14 +549,15 @@ IActor* CreateKqpCompileActor(const TActorId& owner, const TKqpSettings::TConstP
527
549
std::optional<TKqpFederatedQuerySetup> federatedQuerySetup,
528
550
TKqpDbCountersPtr dbCounters, const TIntrusivePtr<TUserRequestContext>& userRequestContext,
529
551
NWilson::TTraceId traceId, TKqpTempTablesState::TConstPtr tempTablesState,
530
- ECompileActorAction compileAction, TMaybe<TQueryAst> astResult, bool collectFullDiagnostics)
552
+ ECompileActorAction compileAction, TMaybe<TQueryAst> queryAst, bool collectFullDiagnostics,
553
+ bool perStatementResult)
531
554
{
532
555
return new TKqpCompileActor (owner, kqpSettings, tableServiceConfig, queryServiceConfig, metadataProviderConfig,
533
556
moduleResolverState, counters,
534
557
uid, query, userToken, dbCounters,
535
558
federatedQuerySetup, userRequestContext,
536
559
std::move (traceId), std::move (tempTablesState), collectFullDiagnostics,
537
- compileAction, std::move (astResult ));
560
+ perStatementResult, compileAction, std::move (queryAst ));
538
561
}
539
562
540
563
} // namespace NKqp
0 commit comments