Skip to content

Commit 67da62a

Browse files
committed
* Added table.Session.ReadRows
1 parent b2dd070 commit 67da62a

File tree

12 files changed

+342
-17
lines changed

12 files changed

+342
-17
lines changed

.github/workflows/publish.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
env:
2525
VERSION_CHANGE: ${{ github.event.inputs.version-change }}
2626
RELEASE_CANDIDATE: ${{ github.event.inputs.release-candidate }}
27-
VERSION_FILE: internal/meta/version.go
27+
VERSION_FILE: internal/version/version.go
2828
CHANGELOG_FILE: CHANGELOG.md
2929
GITHUB_TOKEN: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }}
3030
steps:
@@ -39,9 +39,9 @@ jobs:
3939
echo "CHANGELOG empty"
4040
exit 1;
4141
fi;
42-
MAJOR=$(cat $VERSION_FILE | grep VersionMajor | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
43-
MINOR=$(cat $VERSION_FILE | grep VersionMinor | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
44-
PATCH=$(cat $VERSION_FILE | grep VersionPatch | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
42+
MAJOR=$(cat $VERSION_FILE | grep Major | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
43+
MINOR=$(cat $VERSION_FILE | grep Minor | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
44+
PATCH=$(cat $VERSION_FILE | grep Patch | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
4545
LAST_TAG="v$MAJOR.$MINOR.$PATCH";
4646
if [ "$VERSION_CHANGE" = "MINOR" ]
4747
then
@@ -57,8 +57,8 @@ jobs:
5757
RC=$(git tag | grep "v$MAJOR.$MINOR.$PATCH-rc" | wc -l);
5858
TAG="v$MAJOR.$MINOR.$PATCH-rc$RC";
5959
else
60-
sed -e 's/VersionMinor = "\([0-9]*\)"/VersionMinor = "'$MINOR'"/g' -i $VERSION_FILE;
61-
sed -e 's/VersionPatch = "\([0-9]*\)"/VersionPatch = "'$PATCH'"/g' -i $VERSION_FILE;
60+
sed -e 's/Minor = "\([0-9]*\)"/Minor = "'$MINOR'"/g' -i $VERSION_FILE;
61+
sed -e 's/Patch = "\([0-9]*\)"/Patch = "'$PATCH'"/g' -i $VERSION_FILE;
6262
git add $VERSION_FILE;
6363
echo "## v$MAJOR.$MINOR.$PATCH" >> $CHANGELOG_FILE.tmp
6464
cat $CHANGELOG_FILE >> $CHANGELOG_FILE.tmp

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Added `table.Session.ReadRows`
2+
13
## v3.48.8
24
* Fixed `sugar.RemoveRecursive()` for column table type
35

examples/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ require (
4949
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
5050
github.com/syndtr/goleveldb v1.0.0 // indirect
5151
github.com/yandex-cloud/go-genproto v0.0.0-20220815090733-4c139c0154e2 // indirect
52-
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230528143953-42c825ace222 // indirect
52+
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230801151335-81e01be38941 // indirect
5353
github.com/ydb-platform/ydb-go-sdk-metrics v0.16.3 // indirect
5454
github.com/ydb-platform/ydb-go-yc-metadata v0.5.4 // indirect
5555
golang.org/x/crypto v0.6.0 // indirect
56-
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
56+
golang.org/x/mod v0.7.0 // indirect
5757
golang.org/x/net v0.7.0 // indirect
5858
golang.org/x/sync v0.1.0 // indirect
5959
golang.org/x/sys v0.5.0 // indirect
6060
golang.org/x/text v0.7.0 // indirect
61-
golang.org/x/tools v0.1.12 // indirect
61+
golang.org/x/tools v0.3.0 // indirect
6262
google.golang.org/grpc v1.53.0 // indirect
6363
google.golang.org/protobuf v1.28.1 // indirect
6464
lukechampine.com/uint128 v1.1.1 // indirect

examples/go.sum

Lines changed: 59 additions & 0 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/golang-jwt/jwt/v4 v4.4.1
77
github.com/google/uuid v1.3.0
88
github.com/jonboulle/clockwork v0.3.0
9-
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230528143953-42c825ace222
9+
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230801151335-81e01be38941
1010
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
1111
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
1212
google.golang.org/grpc v1.53.0

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
6565
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
6666
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
6767
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
68-
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230528143953-42c825ace222 h1:8ddsk8HKBkVPH8w3k81si6SeCVJIAtw8dnw+s3h0ciE=
69-
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230528143953-42c825ace222/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I=
68+
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230710134411-552fdf84e4f1 h1:+nKxgNmwZXpWqFDfQfFhXlnd2AfABNE8Z2QEBdmrxRg=
69+
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230710134411-552fdf84e4f1/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I=
70+
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230801151335-81e01be38941 h1:QXgmY0vkYtOoGEXnTjWkyxhOkIzCosMrnoDyYjrv71Q=
71+
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230801151335-81e01be38941/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I=
7072
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
7173
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
7274
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

internal/table/session.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,51 @@ func (s *session) StreamReadTable(
970970
), nil
971971
}
972972

973+
func (s *session) ReadRows(
974+
ctx context.Context,
975+
path string,
976+
keys types.Value,
977+
opts ...options.ReadRowsOption,
978+
) (_ result.Result, err error) {
979+
var (
980+
a = allocator.New()
981+
request = Ydb_Table.ReadRowsRequest{
982+
SessionId: s.id,
983+
Path: path,
984+
Keys: value.ToYDB(keys, a),
985+
}
986+
response *Ydb_Table.ReadRowsResponse
987+
)
988+
defer func() {
989+
a.Free()
990+
}()
991+
992+
for _, opt := range opts {
993+
if opt != nil {
994+
opt.ApplyReadRowsOption((*options.ReadRowsDesc)(&request), a)
995+
}
996+
}
997+
998+
response, err = s.tableService.ReadRows(ctx, &request)
999+
if err != nil {
1000+
return nil, xerrors.WithStackTrace(err)
1001+
}
1002+
1003+
if response.GetStatus() != Ydb.StatusIds_SUCCESS {
1004+
return nil, xerrors.WithStackTrace(
1005+
xerrors.Operation(
1006+
xerrors.FromOperation(response),
1007+
),
1008+
)
1009+
}
1010+
1011+
return scanner.NewUnary(
1012+
[]*Ydb.ResultSet{response.GetResultSet()},
1013+
nil,
1014+
scanner.WithIgnoreTruncated(s.config.IgnoreTruncated()),
1015+
), nil
1016+
}
1017+
9731018
// StreamExecuteScanQuery scan-reads table at given path with given options.
9741019
//
9751020
// Note that given ctx controls the lifetime of the whole read, not only this

table/options/options.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ func WithExecuteScanQueryStats(stats ExecuteScanQueryStatsType) ExecuteScanQuery
977977
}
978978

979979
var (
980+
_ ReadRowsOption = readColumnsOption{}
980981
_ ReadTableOption = readOrderedOption{}
981982
_ ReadTableOption = readKeyRangeOption{}
982983
_ ReadTableOption = readGreaterOrEqualOption{}
@@ -987,6 +988,11 @@ var (
987988
)
988989

989990
type (
991+
ReadRowsDesc Ydb_Table.ReadRowsRequest
992+
ReadRowsOption interface {
993+
ApplyReadRowsOption(*ReadRowsDesc, *allocator.Allocator)
994+
}
995+
990996
ReadTableDesc Ydb_Table.ReadTableRequest
991997
ReadTableOption interface {
992998
ApplyReadTableOption(*ReadTableDesc, *allocator.Allocator)
@@ -1027,6 +1033,10 @@ func (x readLessOption) ApplyReadTableOption(desc *ReadTableDesc, a *allocator.A
10271033
}
10281034
}
10291035

1036+
func (columns readColumnsOption) ApplyReadRowsOption(desc *ReadRowsDesc, a *allocator.Allocator) {
1037+
desc.Columns = append(desc.Columns, columns...)
1038+
}
1039+
10301040
func (columns readColumnsOption) ApplyReadTableOption(desc *ReadTableDesc, a *allocator.Allocator) {
10311041
desc.Columns = append(desc.Columns, columns...)
10321042
}

table/table.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ type Session interface {
171171
opts ...options.BulkUpsertOption,
172172
) (err error)
173173

174+
ReadRows(
175+
ctx context.Context,
176+
path string,
177+
keys types.Value,
178+
opts ...options.ReadRowsOption,
179+
) (_ result.Result, err error)
180+
174181
BeginTransaction(
175182
ctx context.Context,
176183
tx *TransactionSettings,

tests/integration/kv_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//go:build integration
2+
// +build integration
3+
4+
package integration
5+
6+
import (
7+
"context"
8+
"fmt"
9+
"os"
10+
"testing"
11+
12+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/version"
13+
"github.com/ydb-platform/ydb-go-sdk/v3/table"
14+
"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
15+
"github.com/ydb-platform/ydb-go-sdk/v3/table/result/named"
16+
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
17+
)
18+
19+
func TestKeyValue(t *testing.T) {
20+
if version.Lt(os.Getenv("YDB_VERSION"), "23.3") {
21+
t.Skip("read rows not allowed in YDB version '" + os.Getenv("YDB_VERSION") + "'")
22+
}
23+
24+
var (
25+
scope = newScope(t)
26+
driver = scope.Driver()
27+
tablePath = scope.TablePath()
28+
id = int64(100500)
29+
value = "test value"
30+
)
31+
32+
// set
33+
err := driver.Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error {
34+
return s.BulkUpsert(ctx, tablePath, types.ListValue(types.StructValue(
35+
types.StructFieldValue("id", types.Int64Value(id)),
36+
types.StructFieldValue("val", types.TextValue(value)),
37+
)))
38+
})
39+
scope.Require.NoError(err)
40+
41+
// get
42+
err = driver.Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error {
43+
rows, err := s.ReadRows(ctx, tablePath, types.ListValue(types.Int64Value(id)),
44+
options.ReadColumn("val"),
45+
)
46+
if err != nil {
47+
return err
48+
}
49+
defer func() {
50+
_ = rows.Close()
51+
}()
52+
if !rows.HasNextResultSet() {
53+
return fmt.Errorf("no result sets")
54+
}
55+
if !rows.HasNextRow() {
56+
return fmt.Errorf("no rows")
57+
}
58+
if rows.CurrentResultSet().RowCount() != 1 {
59+
return fmt.Errorf("wrong rows count (%d)", rows.CurrentResultSet().RowCount())
60+
}
61+
if rows.CurrentResultSet().ColumnCount() != 1 {
62+
return fmt.Errorf("wrong column count (%d)", rows.CurrentResultSet().ColumnCount())
63+
}
64+
var actualValue int64
65+
if err := rows.ScanNamed(named.Optional("val", &actualValue)); err != nil {
66+
return err
67+
}
68+
return rows.Err()
69+
})
70+
scope.Require.NoError(err)
71+
}

0 commit comments

Comments
 (0)