Skip to content

Commit c487d1f

Browse files
authored
Merge pull request #1268 from ydb-platform/range-result
* Added experimental range functions to the `query.Result` and `query.ResultSet` types, available starting with Go version 1.22. These features can be enabled by setting the environment variable `GOEXPERIMENT=rangefunc`.
2 parents 3e16b3a + 62dbf1e commit c487d1f

File tree

12 files changed

+1708
-3
lines changed

12 files changed

+1708
-3
lines changed

.github/workflows/tests.yml

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,60 @@ jobs:
7878
go-version: ${{ matrix.go-version }}
7979
cache: true
8080
- name: Integration test
81-
run: go test -race -tags integration -coverpkg=./... -coverprofile integration-secure.txt -covermode atomic ./tests/integration
81+
run: go test -race -tags integration -coverpkg=./... -coverprofile integration.txt -covermode atomic ./tests/integration
8282
- name: Upload Test secure connection coverage report to Codecov
8383
uses: codecov/codecov-action@v4
8484
with:
85-
file: ./integration-secure.txt
85+
file: ./integration.txt
8686
flags: integration,${{ matrix.os }},go-${{ matrix.go-version }},ydb-${{ matrix.ydb-version }}
87-
name: integration-secure
87+
name: integration
88+
experiment:
89+
concurrency:
90+
group: experiment-${{ github.ref }}-${{ matrix.os }}-${{ matrix.go-version }}-${{ matrix.ydb-version }}
91+
cancel-in-progress: true
92+
runs-on: ubuntu-latest
93+
strategy:
94+
fail-fast: false
95+
matrix:
96+
go-version: [1.22.x]
97+
ydb-version: [24.1]
98+
services:
99+
ydb:
100+
image: ydbplatform/local-ydb:${{ matrix.ydb-version }}
101+
ports:
102+
- 2135:2135
103+
- 2136:2136
104+
- 8765:8765
105+
volumes:
106+
- /tmp/ydb_certs:/ydb_certs
107+
env:
108+
YDB_LOCAL_SURVIVE_RESTART: true
109+
YDB_USE_IN_MEMORY_PDISKS: true
110+
YDB_TABLE_ENABLE_PREPARED_DDL: true
111+
options: '-h localhost'
112+
env:
113+
OS: ubuntu-latest
114+
GO: ${{ matrix.go-version }}
115+
YDB_VERSION: ${{ matrix.ydb-version }}
116+
YDB_CONNECTION_STRING: grpc://localhost:2136/local
117+
YDB_CONNECTION_STRING_SECURE: grpcs://localhost:2135/local
118+
YDB_SSL_ROOT_CERTIFICATES_FILE: /tmp/ydb_certs/ca.pem
119+
YDB_SESSIONS_SHUTDOWN_URLS: http://localhost:8765/actors/kqp_proxy?force_shutdown=all
120+
HIDE_APPLICATION_OUTPUT: 1
121+
GOEXPERIMENT: rangefunc
122+
steps:
123+
- name: Checkout code
124+
uses: actions/checkout@v4
125+
- name: Install Go
126+
uses: actions/setup-go@v5
127+
with:
128+
go-version: ${{ matrix.go-version }}
129+
cache: true
130+
- name: Integration test
131+
run: go test -race -tags integration -coverpkg=./... -coverprofile experiment.txt -covermode atomic ./...
132+
- name: Upload Test secure connection coverage report to Codecov
133+
uses: codecov/codecov-action@v4
134+
with:
135+
file: ./integration-secure.txt
136+
flags: experiment,${{ matrix.os }},go-${{ matrix.go-version }},ydb-${{ matrix.ydb-version }}
137+
name: experiment

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Added experimental range functions to the `query.Result` and `query.ResultSet` types, available as for-range loops starting with Go version 1.22. These features can be enabled by setting the environment variable `GOEXPERIMENT=rangefunc`.
12
* Added public types for `tx.Option`, `options.DoOption` and `options.DoTxOption`
23

34
## v3.73.1

internal/query/range_experiment.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package query
2+
3+
import (
4+
"context"
5+
"io"
6+
7+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
8+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xiter"
9+
"github.com/ydb-platform/ydb-go-sdk/v3/query"
10+
)
11+
12+
func rangeResultSets(ctx context.Context, r query.Result) xiter.Seq2[query.ResultSet, error] {
13+
return func(yield func(query.ResultSet, error) bool) {
14+
for {
15+
rs, err := r.NextResultSet(ctx)
16+
if err != nil {
17+
if xerrors.Is(err, io.EOF) {
18+
return
19+
}
20+
}
21+
cont := yield(rs, err)
22+
if !cont || err != nil {
23+
return
24+
}
25+
}
26+
}
27+
}
28+
29+
func rangeRows(ctx context.Context, rs query.ResultSet) xiter.Seq2[query.Row, error] {
30+
return func(yield func(query.Row, error) bool) {
31+
for {
32+
rs, err := rs.NextRow(ctx)
33+
if err != nil {
34+
if xerrors.Is(err, io.EOF) {
35+
return
36+
}
37+
}
38+
cont := yield(rs, err)
39+
if !cont || err != nil {
40+
return
41+
}
42+
}
43+
}
44+
}

internal/query/result.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
1212
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
1313
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
14+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xiter"
1415
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsync"
1516
"github.com/ydb-platform/ydb-go-sdk/v3/query"
1617
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
@@ -37,6 +38,14 @@ type (
3738
}
3839
)
3940

41+
func (r *materializedResult) Range(ctx context.Context) xiter.Seq2[query.ResultSet, error] {
42+
return rangeResultSets(ctx, r)
43+
}
44+
45+
func (r *result) Range(ctx context.Context) xiter.Seq2[query.ResultSet, error] {
46+
return rangeResultSets(ctx, r)
47+
}
48+
4049
func (r *materializedResult) Close(ctx context.Context) error {
4150
return nil
4251
}

0 commit comments

Comments
 (0)