Skip to content

Commit

Permalink
removed implicit Close of result
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Sep 3, 2024
1 parent eaa96e5 commit 6eb9e4d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 53 deletions.
2 changes: 1 addition & 1 deletion internal/query/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package query

import (
"context"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result"
"time"

"github.com/ydb-platform/ydb-go-genproto/Ydb_Query_V1"
Expand All @@ -16,6 +15,7 @@ import (
"github.com/ydb-platform/ydb-go-sdk/v3/internal/pool"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/options"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/types"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
Expand Down
4 changes: 0 additions & 4 deletions internal/query/execute_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ func readAll(ctx context.Context, r *streamResult) error {
}

func readResultSet(ctx context.Context, r *streamResult) (_ *resultSetWithClose, finalErr error) {
defer func() {
_ = r.Close(ctx)
}()

rs, err := r.nextResultSet(ctx)
if err != nil {
return nil, xerrors.WithStackTrace(err)
Expand Down
44 changes: 0 additions & 44 deletions internal/query/range_experiment.go

This file was deleted.

17 changes: 17 additions & 0 deletions internal/query/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ type (
resultOption func(s *streamResult)
)

func rangeResultSets(ctx context.Context, r result.Result) xiter.Seq2[result.Set, error] {
return func(yield func(result.Set, error) bool) {
for {
rs, err := r.NextResultSet(ctx)
if err != nil {
if xerrors.Is(err, io.EOF) {
return
}
}
cont := yield(rs, err)
if !cont || err != nil {
return
}
}
}
}

func (r *materializedResult) ResultSets(ctx context.Context) xiter.Seq2[result.Set, error] {
return rangeResultSets(ctx, r)
}
Expand Down
22 changes: 20 additions & 2 deletions internal/query/result_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Query"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/types"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xiter"
Expand Down Expand Up @@ -41,6 +42,23 @@ type (
}
)

func rangeRows(ctx context.Context, rs result.Set) xiter.Seq2[result.Row, error] {
return func(yield func(result.Row, error) bool) {
for {
rs, err := rs.NextRow(ctx)
if err != nil {
if xerrors.Is(err, io.EOF) {
return
}
}
cont := yield(rs, err)
if !cont || err != nil {
return
}
}
}
}

func (*materializedResultSet) Close(context.Context) error {
return nil
}
Expand All @@ -49,11 +67,11 @@ func (rs *resultSetWithClose) Close(ctx context.Context) error {
return rs.close(ctx)
}

func (rs *materializedResultSet) Rows(ctx context.Context) xiter.Seq2[query.Row, error] {
func (rs *materializedResultSet) Rows(ctx context.Context) xiter.Seq2[result.Row, error] {
return rangeRows(ctx, rs)
}

func (rs *resultSet) Rows(ctx context.Context) xiter.Seq2[query.Row, error] {
func (rs *resultSet) Rows(ctx context.Context) xiter.Seq2[result.Row, error] {
return rangeRows(ctx, rs)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/query/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package query

import (
"context"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result"
"sync/atomic"

"github.com/ydb-platform/ydb-go-genproto/Ydb_Query_V1"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Query"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/options"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/tx"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
Expand Down
2 changes: 1 addition & 1 deletion internal/query/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package query
import (
"context"
"fmt"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result"

"github.com/ydb-platform/ydb-go-genproto/Ydb_Query_V1"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Query"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/options"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result"
queryTx "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/tx"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
baseTx "github.com/ydb-platform/ydb-go-sdk/v3/internal/tx"
Expand Down

0 comments on commit 6eb9e4d

Please sign in to comment.