Skip to content

Commit 75b64a2

Browse files
committed
set public interface query.ClosableResultSet
1 parent 903a6df commit 75b64a2

File tree

7 files changed

+160
-12
lines changed

7 files changed

+160
-12
lines changed

Diff for: internal/query/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (c *Client) ExecuteScript(
186186
return op, nil
187187
}
188188

189-
func (p *poolStub) Close(ctx context.Context) error {
189+
func (p *poolStub) Close(context.Context) error {
190190
return nil
191191
}
192192

Diff for: internal/query/result_range_test.go renamed to internal/query/result_go1.23_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
1616
)
1717

18-
func TestResultRange(t *testing.T) {
18+
func TestResultRangeResultSets(t *testing.T) {
1919
ctx, cancel := context.WithCancel(xtest.Context(t))
2020
defer cancel()
2121
ctrl := gomock.NewController(t)

Diff for: internal/query/result_set_range_test.go renamed to internal/query/result_set_go1.23_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
2020
)
2121

22-
func TestResultSetRange(t *testing.T) {
22+
func TestResultSetRangeRows(t *testing.T) {
2323
ctx := xtest.Context(t)
2424
ctrl := gomock.NewController(t)
2525
t.Run("EmptyResultSet", func(t *testing.T) {

Diff for: internal/query/result_test.go

+148
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1919
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
2020
"github.com/ydb-platform/ydb-go-sdk/v3/query"
21+
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
2122
)
2223

2324
func TestResultNextResultSet(t *testing.T) {
@@ -1435,6 +1436,153 @@ func TestExactlyOneResultSetFromResult(t *testing.T) {
14351436
})
14361437
}
14371438

1439+
func TestCloseResultOnCloseClosableResultSet(t *testing.T) {
1440+
ctx := xtest.Context(t)
1441+
ctrl := gomock.NewController(t)
1442+
stream := NewMockQueryService_ExecuteQueryClient(ctrl)
1443+
stream.EXPECT().Recv().Return(&Ydb_Query.ExecuteQueryResponsePart{
1444+
Status: Ydb.StatusIds_SUCCESS,
1445+
TxMeta: &Ydb_Query.TransactionMeta{
1446+
Id: "456",
1447+
},
1448+
ResultSetIndex: 0,
1449+
ResultSet: &Ydb.ResultSet{
1450+
Columns: []*Ydb.Column{
1451+
{
1452+
Name: "a",
1453+
Type: &Ydb.Type{
1454+
Type: &Ydb.Type_TypeId{
1455+
TypeId: Ydb.Type_UINT64,
1456+
},
1457+
},
1458+
},
1459+
{
1460+
Name: "b",
1461+
Type: &Ydb.Type{
1462+
Type: &Ydb.Type_TypeId{
1463+
TypeId: Ydb.Type_UTF8,
1464+
},
1465+
},
1466+
},
1467+
},
1468+
Rows: []*Ydb.Value{
1469+
{
1470+
Items: []*Ydb.Value{{
1471+
Value: &Ydb.Value_Uint64Value{
1472+
Uint64Value: 1,
1473+
},
1474+
}, {
1475+
Value: &Ydb.Value_TextValue{
1476+
TextValue: "1",
1477+
},
1478+
}},
1479+
},
1480+
{
1481+
Items: []*Ydb.Value{{
1482+
Value: &Ydb.Value_Uint64Value{
1483+
Uint64Value: 2,
1484+
},
1485+
}, {
1486+
Value: &Ydb.Value_TextValue{
1487+
TextValue: "2",
1488+
},
1489+
}},
1490+
},
1491+
},
1492+
},
1493+
}, nil)
1494+
stream.EXPECT().Recv().Return(&Ydb_Query.ExecuteQueryResponsePart{
1495+
Status: Ydb.StatusIds_SUCCESS,
1496+
TxMeta: &Ydb_Query.TransactionMeta{
1497+
Id: "456",
1498+
},
1499+
ResultSetIndex: 0,
1500+
ResultSet: &Ydb.ResultSet{
1501+
Columns: []*Ydb.Column{
1502+
{
1503+
Name: "a",
1504+
Type: &Ydb.Type{
1505+
Type: &Ydb.Type_TypeId{
1506+
TypeId: Ydb.Type_UINT64,
1507+
},
1508+
},
1509+
},
1510+
{
1511+
Name: "b",
1512+
Type: &Ydb.Type{
1513+
Type: &Ydb.Type_TypeId{
1514+
TypeId: Ydb.Type_UTF8,
1515+
},
1516+
},
1517+
},
1518+
},
1519+
Rows: []*Ydb.Value{
1520+
{
1521+
Items: []*Ydb.Value{{
1522+
Value: &Ydb.Value_Uint64Value{
1523+
Uint64Value: 1,
1524+
},
1525+
}, {
1526+
Value: &Ydb.Value_TextValue{
1527+
TextValue: "1",
1528+
},
1529+
}},
1530+
},
1531+
{
1532+
Items: []*Ydb.Value{{
1533+
Value: &Ydb.Value_Uint64Value{
1534+
Uint64Value: 2,
1535+
},
1536+
}, {
1537+
Value: &Ydb.Value_TextValue{
1538+
TextValue: "2",
1539+
},
1540+
}},
1541+
},
1542+
},
1543+
},
1544+
}, nil)
1545+
stream.EXPECT().Recv().Return(nil, io.EOF)
1546+
var closed bool
1547+
r, _, err := newResult(ctx, stream, withTrace(&trace.Query{
1548+
OnResultClose: func(info trace.QueryResultCloseStartInfo) func(info trace.QueryResultCloseDoneInfo) {
1549+
require.False(t, closed)
1550+
closed = true
1551+
1552+
return nil
1553+
},
1554+
}))
1555+
1556+
require.NoError(t, err)
1557+
1558+
rs, err := readResultSet(ctx, r)
1559+
require.NoError(t, err)
1560+
var (
1561+
a uint64
1562+
b string
1563+
)
1564+
r1, err1 := rs.NextRow(ctx)
1565+
require.NoError(t, err1)
1566+
require.NotNil(t, r1)
1567+
scanErr1 := r1.Scan(&a, &b)
1568+
require.NoError(t, scanErr1)
1569+
require.EqualValues(t, 1, a)
1570+
require.EqualValues(t, "1", b)
1571+
r2, err2 := rs.NextRow(ctx)
1572+
require.NoError(t, err2)
1573+
require.NotNil(t, r2)
1574+
scanErr2 := r2.Scan(&a, &b)
1575+
require.NoError(t, scanErr2)
1576+
require.EqualValues(t, 2, a)
1577+
require.EqualValues(t, "2", b)
1578+
r3, err3 := rs.NextRow(ctx)
1579+
require.ErrorIs(t, err3, io.EOF)
1580+
require.Nil(t, r3)
1581+
err = rs.Close(ctx)
1582+
require.NoError(t, err)
1583+
require.True(t, closed)
1584+
}
1585+
14381586
func TestResultStats(t *testing.T) {
14391587
t.Run("Stats", func(t *testing.T) {
14401588
t.Run("Never", func(t *testing.T) {
File renamed without changes.

Diff for: query/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type (
3131
//
3232
// Exec used by default:
3333
// - DefaultTxControl
34-
QueryResultSet(ctx context.Context, query string, opts ...options.Execute) (resultSetWithClose, error)
34+
QueryResultSet(ctx context.Context, query string, opts ...options.Execute) (ClosableResultSet, error)
3535

3636
// QueryRow execute query and take the exactly single row from exactly single result set from result
3737
//
@@ -87,7 +87,7 @@ type (
8787
// Warning: the large result set from query will be materialized and can happened to "OOM killed" problem
8888
//
8989
// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
90-
QueryResultSet(ctx context.Context, query string, opts ...options.Execute) (resultSetWithClose, error)
90+
QueryResultSet(ctx context.Context, query string, opts ...options.Execute) (ClosableResultSet, error)
9191

9292
// QueryRow is a helper which read only one row from first result set in result
9393
//

Diff for: query/result.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import (
77
)
88

99
type (
10-
Result = result.Result
11-
ResultSet = result.Set
12-
resultSetWithClose = result.ClosableResultSet
13-
Row = result.Row
14-
Type = types.Type
15-
NamedDestination = scanner.NamedDestination
16-
ScanStructOption = scanner.ScanStructOption
10+
Result = result.Result
11+
ResultSet = result.Set
12+
ClosableResultSet = result.ClosableResultSet
13+
Row = result.Row
14+
Type = types.Type
15+
NamedDestination = scanner.NamedDestination
16+
ScanStructOption = scanner.ScanStructOption
1717
)
1818

1919
func Named(columnName string, destinationValueReference interface{}) (dst NamedDestination) {

0 commit comments

Comments
 (0)