@@ -13,6 +13,7 @@ import (
1313 "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result"
1414 "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
1515 "github.com/ydb-platform/ydb-go-sdk/v3/internal/stats"
16+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/types"
1617 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1718 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xiter"
1819 "github.com/ydb-platform/ydb-go-sdk/v3/query"
@@ -341,6 +342,33 @@ func (r *streamResult) nextPartFunc(
341342 }
342343}
343344
345+ func (r * streamResult ) NextPart (ctx context.Context ) (_ result.Part , err error ) {
346+ if r .lastPart == nil {
347+ return nil , xerrors .WithStackTrace (io .EOF )
348+ }
349+
350+ select {
351+ case <- r .closer .Done ():
352+ return nil , xerrors .WithStackTrace (r .closer .Err ())
353+ case <- ctx .Done ():
354+ return nil , xerrors .WithStackTrace (ctx .Err ())
355+ default :
356+ part , err := r .nextPart (ctx )
357+ if err != nil && ! xerrors .Is (err , io .EOF ) {
358+ return nil , xerrors .WithStackTrace (err )
359+ }
360+ if part .GetExecStats () != nil && r .statsCallback != nil {
361+ r .statsCallback (stats .FromQueryStats (part .GetExecStats ()))
362+ }
363+ defer func () {
364+ r .lastPart = part
365+ r .resultSetIndex = part .GetResultSetIndex ()
366+ }()
367+
368+ return newResultPart (r .lastPart ), nil
369+ }
370+ }
371+
344372func (r * streamResult ) NextResultSet (ctx context.Context ) (_ result.Set , err error ) {
345373 if r .trace != nil {
346374 onDone := trace .QueryOnResultNextResultSet (r .trace , & ctx ,
@@ -425,11 +453,20 @@ func exactlyOneResultSetFromResult(ctx context.Context, r result.Result) (rs res
425453 return MaterializedResultSet (rs .Index (), rs .Columns (), rs .ColumnTypes (), rows ), nil
426454}
427455
428- func resultToMaterializedResult (ctx context.Context , r result.Result ) (result.Result , error ) {
429- var resultSets []result.Set
456+ func concurrentResultToMaterializedResult (ctx context.Context , r result.ConcurrentResult ) (result.Result , error ) {
457+ type resultSet struct {
458+ rows []query.Row
459+ columnNames []string
460+ columnTypes []types.Type
461+ }
462+ resultSetByIndex := make (map [int64 ]resultSet )
430463
431464 for {
432- rs , err := r .NextResultSet (ctx )
465+ if ctx .Err () != nil {
466+ return nil , xerrors .WithStackTrace (ctx .Err ())
467+ }
468+
469+ part , err := r .NextPart (ctx )
433470 if err != nil {
434471 if xerrors .Is (err , io .EOF ) {
435472 break
@@ -438,21 +475,32 @@ func resultToMaterializedResult(ctx context.Context, r result.Result) (result.Re
438475 return nil , xerrors .WithStackTrace (err )
439476 }
440477
441- var rows []query.Row
478+ rs := resultSetByIndex [part .ResultSetIndex ()]
479+ if len (rs .columnNames ) == 0 {
480+ rs .columnTypes = part .ColumnTypes ()
481+ rs .columnNames = part .ColumnNames ()
482+ }
483+
484+ rows := make ([]query.Row , 0 )
442485 for {
443- row , err := rs .NextRow (ctx )
486+ row , err := part .NextRow (ctx )
444487 if err != nil {
445488 if xerrors .Is (err , io .EOF ) {
446489 break
447490 }
448491
449492 return nil , xerrors .WithStackTrace (err )
450493 }
451-
452494 rows = append (rows , row )
453495 }
496+ rs .rows = append (rs .rows , rows ... )
497+
498+ resultSetByIndex [part .ResultSetIndex ()] = rs
499+ }
454500
455- resultSets = append (resultSets , MaterializedResultSet (rs .Index (), rs .Columns (), rs .ColumnTypes (), rows ))
501+ resultSets := make ([]result.Set , len (resultSetByIndex ))
502+ for rsIndex , rs := range resultSetByIndex {
503+ resultSets [rsIndex ] = MaterializedResultSet (int (rsIndex ), rs .columnNames , rs .columnTypes , rs .rows )
456504 }
457505
458506 return & materializedResult {
0 commit comments