@@ -14,6 +14,7 @@ import (
1414 "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result"
1515 "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
1616 "github.com/ydb-platform/ydb-go-sdk/v3/internal/stats"
17+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/types"
1718 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1819 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xiter"
1920 "github.com/ydb-platform/ydb-go-sdk/v3/query"
@@ -349,6 +350,33 @@ func (r *streamResult) nextPartFunc(
349350 }
350351}
351352
353+ func (r * streamResult ) NextPart (ctx context.Context ) (_ result.Part , err error ) {
354+ if r .lastPart == nil {
355+ return nil , xerrors .WithStackTrace (io .EOF )
356+ }
357+
358+ select {
359+ case <- r .closer .Done ():
360+ return nil , xerrors .WithStackTrace (r .closer .Err ())
361+ case <- ctx .Done ():
362+ return nil , xerrors .WithStackTrace (ctx .Err ())
363+ default :
364+ part , err := r .nextPart (ctx )
365+ if err != nil && ! xerrors .Is (err , io .EOF ) {
366+ return nil , xerrors .WithStackTrace (err )
367+ }
368+ if part .GetExecStats () != nil && r .statsCallback != nil {
369+ r .statsCallback (stats .FromQueryStats (part .GetExecStats ()))
370+ }
371+ defer func () {
372+ r .lastPart = part
373+ r .resultSetIndex = part .GetResultSetIndex ()
374+ }()
375+
376+ return newResultPart (r .lastPart ), nil
377+ }
378+ }
379+
352380func (r * streamResult ) NextResultSet (ctx context.Context ) (_ result.Set , err error ) {
353381 if r .trace != nil {
354382 onDone := trace .QueryOnResultNextResultSet (r .trace , & ctx ,
@@ -433,11 +461,20 @@ func exactlyOneResultSetFromResult(ctx context.Context, r result.Result) (rs res
433461 return MaterializedResultSet (rs .Index (), rs .Columns (), rs .ColumnTypes (), rows ), nil
434462}
435463
436- func resultToMaterializedResult (ctx context.Context , r result.Result ) (result.Result , error ) {
437- var resultSets []result.Set
464+ func concurrentResultToMaterializedResult (ctx context.Context , r result.ConcurrentResult ) (result.Result , error ) {
465+ type resultSet struct {
466+ rows []query.Row
467+ columnNames []string
468+ columnTypes []types.Type
469+ }
470+ resultSetByIndex := make (map [int64 ]resultSet )
438471
439472 for {
440- rs , err := r .NextResultSet (ctx )
473+ if ctx .Err () != nil {
474+ return nil , xerrors .WithStackTrace (ctx .Err ())
475+ }
476+
477+ part , err := r .NextPart (ctx )
441478 if err != nil {
442479 if xerrors .Is (err , io .EOF ) {
443480 break
@@ -446,21 +483,32 @@ func resultToMaterializedResult(ctx context.Context, r result.Result) (result.Re
446483 return nil , xerrors .WithStackTrace (err )
447484 }
448485
449- var rows []query.Row
486+ rs := resultSetByIndex [part .ResultSetIndex ()]
487+ if len (rs .columnNames ) == 0 {
488+ rs .columnTypes = part .ColumnTypes ()
489+ rs .columnNames = part .ColumnNames ()
490+ }
491+
492+ rows := make ([]query.Row , 0 )
450493 for {
451- row , err := rs .NextRow (ctx )
494+ row , err := part .NextRow (ctx )
452495 if err != nil {
453496 if xerrors .Is (err , io .EOF ) {
454497 break
455498 }
456499
457500 return nil , xerrors .WithStackTrace (err )
458501 }
459-
460502 rows = append (rows , row )
461503 }
504+ rs .rows = append (rs .rows , rows ... )
505+
506+ resultSetByIndex [part .ResultSetIndex ()] = rs
507+ }
462508
463- resultSets = append (resultSets , MaterializedResultSet (rs .Index (), rs .Columns (), rs .ColumnTypes (), rows ))
509+ resultSets := make ([]result.Set , len (resultSetByIndex ))
510+ for rsIndex , rs := range resultSetByIndex {
511+ resultSets [rsIndex ] = MaterializedResultSet (int (rsIndex ), rs .columnNames , rs .columnTypes , rs .rows )
464512 }
465513
466514 return & materializedResult {
0 commit comments