@@ -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 ,
@@ -459,3 +487,58 @@ func resultToMaterializedResult(ctx context.Context, r result.Result) (result.Re
459487 resultSets : resultSets ,
460488 }, nil
461489}
490+
491+ func concurrentResultToMaterializedResult (ctx context.Context , r result.ConcurrentResult ) (result.Result , error ) {
492+ type resultSet struct {
493+ rows []query.Row
494+ columnNames []string
495+ columnTypes []types.Type
496+ }
497+ resultSetByIndex := make (map [int64 ]resultSet )
498+
499+ for {
500+ if ctx .Err () != nil {
501+ return nil , xerrors .WithStackTrace (ctx .Err ())
502+ }
503+
504+ part , err := r .NextPart (ctx )
505+ if err != nil {
506+ if xerrors .Is (err , io .EOF ) {
507+ break
508+ }
509+
510+ return nil , xerrors .WithStackTrace (err )
511+ }
512+
513+ rs := resultSetByIndex [part .ResultSetIndex ()]
514+ if len (rs .columnNames ) == 0 {
515+ rs .columnTypes = part .ColumnTypes ()
516+ rs .columnNames = part .ColumnNames ()
517+ }
518+
519+ rows := make ([]query.Row , 0 )
520+ for {
521+ row , err := part .NextRow (ctx )
522+ if err != nil {
523+ if xerrors .Is (err , io .EOF ) {
524+ break
525+ }
526+
527+ return nil , xerrors .WithStackTrace (err )
528+ }
529+ rows = append (rows , row )
530+ }
531+ rs .rows = append (rs .rows , rows ... )
532+
533+ resultSetByIndex [part .ResultSetIndex ()] = rs
534+ }
535+
536+ resultSets := make ([]result.Set , len (resultSetByIndex ))
537+ for rsIndex , rs := range resultSetByIndex {
538+ resultSets [rsIndex ] = MaterializedResultSet (int (rsIndex ), rs .columnNames , rs .columnTypes , rs .rows )
539+ }
540+
541+ return & materializedResult {
542+ resultSets : resultSets ,
543+ }, nil
544+ }
0 commit comments